Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cc/private/link/finalize_link_action.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def finalize_link_action(
else:
tool_path = _cc_common_internal.get_tool_for_action(
feature_configuration = feature_configuration,
action_name = link_type.action_name,
action_name = action_name,
)

if link_type.linker_or_archiver == USE_ARCHIVER:
Expand Down
3 changes: 3 additions & 0 deletions cc/toolchains/legacy_file_group.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ LEGACY_FILE_GROUPS = {
Label("//cc/toolchains/actions:cpp_link_nodeps_dynamic_library"),
Label("//cc/toolchains/actions:cpp_link_executable"),
Label("//cc/toolchains/actions:generate_def_file"),
Label("//cc/toolchains/actions:lto_index_for_dynamic_library"),
Label("//cc/toolchains/actions:lto_index_for_executable"),
Label("//cc/toolchains/actions:lto_index_for_nodeps_dynamic_library"),
],
"objcopy_files": [
Label("//cc/toolchains/actions:objcopy_embed_data"),
Expand Down
27 changes: 27 additions & 0 deletions tests/cc/common/cc_binary_thin_lto_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ load("@bazel_features//:features.bzl", "bazel_features")
load("@rules_testing//lib:analysis_test.bzl", "test_suite")
load("@rules_testing//lib:truth.bzl", "matching", "subjects")
load("@rules_testing//lib:util.bzl", "TestingAspectInfo", "util")
load("//cc:action_names.bzl", "ACTION_NAMES")
load("//cc:cc_binary.bzl", _actual_cc_binary = "cc_binary")
load("//cc:cc_library.bzl", "cc_library")
load("//cc:cc_test.bzl", _actual_cc_test = "cc_test")
Expand Down Expand Up @@ -176,6 +177,31 @@ def _test_thin_lto_action_graph_impl(env, target):
),
)

def _test_thin_lto_index_uses_its_action_tool(name, **kwargs):
util.helper_target(
cc_binary,
name = name + "/bin",
srcs = ["hello.cc"],
)
cc_analysis_test(
name = name,
impl = _test_thin_lto_index_uses_its_action_tool_impl,
target = name + "/bin",
test_features = ["thin_lto", "supports_start_end_lib"],
with_action_configs = [
ACTION_NAMES.cpp_link_executable,
ACTION_NAMES.lto_index_for_executable,
],
**kwargs
)

def _test_thin_lto_index_uses_its_action_tool_impl(env, target):
index_action = env.expect.that_target(target).action_named("CppLTOIndexing")
env.expect.that_str(index_action.actual.argv[0]).equals("tests/cc/testutil/toolchains/lto_index_tool")

link_action = env.expect.that_target(target).action_named("CppLink")
env.expect.that_str(link_action.actual.argv[0]).equals("tests/cc/testutil/toolchains/link_executable_tool")

def _test_thin_lto_linkshared(name, **kwargs):
util.helper_target(
cc_library,
Expand Down Expand Up @@ -2345,6 +2371,7 @@ def cc_binary_thin_lto_tests(name):

# These tests fail on Bazel 7 and 8, run only for Bazel 9+.
if bazel_features.cc.cc_common_is_in_rules_cc:
tests.append(_test_thin_lto_index_uses_its_action_tool)
tests.append(_test_thin_lto_linkshared)
tests.append(_test_thin_lto_backend_env)
tests.append(_test_linkstatic_cc_test)
Expand Down
2 changes: 2 additions & 0 deletions tests/cc/testutil/toolchains/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1900,7 +1900,9 @@ _action_name_to_action = {
}

_tool_for_action_config = {
"c++-link-executable": "link_executable_tool",
"generate-def-file": "def_parser_tool",
"lto-index-for-executable": "lto_index_tool",
"objcopy_embed_data": "objcopy_embed_data_tool",
"ld_embed_data": "ld_embed_data_tool",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ load(
)
load("//cc/toolchains:cc_toolchain_config_info.bzl", "CcToolchainConfigInfo")
load("//cc/toolchains:cc_toolchain_info.bzl", "ActionTypeInfo", "ToolchainConfigInfo")
load("//cc/toolchains:legacy_file_group.bzl", "LEGACY_FILE_GROUPS")
load("//cc/toolchains/impl:legacy_converter.bzl", "convert_toolchain")
load("//cc/toolchains/impl:toolchain_config_info.bzl", _toolchain_config_info = "toolchain_config_info")
load("//tests/rule_based_toolchain:helpers.bzl", "path_pattern")
Expand Down Expand Up @@ -277,6 +278,13 @@ def _toolchain_collects_files_test(env, targets):
),
]).in_order()

def _thin_lto_index_actions_are_linker_files_test(env, _targets):
env.expect.that_collection(LEGACY_FILE_GROUPS["linker_files"]).contains_at_least([
Label("//cc/toolchains/actions:lto_index_for_dynamic_library"),
Label("//cc/toolchains/actions:lto_index_for_executable"),
Label("//cc/toolchains/actions:lto_index_for_nodeps_dynamic_library"),
])

def _tool_env_wires_into_toolchain_test(env, targets):
tc = env.expect.that_target(targets.tool_env_toolchain_config).provider(ToolchainConfigInfo)
legacy = convert_toolchain(tc.actual)
Expand Down Expand Up @@ -395,6 +403,7 @@ TESTS = {
"args_missing_requirements_invalid_test": _args_missing_requirements_invalid_test,
"args_requiring_capability_valid_test": _args_requiring_capability_valid_test,
"toolchain_collects_files_test": _toolchain_collects_files_test,
"thin_lto_index_actions_are_linker_files_test": _thin_lto_index_actions_are_linker_files_test,
"tool_env_wires_into_toolchain_test": _tool_env_wires_into_toolchain_test,
"legacy_tools_produce_tool_paths_test": _legacy_tools_produce_tool_paths_test,
"rules_based_cc_toolchain_returns_cc_toolchain_config_info_test": _rules_based_cc_toolchain_returns_cc_toolchain_config_info_test,
Expand Down