We have a large project where most of the targets has to be built for each target platform separately. At the same time we have substantial number of the “codegen” targets, which invoke Python to produce additional source files. Result of that code generation does not depend on the target platform – generated sources are always the same on all platforms or configuration flavors. It is inefficient to run codegens for each platform when we can share the results for all platforms.
I am looking how to express that in Starlark and my gut feeling is that configuration transitions should be involved, although it is not obvious how exactly.
My first try was to add cfg = “exec” to express that Python targets should be run with executor configuration. Unfortunately to my surprise cfg = “exec” can be specified on the attributes of the rule, but CANNOT on the cfg attribute of the rule itself! We have thousands of rules which depend on the Python rules and it is not feasible to modify all of them (add cfg = “exec“ to the attribute) to indicate configuration change. Also in some cases Python rules are part of the lists where other rules are normal, so we cannot even specify cfg = “exec” on the consuming rule attribute as it would affect other irrelevant rules too.
My next attempt was to implement a simple custom transition like this:
def _winr64_impl(settings, attr):
current_platform = settings["//command_line_option:platforms"]
if current_platform == [Label("@tab_toolchains//bazel/platforms:x86_windows")]:
new_platform = "@tab_toolchains//bazel/platforms:x64_windows"
else:
new_platform = current_platform
return {
"//command_line_option:compilation_mode": "opt",
"//command_line_option:platforms": new_platform,
}
winr64_transition = transition(
implementation = _winr64_impl,
inputs = [
"//command_line_option:platforms",
"//command_line_option:compilation_mode",
],
outputs = [
"//command_line_option:compilation_mode",
"//command_line_option:platforms",
],
)
The idea behind it is to always use opt flavor regardless of what’s requested and also when the build platform is x86_windows it is replaced with x64_windows, so we get only one set of generated sources for all four combinations of Windows builds.
It does work, but I still don’t understand how to share the results of the platform independent targets with the other platforms, such as Linux and Mac.
Any advice?
Thank you!
Konstantin
defs.bzl
:
def _impl(ctx):
return []
my_rule = rule(
implementation = _impl,
cfg = config.exec(),
)
BUILD
:
load(":defs.bzl", "my_rule")
my_rule(name = "foo")
--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/e1630f16-3c21-4b1b-a756-ffb5ea8860dbn%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CAAvaYBn3h_d5YM4P%2BLQwqg-s0E1qHv1Z%3DDo%3Do0HY-v2rXOgsFA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/46d97796-79a1-4f56-91c1-31c898816816n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/98604362-2b12-4649-9fea-731bf602bf13n%40googlegroups.com.
Alex, I'm curious where you got that "cfg = config.exec()" construct? I don't remember seeing it anywhere and wonder what other values could be there.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/068074cc-a175-4566-baf0-8aab07b92f19n%40googlegroups.com.