Skip to content

Trying to use modifiers when not configured does not error or warn #1092

@lf-

Description

@lf-

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: #832 and #448.

My immediate need at work has been unblocked by writing a transition, anyhow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions