Skip to content

Handle debug info packages separately when using cc_common.link #3257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 27, 2025
Merged
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
8 changes: 7 additions & 1 deletion rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ def rustc_compile_action(
# types that benefit from having debug information in a separate file.
pdb_file = None
dsym_folder = None
if crate_info.type in ("cdylib", "bin"):
if crate_info.type in ("cdylib", "bin") and not experimental_use_cc_common_link:
if toolchain.target_os == "windows" and compilation_mode.strip_level == "none":
pdb_file = ctx.actions.declare_file(crate_info.output.basename[:-len(crate_info.output.extension)] + "pdb", sibling = crate_info.output)
action_outputs.append(pdb_file)
Expand Down Expand Up @@ -1463,6 +1463,11 @@ def rustc_compile_action(
# Append the name of the library
output_relative_to_package = output_relative_to_package + output_lib

additional_linker_outputs = []
if crate_info.type in ("cdylib", "bin") and cc_common.is_enabled(feature_configuration = feature_configuration, feature_name = "generate_pdb_file"):
pdb_file = ctx.actions.declare_file(crate_info.output.basename[:-len(crate_info.output.extension)] + "pdb", sibling = crate_info.output)
additional_linker_outputs.append(pdb_file)

cc_common.link(
actions = ctx.actions,
feature_configuration = feature_configuration,
Expand All @@ -1472,6 +1477,7 @@ def rustc_compile_action(
name = output_relative_to_package,
stamp = ctx.attr.stamp,
output_type = "executable" if crate_info.type == "bin" else "dynamic_library",
additional_outputs = additional_linker_outputs,
)

outputs = [crate_info.output]
Expand Down
35 changes: 33 additions & 2 deletions test/cc_common_link/unit/cc_common_link_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use_cc_common_link_transition = transition(
)

def _use_cc_common_link_on_target_impl(ctx):
return [ctx.attr.target[0][DepActionsInfo]]
return [ctx.attr.target[0][DepActionsInfo], ctx.attr.target[0][OutputGroupInfo]]

use_cc_common_link_on_target = rule(
implementation = _use_cc_common_link_on_target_impl,
Expand Down Expand Up @@ -63,9 +63,18 @@ def _use_cc_common_link_test(ctx):
has_cpp_link_action = len([action for action in registered_actions if action.mnemonic == "CppLink"]) > 0
asserts.true(env, has_cpp_link_action, "Expected that the target registers a CppLink action")

output_groups = tut[OutputGroupInfo]
asserts.false(env, hasattr(output_groups, "dsym_folder"), "Expected no dsym_folder output group")
asserts.equals(
env,
ctx.attr.expect_pdb,
hasattr(output_groups, "pdb_file"),
"Expected " + ("" if ctx.attr.expect_pdb else "no ") + "pdb_file output group",
)

return analysistest.end(env)

use_cc_common_link_test = analysistest.make(_use_cc_common_link_test)
use_cc_common_link_test = analysistest.make(_use_cc_common_link_test, attrs = {"expect_pdb": attr.bool()})

def _custom_malloc_test(ctx):
env = analysistest.begin(ctx)
Expand Down Expand Up @@ -102,6 +111,18 @@ def _cc_common_link_test_targets():
target = ":bin",
)

rust_binary(
name = "bin_with_pdb",
srcs = ["bin.rs"],
edition = "2018",
features = ["generate_pdb_file"],
)

use_cc_common_link_on_target(
name = "bin_with_cc_common_link_with_pdb",
target = ":bin_with_pdb",
)

rust_shared_library(
name = "cdylib",
srcs = ["lib.rs"],
Expand Down Expand Up @@ -142,6 +163,15 @@ def _cc_common_link_test_targets():
target_under_test = ":bin_with_cc_common_link",
)

use_cc_common_link_test(
name = "use_cc_common_link_on_binary_with_pdb",
target_under_test = ":bin_with_cc_common_link_with_pdb",
expect_pdb = select({
"@platforms//os:windows": True,
"//conditions:default": False,
}),
)

use_cc_common_link_test(
name = "use_cc_common_link_on_test",
target_under_test = ":test_with_cc_common_link",
Expand Down Expand Up @@ -174,6 +204,7 @@ def cc_common_link_test_suite(name):
name = name,
tests = [
"use_cc_common_link_on_binary",
"use_cc_common_link_on_binary_with_pdb",
"use_cc_common_link_on_test",
"use_cc_common_link_on_crate_test",
"use_cc_common_link_on_cdylib",
Expand Down