Trying to use modifiers when not configured does not error or warn
We're trying to use modifiers to set link_style on our cxx toolchain at work and it's not being picked up from the command line or from modifiers = [...].
I have produced a minimal example. Apply the following diff to the buck2 repo:
diff --git a/shim/BUCK b/shim/BUCK
index 180aa39bcc..2da42c0e6d 100644
--- a/shim/BUCK
+++ b/shim/BUCK
@@ -26,6 +26,10 @@
"-latomic",
],
}),
+ link_style = select({
+ "root//foobar:static_pic": "static_pic",
+ "root//foobar:shared": "shared",
+ }),
visibility = ["PUBLIC"],
)
diff --git a/shim/foobar/BUCK b/shim/foobar/BUCK
new file mode 100644
index 0000000000..7842b4021c
--- /dev/null
+++ b/shim/foobar/BUCK
@@ -0,0 +1,23 @@
+constraint_setting(
+ name = "link_style",
+ visibility = ["PUBLIC"],
+)
+
+constraint_value(
+ name = "static_pic",
+ constraint_setting = ":link_style",
+ visibility = ["PUBLIC"],
+)
+
+# N.B. This means static_pic in practice. We do not support non-PIC static
+# linking because it is at odds with modern security mitigations like ASLR.
+alias(
+ name = "static",
+ actual = ":static_pic",
+)
+
+constraint_value(
+ name = "shared",
+ constraint_setting = ":link_style",
+ visibility = ["PUBLIC"],
+)
Then:
co/buck2 » buck2 build --modifier gh_facebook_buck2_shims_meta//foobar:shared //app/buck2_error:buck2_error
Build ID: bf4e2340-5bc3-4449-8634-f67612955fcb
Loading targets. Remaining 0/2
Analyzing targets. Remaining 0/1
Command: build.
Time elapsed: 0.0s
BUILD FAILED
Error running analysis for `gh_facebook_buck2//app/buck2_error:buck2_error (prelude//platforms:default#200212f73efcd57d)`
Caused by:
0: Error in configured node dependency, dependency chain follows (-> indicates depends on, ^ indicates same configuration as previous):
gh_facebook_buck2//app/buck2_error:buck2_error (prelude//platforms:default#200212f73efcd57d)
-> gh_facebook_buck2_shims_meta//:cxx (^)
1: configuring attr `link_style`
2: None of 2 conditions matched configuration `prelude//platforms:default#200212f73efcd57d` and no default was set:
gh_facebook_buck2_shims_meta//foobar:static_pic
gh_facebook_buck2_shims_meta//foobar:shared
The expected result is that the modifier will satisfy the select rather than trying to take the default case.
The documentation advises using modifiers for use cases like setting something in release/debug mode, which is transitive through the build graph, in https://buck2.build/docs/users/how_tos/modifiers_target/, however, the original design document says they're only applied to the top-level target, which seems to be a contradiction. I would assume that to be able to do this and be sound to begin with, modifiers would have to change the configuration hash anyway, just like transitions, right??
@cbarrete, the author of the documentation says they have used them for these transitive things successfully so I dunno what we're doing wrong here. Related: https://github.com/facebook/buck2/issues/832 and https://github.com/facebook/buck2/issues/448.
My immediate need at work has been unblocked by writing a transition, anyhow.
I would assume that to be able to do this and be sound to begin with, modifiers would have to change the configuration hash anyway, just like transitions, right??
That's right. Actually an issue with modifiers is that they create build configurations that have no human-friendly names, so when you press p in the supergui, the platform names make no sense.
@cbarrete, the author of the documentation says they have used them for these transitive things successfully
I have :) https://github.com/cbarrete/buck2_example/ is an example that uses modifiers to set constraints that get picked up by the toolchain.
The repro that you provided doesn't work because the Buck2 repo doesn't have a root PACKAGE file like https://github.com/cbarrete/buck2_example/blob/master/PACKAGE.
See https://buck2.build/docs/concepts/modifiers/#open-source-only-getting-started-with-modifiers.
Confirmed that is the issue, so I am renaming the issue, because the fact it's confusing is equally a problem.
Sorry for the late reply.
Trying to use modifiers when not configured does not error or warn
Agreed this is a problem. The reason this hasn't been fixed is that I had a stack of diffs to make modifiers automatically enabled. Unfortunately, it got left behind because of other priorities and now this stack of diffs is outdated, but I'm hoping to revive this at some point and then this wouldn't be a problem.
That's right. Actually an issue with modifiers is that they create build configurations that have no human-friendly names, so when you press p in the supergui, the platform names make no sense.
The issue here is that name.bzl generates the configuration name but because all of the specified constraints are Meta-internal constraints, you cannot get names outside of Meta right now. I will put up a commit to make naming configurable from set_cfg_constructor.