Implement force_pic_flags as cc_args
BEGIN_PUBLIC
Implement force_pic_flags as cc_args
Implements the force_pic_flags feature as cc_args rules.
END_PUBLIC
PiperOrigin-RevId: 671764316
Change-Id: I7f04bbf46027007fc47d230d49d3334b1a6ddfac
diff --git a/cc/toolchains/args/BUILD b/cc/toolchains/args/BUILD
index 94012d0..2741f2f 100644
--- a/cc/toolchains/args/BUILD
+++ b/cc/toolchains/args/BUILD
@@ -15,6 +15,7 @@
name = "experimental_replace_legacy_action_config_features",
args = [
"//cc/toolchains/args/archiver_flags",
+ "//cc/toolchains/args/force_pic_flags",
"//cc/toolchains/args/linker_param_file",
],
feature_name = "experimental_replace_legacy_action_config_features",
@@ -34,7 +35,6 @@
"//cc/toolchains/features/legacy:unfiltered_compile_flags",
"//cc/toolchains/features/legacy:user_compile_flags",
"//cc/toolchains/features/legacy:user_link_flags",
- "//cc/toolchains/features/legacy:force_pic_flags",
"//cc/toolchains/features/legacy:libraries_to_link",
"//cc/toolchains/features/legacy:runtime_library_search_directories",
"//cc/toolchains/features/legacy:shared_flag",
diff --git a/cc/toolchains/args/force_pic_flags/BUILD b/cc/toolchains/args/force_pic_flags/BUILD
new file mode 100644
index 0000000..63bc341
--- /dev/null
+++ b/cc/toolchains/args/force_pic_flags/BUILD
@@ -0,0 +1,17 @@
+load("//cc/toolchains:args.bzl", "cc_args")
+
+package(default_visibility = ["//visibility:private"])
+
+cc_args(
+ name = "force_pic_flags",
+ actions = [
+ "//cc/toolchains/actions:cpp_link_executable",
+ "//cc/toolchains/actions:lto_index_for_executable",
+ ],
+ args = select({
+ "@platforms//os:macos": ["-Wl,-pie"],
+ "//conditions:default": ["-pie"],
+ }),
+ requires_not_none = "//cc/toolchains/variables:force_pic",
+ visibility = ["//visibility:public"],
+)
diff --git a/cc/toolchains/features/legacy/BUILD b/cc/toolchains/features/legacy/BUILD
index 7dbe406..ffea87c 100644
--- a/cc/toolchains/features/legacy/BUILD
+++ b/cc/toolchains/features/legacy/BUILD
@@ -140,6 +140,7 @@
cc_external_feature(
name = "force_pic_flags",
+ deprecation = "Use //cc/toolchains/args/force_pic_flags instead",
feature_name = "force_pic_flags",
overridable = True,
)
diff --git a/tests/rule_based_toolchain/legacy_features_as_args/BUILD b/tests/rule_based_toolchain/legacy_features_as_args/BUILD
index 12470ec..002962d 100644
--- a/tests/rule_based_toolchain/legacy_features_as_args/BUILD
+++ b/tests/rule_based_toolchain/legacy_features_as_args/BUILD
@@ -19,6 +19,15 @@
)
compare_feature_implementation(
+ name = "force_pic_flags_test",
+ actual_implementation = "//cc/toolchains/args/force_pic_flags",
+ expected = select({
+ "@platforms//os:macos": "//tests/rule_based_toolchain/legacy_features_as_args:goldens/macos/force_pic_flags.textproto",
+ "//conditions:default": "//tests/rule_based_toolchain/legacy_features_as_args:goldens/unix/force_pic_flags.textproto",
+ }),
+)
+
+compare_feature_implementation(
name = "linker_param_file_test",
actual_implementation = "//cc/toolchains/args/linker_param_file",
expected = "//tests/rule_based_toolchain/legacy_features_as_args:goldens/unix/linker_param_file.textproto",
diff --git a/tests/rule_based_toolchain/legacy_features_as_args/goldens/macos/force_pic_flags.textproto b/tests/rule_based_toolchain/legacy_features_as_args/goldens/macos/force_pic_flags.textproto
new file mode 100644
index 0000000..c18413b
--- /dev/null
+++ b/tests/rule_based_toolchain/legacy_features_as_args/goldens/macos/force_pic_flags.textproto
@@ -0,0 +1,10 @@
+enabled: false
+flag_sets {
+ actions: "c++-link-executable"
+ actions: "lto-index-for-executable"
+ flag_groups {
+ expand_if_available: "force_pic"
+ flags: "-Wl,-pie"
+ }
+}
+name: "force_pic_flags_test"
diff --git a/tests/rule_based_toolchain/legacy_features_as_args/goldens/unix/force_pic_flags.textproto b/tests/rule_based_toolchain/legacy_features_as_args/goldens/unix/force_pic_flags.textproto
new file mode 100644
index 0000000..d8e2ebf
--- /dev/null
+++ b/tests/rule_based_toolchain/legacy_features_as_args/goldens/unix/force_pic_flags.textproto
@@ -0,0 +1,10 @@
+enabled: false
+flag_sets {
+ actions: "c++-link-executable"
+ actions: "lto-index-for-executable"
+ flag_groups {
+ expand_if_available: "force_pic"
+ flags: "-pie"
+ }
+}
+name: "force_pic_flags_test"