Skip to content

Commit

Permalink
Implement force_pic_flags as cc_args
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Googler authored and copybara-github committed Sep 6, 2024
1 parent cf6ccb9 commit 98ab833
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cc/toolchains/args/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
17 changes: 17 additions & 0 deletions cc/toolchains/args/force_pic_flags/BUILD
Original file line number Diff line number Diff line change
@@ -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"],
)
1 change: 1 addition & 0 deletions cc/toolchains/features/legacy/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
9 changes: 9 additions & 0 deletions tests/rule_based_toolchain/legacy_features_as_args/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 98ab833

Please sign in to comment.