From 98ab8334e7d2621af31ff4eff7b1c5a122abbec1 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 6 Sep 2024 08:20:08 -0700 Subject: [PATCH] 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 --- cc/toolchains/args/BUILD | 2 +- cc/toolchains/args/force_pic_flags/BUILD | 17 +++++++++++++++++ cc/toolchains/features/legacy/BUILD | 1 + .../legacy_features_as_args/BUILD | 9 +++++++++ .../goldens/macos/force_pic_flags.textproto | 10 ++++++++++ .../goldens/unix/force_pic_flags.textproto | 10 ++++++++++ 6 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 cc/toolchains/args/force_pic_flags/BUILD create mode 100644 tests/rule_based_toolchain/legacy_features_as_args/goldens/macos/force_pic_flags.textproto create mode 100644 tests/rule_based_toolchain/legacy_features_as_args/goldens/unix/force_pic_flags.textproto diff --git a/cc/toolchains/args/BUILD b/cc/toolchains/args/BUILD index 94012d09..2741f2f1 100644 --- a/cc/toolchains/args/BUILD +++ b/cc/toolchains/args/BUILD @@ -15,6 +15,7 @@ cc_feature( 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_feature( "//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 00000000..63bc3418 --- /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 7dbe4060..ffea87c3 100644 --- a/cc/toolchains/features/legacy/BUILD +++ b/cc/toolchains/features/legacy/BUILD @@ -140,6 +140,7 @@ cc_external_feature( 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 12470ec6..002962d4 100644 --- a/tests/rule_based_toolchain/legacy_features_as_args/BUILD +++ b/tests/rule_based_toolchain/legacy_features_as_args/BUILD @@ -18,6 +18,15 @@ compare_feature_implementation( }), ) +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", 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 00000000..c18413b3 --- /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 00000000..d8e2ebfc --- /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"