mirror of https://github.com/bazelbuild/rules_cc
Implement runtime_library_search_directories as cc_args
BEGIN_PUBLIC Implement runtime_library_search_directories as cc_args Implements the runtime_library_search_directories feature as cc_args rules. END_PUBLIC PiperOrigin-RevId: 671773775 Change-Id: I703824dee8ceb62ac1597e42cc74de0162952386
This commit is contained in:
parent
4bf8bb1f7d
commit
7c2883f3b1
|
@ -17,6 +17,7 @@ cc_feature(
|
||||||
"//cc/toolchains/args/archiver_flags",
|
"//cc/toolchains/args/archiver_flags",
|
||||||
"//cc/toolchains/args/force_pic_flags",
|
"//cc/toolchains/args/force_pic_flags",
|
||||||
"//cc/toolchains/args/linker_param_file",
|
"//cc/toolchains/args/linker_param_file",
|
||||||
|
"//cc/toolchains/args/runtime_library_search_directories",
|
||||||
"//cc/toolchains/args/shared_flag",
|
"//cc/toolchains/args/shared_flag",
|
||||||
],
|
],
|
||||||
feature_name = "experimental_replace_legacy_action_config_features",
|
feature_name = "experimental_replace_legacy_action_config_features",
|
||||||
|
@ -37,6 +38,5 @@ cc_feature(
|
||||||
"//cc/toolchains/features/legacy:user_compile_flags",
|
"//cc/toolchains/features/legacy:user_compile_flags",
|
||||||
"//cc/toolchains/features/legacy:user_link_flags",
|
"//cc/toolchains/features/legacy:user_link_flags",
|
||||||
"//cc/toolchains/features/legacy:libraries_to_link",
|
"//cc/toolchains/features/legacy:libraries_to_link",
|
||||||
"//cc/toolchains/features/legacy:runtime_library_search_directories",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,122 @@
|
||||||
|
load("//cc/toolchains:args.bzl", "cc_args")
|
||||||
|
load("//cc/toolchains:args_list.bzl", "cc_args_list")
|
||||||
|
load("//cc/toolchains:feature_constraint.bzl", "cc_feature_constraint")
|
||||||
|
load("//cc/toolchains:nested_args.bzl", "cc_nested_args")
|
||||||
|
|
||||||
|
package(default_visibility = ["//visibility:private"])
|
||||||
|
|
||||||
|
# TODO: b/27153401 - The implementation of this is particularly complex because
|
||||||
|
# of what appears to be a workaround where macOS cc_test targets with
|
||||||
|
# static_link_cpp_runtimes enabled utilize a $EXEC_ORIGIN/ prefix. This can be
|
||||||
|
# paired down significantly after it is clear this workaround is no longer
|
||||||
|
# required.
|
||||||
|
|
||||||
|
cc_feature_constraint(
|
||||||
|
name = "static_link_cpp_runtimes_enabled",
|
||||||
|
all_of = ["//cc/toolchains/features:static_link_cpp_runtimes"],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_feature_constraint(
|
||||||
|
name = "static_link_cpp_runtimes_disabled",
|
||||||
|
none_of = ["//cc/toolchains/features:static_link_cpp_runtimes"],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_args_list(
|
||||||
|
name = "runtime_library_search_directories",
|
||||||
|
args = [
|
||||||
|
":runtime_library_search_directories_static_runtimes_args",
|
||||||
|
":runtime_library_search_directories_args",
|
||||||
|
],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_args(
|
||||||
|
name = "runtime_library_search_directories_static_runtimes_args",
|
||||||
|
actions = [
|
||||||
|
"//cc/toolchains/actions:cpp_link_executable",
|
||||||
|
"//cc/toolchains/actions:cpp_link_dynamic_library",
|
||||||
|
"//cc/toolchains/actions:cpp_link_nodeps_dynamic_library",
|
||||||
|
"//cc/toolchains/actions:lto_index_for_executable",
|
||||||
|
"//cc/toolchains/actions:lto_index_for_dynamic_library",
|
||||||
|
"//cc/toolchains/actions:lto_index_for_nodeps_dynamic_library",
|
||||||
|
],
|
||||||
|
nested = [":iterate_over_search_dirs"],
|
||||||
|
requires_any_of = [":static_link_cpp_runtimes_enabled"],
|
||||||
|
requires_not_none = "//cc/toolchains/variables:runtime_library_search_directories",
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_nested_args(
|
||||||
|
name = "iterate_over_search_dirs",
|
||||||
|
iterate_over = "//cc/toolchains/variables:runtime_library_search_directories",
|
||||||
|
nested = [
|
||||||
|
":unit_test_static_runtime_search_dir_args",
|
||||||
|
":static_runtime_search_dir_args",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_nested_args(
|
||||||
|
name = "unit_test_static_runtime_search_dir_args",
|
||||||
|
args = [
|
||||||
|
"-Xlinker",
|
||||||
|
"-rpath",
|
||||||
|
"-Xlinker",
|
||||||
|
# TODO(b/27153401): This should probably be @loader_path on osx.
|
||||||
|
"$EXEC_ORIGIN/{search_path}",
|
||||||
|
],
|
||||||
|
format = {
|
||||||
|
"search_path": "//cc/toolchains/variables:runtime_library_search_directories",
|
||||||
|
},
|
||||||
|
requires_true = "//cc/toolchains/variables:is_cc_test",
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_nested_args(
|
||||||
|
name = "static_runtime_search_dir_args",
|
||||||
|
args = [
|
||||||
|
"-Xlinker",
|
||||||
|
"-rpath",
|
||||||
|
"-Xlinker",
|
||||||
|
] + select({
|
||||||
|
"@platforms//os:macos": ["@loader_path/{search_path}"],
|
||||||
|
"//conditions:default": ["$EXEC_ORIGIN/{search_path}"],
|
||||||
|
}),
|
||||||
|
format = {
|
||||||
|
"search_path": "//cc/toolchains/variables:runtime_library_search_directories",
|
||||||
|
},
|
||||||
|
requires_false = "//cc/toolchains/variables:is_cc_test",
|
||||||
|
)
|
||||||
|
|
||||||
|
# TODO: b/27153401 - runtime_library_search_directories_args and
|
||||||
|
# search_dir_args are all we need to keep if the workaround is no
|
||||||
|
# longer required.
|
||||||
|
cc_args(
|
||||||
|
name = "runtime_library_search_directories_args",
|
||||||
|
actions = [
|
||||||
|
"//cc/toolchains/actions:cpp_link_executable",
|
||||||
|
"//cc/toolchains/actions:cpp_link_dynamic_library",
|
||||||
|
"//cc/toolchains/actions:cpp_link_nodeps_dynamic_library",
|
||||||
|
"//cc/toolchains/actions:lto_index_for_executable",
|
||||||
|
"//cc/toolchains/actions:lto_index_for_dynamic_library",
|
||||||
|
"//cc/toolchains/actions:lto_index_for_nodeps_dynamic_library",
|
||||||
|
],
|
||||||
|
nested = [":search_dir_args"],
|
||||||
|
# Remove the requires_any_of here if the workaround for b/27153401 is no
|
||||||
|
# longer required.
|
||||||
|
requires_any_of = [":static_link_cpp_runtimes_disabled"],
|
||||||
|
requires_not_none = "//cc/toolchains/variables:runtime_library_search_directories",
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_nested_args(
|
||||||
|
name = "search_dir_args",
|
||||||
|
args = [
|
||||||
|
"-Xlinker",
|
||||||
|
"-rpath",
|
||||||
|
"-Xlinker",
|
||||||
|
] + select({
|
||||||
|
"@platforms//os:macos": ["@loader_path/{search_path}"],
|
||||||
|
"//conditions:default": ["$EXEC_ORIGIN/{search_path}"],
|
||||||
|
}),
|
||||||
|
format = {
|
||||||
|
"search_path": "//cc/toolchains/variables:runtime_library_search_directories",
|
||||||
|
},
|
||||||
|
iterate_over = "//cc/toolchains/variables:runtime_library_search_directories",
|
||||||
|
)
|
|
@ -116,6 +116,7 @@ cc_external_feature(
|
||||||
|
|
||||||
cc_external_feature(
|
cc_external_feature(
|
||||||
name = "runtime_library_search_directories",
|
name = "runtime_library_search_directories",
|
||||||
|
deprecation = "Use //cc/toolchains/args/runtime_library_search_directories instead",
|
||||||
feature_name = "runtime_library_search_directories",
|
feature_name = "runtime_library_search_directories",
|
||||||
overridable = True,
|
overridable = True,
|
||||||
)
|
)
|
||||||
|
|
|
@ -33,6 +33,15 @@ compare_feature_implementation(
|
||||||
expected = "//tests/rule_based_toolchain/legacy_features_as_args:goldens/unix/linker_param_file.textproto",
|
expected = "//tests/rule_based_toolchain/legacy_features_as_args:goldens/unix/linker_param_file.textproto",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
compare_feature_implementation(
|
||||||
|
name = "runtime_library_search_directories_test",
|
||||||
|
actual_implementation = "//cc/toolchains/args/runtime_library_search_directories",
|
||||||
|
expected = select({
|
||||||
|
"@platforms//os:macos": "//tests/rule_based_toolchain/legacy_features_as_args:goldens/macos/runtime_library_search_directories.textproto",
|
||||||
|
"//conditions:default": "//tests/rule_based_toolchain/legacy_features_as_args:goldens/unix/runtime_library_search_directories.textproto",
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
compare_feature_implementation(
|
compare_feature_implementation(
|
||||||
name = "shared_flag_test",
|
name = "shared_flag_test",
|
||||||
actual_implementation = "//cc/toolchains/args/shared_flag",
|
actual_implementation = "//cc/toolchains/args/shared_flag",
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
enabled: false
|
||||||
|
flag_sets {
|
||||||
|
actions: "c++-link-dynamic-library"
|
||||||
|
actions: "c++-link-executable"
|
||||||
|
actions: "c++-link-nodeps-dynamic-library"
|
||||||
|
actions: "lto-index-for-dynamic-library"
|
||||||
|
actions: "lto-index-for-executable"
|
||||||
|
actions: "lto-index-for-nodeps-dynamic-library"
|
||||||
|
flag_groups {
|
||||||
|
expand_if_available: "runtime_library_search_directories"
|
||||||
|
flag_groups {
|
||||||
|
flag_groups {
|
||||||
|
expand_if_true: "is_cc_test"
|
||||||
|
flags: "-Xlinker"
|
||||||
|
flags: "-rpath"
|
||||||
|
flags: "-Xlinker"
|
||||||
|
flags: "$EXEC_ORIGIN/%{runtime_library_search_directories}"
|
||||||
|
}
|
||||||
|
flag_groups {
|
||||||
|
expand_if_false: "is_cc_test"
|
||||||
|
flags: "-Xlinker"
|
||||||
|
flags: "-rpath"
|
||||||
|
flags: "-Xlinker"
|
||||||
|
flags: "@loader_path/%{runtime_library_search_directories}"
|
||||||
|
}
|
||||||
|
iterate_over: "runtime_library_search_directories"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
with_features {
|
||||||
|
features: "static_link_cpp_runtimes"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
flag_sets {
|
||||||
|
actions: "c++-link-dynamic-library"
|
||||||
|
actions: "c++-link-executable"
|
||||||
|
actions: "c++-link-nodeps-dynamic-library"
|
||||||
|
actions: "lto-index-for-dynamic-library"
|
||||||
|
actions: "lto-index-for-executable"
|
||||||
|
actions: "lto-index-for-nodeps-dynamic-library"
|
||||||
|
flag_groups {
|
||||||
|
expand_if_available: "runtime_library_search_directories"
|
||||||
|
flag_groups {
|
||||||
|
flags: "-Xlinker"
|
||||||
|
flags: "-rpath"
|
||||||
|
flags: "-Xlinker"
|
||||||
|
flags: "@loader_path/%{runtime_library_search_directories}"
|
||||||
|
iterate_over: "runtime_library_search_directories"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
with_features {
|
||||||
|
not_features: "static_link_cpp_runtimes"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
name: "runtime_library_search_directories_test"
|
|
@ -0,0 +1,54 @@
|
||||||
|
enabled: false
|
||||||
|
flag_sets {
|
||||||
|
actions: "c++-link-dynamic-library"
|
||||||
|
actions: "c++-link-executable"
|
||||||
|
actions: "c++-link-nodeps-dynamic-library"
|
||||||
|
actions: "lto-index-for-dynamic-library"
|
||||||
|
actions: "lto-index-for-executable"
|
||||||
|
actions: "lto-index-for-nodeps-dynamic-library"
|
||||||
|
flag_groups {
|
||||||
|
expand_if_available: "runtime_library_search_directories"
|
||||||
|
flag_groups {
|
||||||
|
flag_groups {
|
||||||
|
expand_if_true: "is_cc_test"
|
||||||
|
flags: "-Xlinker"
|
||||||
|
flags: "-rpath"
|
||||||
|
flags: "-Xlinker"
|
||||||
|
flags: "$EXEC_ORIGIN/%{runtime_library_search_directories}"
|
||||||
|
}
|
||||||
|
flag_groups {
|
||||||
|
expand_if_false: "is_cc_test"
|
||||||
|
flags: "-Xlinker"
|
||||||
|
flags: "-rpath"
|
||||||
|
flags: "-Xlinker"
|
||||||
|
flags: "$EXEC_ORIGIN/%{runtime_library_search_directories}"
|
||||||
|
}
|
||||||
|
iterate_over: "runtime_library_search_directories"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
with_features {
|
||||||
|
features: "static_link_cpp_runtimes"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
flag_sets {
|
||||||
|
actions: "c++-link-dynamic-library"
|
||||||
|
actions: "c++-link-executable"
|
||||||
|
actions: "c++-link-nodeps-dynamic-library"
|
||||||
|
actions: "lto-index-for-dynamic-library"
|
||||||
|
actions: "lto-index-for-executable"
|
||||||
|
actions: "lto-index-for-nodeps-dynamic-library"
|
||||||
|
flag_groups {
|
||||||
|
expand_if_available: "runtime_library_search_directories"
|
||||||
|
flag_groups {
|
||||||
|
flags: "-Xlinker"
|
||||||
|
flags: "-rpath"
|
||||||
|
flags: "-Xlinker"
|
||||||
|
flags: "$EXEC_ORIGIN/%{runtime_library_search_directories}"
|
||||||
|
iterate_over: "runtime_library_search_directories"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
with_features {
|
||||||
|
not_features: "static_link_cpp_runtimes"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
name: "runtime_library_search_directories_test"
|
Loading…
Reference in New Issue