diff --git a/cc/private/link/finalize_link_action.bzl b/cc/private/link/finalize_link_action.bzl index a6ec53d50..610c36d6d 100644 --- a/cc/private/link/finalize_link_action.bzl +++ b/cc/private/link/finalize_link_action.bzl @@ -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: diff --git a/cc/toolchains/legacy_file_group.bzl b/cc/toolchains/legacy_file_group.bzl index dc51569ff..d5d88c85b 100644 --- a/cc/toolchains/legacy_file_group.bzl +++ b/cc/toolchains/legacy_file_group.bzl @@ -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"), diff --git a/tests/cc/common/cc_binary_thin_lto_tests.bzl b/tests/cc/common/cc_binary_thin_lto_tests.bzl index 5cbb1d116..c2a01e7e7 100644 --- a/tests/cc/common/cc_binary_thin_lto_tests.bzl +++ b/tests/cc/common/cc_binary_thin_lto_tests.bzl @@ -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") @@ -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, @@ -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) diff --git a/tests/cc/testutil/toolchains/cc_toolchain_config.bzl b/tests/cc/testutil/toolchains/cc_toolchain_config.bzl index 50fefe655..bd7bff10d 100644 --- a/tests/cc/testutil/toolchains/cc_toolchain_config.bzl +++ b/tests/cc/testutil/toolchains/cc_toolchain_config.bzl @@ -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", } diff --git a/tests/rule_based_toolchain/toolchain_config/toolchain_config_test.bzl b/tests/rule_based_toolchain/toolchain_config/toolchain_config_test.bzl index f668ba24b..b5a2d2b8f 100644 --- a/tests/rule_based_toolchain/toolchain_config/toolchain_config_test.bzl +++ b/tests/rule_based_toolchain/toolchain_config/toolchain_config_test.bzl @@ -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") @@ -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) @@ -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,