Two rules, csharp_binary and cc_binary both depend on a single code generation rule. However, because csharp_binary uses transitions, the code generation rule runs multiple times, once for cc_binary, and another time for each csharp_binary target framework.
I've found an unpleasant workaround to use rules_dotnet's 'default_transition' as cfg= in the custom codegen rule, but this causes all code generations to run in a directory with ST-hash, rather than the actual default configuration. And it only works if rules_dotnet is the only ruleset using transitions.
Possible solutions
rules_dotnet could reset srcs and dependencies that are not other rules_dotnet targets back to actual default. Not sure if this is possible in Bazel today?
or: document a way to reset a custom codegen rule back to actual default transition
or: document a way to reset an ootb rule back to actual default transition
It's on my list to see if I can optimize the transitions a bit since I'm encountering some double building as well. Can't say when I will have the time though.
Two rules, csharp_binary and cc_binary both depend on a single code generation rule. However, because csharp_binary uses transitions, the code generation rule runs multiple times, once for cc_binary, and another time for each csharp_binary target framework.
Here is a minimal worked example: https://github.com/peakschris/bazel-cs-gen-transitions
I've found an unpleasant workaround to use rules_dotnet's 'default_transition' as cfg= in the custom codegen rule, but this causes all code generations to run in a directory with ST-hash, rather than the actual default configuration. And it only works if rules_dotnet is the only ruleset using transitions.
Possible solutions