Fix pic default for musl#668
Conversation
Previously since this defaulted to on, linking cgo with musl would fail because cgo assumes pic is off by default
|
the second commit here shows the issue with this approach. this breaks if you try to enable we could maybe make rules_go read the cc* stuff for this, but I'm not sure if it's worth it. the nice thing about this change is that it works by default. we could also continue supporting |
|
like this works to maintain override behavior: diff --git a/constraints/pie/BUILD.bazel b/constraints/pie/BUILD.bazel
new file mode 100644
index 0000000..2542880
--- /dev/null
+++ b/constraints/pie/BUILD.bazel
@@ -0,0 +1,21 @@
+package(default_visibility = ["//visibility:public"])
+
+constraint_setting(
+ name = "pie",
+ default_constraint_value = "unset",
+)
+
+constraint_value(
+ name = "unset",
+ constraint_setting = "pie",
+)
+
+constraint_value(
+ name = "on",
+ constraint_setting = "pie",
+)
+
+constraint_value(
+ name = "off",
+ constraint_setting = "pie",
+)
diff --git a/toolchain/args/BUILD.bazel b/toolchain/args/BUILD.bazel
index c358fff..f05b12f 100644
--- a/toolchain/args/BUILD.bazel
+++ b/toolchain/args/BUILD.bazel
@@ -153,6 +153,20 @@ cc_args(
},
)
+cc_args(
+ name = "static_link_executable_custom_pic",
+ actions = [
+ "@rules_cc//cc/toolchains/actions:cpp_link_executable",
+ "@rules_cc//cc/toolchains/actions:lto_index_for_executable",
+ "@rules_cc//cc/toolchains/actions:lto_index_for_dynamic_library",
+ "@rules_cc//cc/toolchains/actions:lto_index_for_nodeps_dynamic_library",
+ ],
+ args = select({
+ "//constraints/pie:on": ["-static-pie"],
+ "//constraints/pie:off": ["-static"],
+ }),
+)
+
cc_args(
name = "static_link_executable_pic",
actions = [
@@ -179,10 +193,13 @@ cc_args(
cc_args_list(
name = "static_link_executable",
- args = [
- ":static_link_executable_pic",
- ":static_link_executable_no_pic",
- ],
+ args = select({
+ "//constraints/pie:unset": [
+ ":static_link_executable_pic",
+ ":static_link_executable_no_pic",
+ ],
+ "//conditions:default": [":static_link_executable_custom_pic"],
+ }),
)
cc_args( |
|
rules_go stuff would be fixed by bazel-contrib/rules_go#4648 |
| cc_args( | ||
| name = "static_link_executable_no_pic", | ||
| actions = [ | ||
| "@rules_cc//cc/toolchains/actions:cpp_link_executable", |
There was a problem hiding this comment.
should we factor out an action_set for these?
| package(default_visibility = ["//visibility:public"]) | ||
|
|
||
| constraint_setting( | ||
| name = "pie", |
There was a problem hiding this comment.
should we keep these around as no-op with deprecation warning for a bit? give rules_rs and anyone else using them a chance to upgrade?
|
i will rebase once rules_go is released with that fix |
Previously since this defaulted to on, linking cgo with musl would fail
because cgo assumes pic is off by default