Skip to content

Commit 1f6d91f

Browse files
authored
Handle debug info packages separately when using cc_common.link (#3257)
Debug info packages (`dSYM`, `pdb`) are created by `rustc` only if you link with `rustc`. When linking with `cc_common`, they should be handled by the cc toolchain or a custom aspect. Declaring them prematurely can cause conflicts. This PR removes the `dsym_folder` declaration if `cc_common.link` is being used - since cc_common doesn't support dsym generation yet. It postpones the declaration of `pdb_file` after checking with the cpp features first.
1 parent 42d8d90 commit 1f6d91f

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

rust/private/rustc.bzl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,7 @@ def rustc_compile_action(
13351335
# types that benefit from having debug information in a separate file.
13361336
pdb_file = None
13371337
dsym_folder = None
1338-
if crate_info.type in ("cdylib", "bin"):
1338+
if crate_info.type in ("cdylib", "bin") and not experimental_use_cc_common_link:
13391339
if toolchain.target_os == "windows" and compilation_mode.strip_level == "none":
13401340
pdb_file = ctx.actions.declare_file(crate_info.output.basename[:-len(crate_info.output.extension)] + "pdb", sibling = crate_info.output)
13411341
action_outputs.append(pdb_file)
@@ -1463,6 +1463,11 @@ def rustc_compile_action(
14631463
# Append the name of the library
14641464
output_relative_to_package = output_relative_to_package + output_lib
14651465

1466+
additional_linker_outputs = []
1467+
if crate_info.type in ("cdylib", "bin") and cc_common.is_enabled(feature_configuration = feature_configuration, feature_name = "generate_pdb_file"):
1468+
pdb_file = ctx.actions.declare_file(crate_info.output.basename[:-len(crate_info.output.extension)] + "pdb", sibling = crate_info.output)
1469+
additional_linker_outputs.append(pdb_file)
1470+
14661471
cc_common.link(
14671472
actions = ctx.actions,
14681473
feature_configuration = feature_configuration,
@@ -1472,6 +1477,7 @@ def rustc_compile_action(
14721477
name = output_relative_to_package,
14731478
stamp = ctx.attr.stamp,
14741479
output_type = "executable" if crate_info.type == "bin" else "dynamic_library",
1480+
additional_outputs = additional_linker_outputs,
14751481
)
14761482

14771483
outputs = [crate_info.output]

test/cc_common_link/unit/cc_common_link_test.bzl

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use_cc_common_link_transition = transition(
3131
)
3232

3333
def _use_cc_common_link_on_target_impl(ctx):
34-
return [ctx.attr.target[0][DepActionsInfo]]
34+
return [ctx.attr.target[0][DepActionsInfo], ctx.attr.target[0][OutputGroupInfo]]
3535

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

66+
output_groups = tut[OutputGroupInfo]
67+
asserts.false(env, hasattr(output_groups, "dsym_folder"), "Expected no dsym_folder output group")
68+
asserts.equals(
69+
env,
70+
ctx.attr.expect_pdb,
71+
hasattr(output_groups, "pdb_file"),
72+
"Expected " + ("" if ctx.attr.expect_pdb else "no ") + "pdb_file output group",
73+
)
74+
6675
return analysistest.end(env)
6776

68-
use_cc_common_link_test = analysistest.make(_use_cc_common_link_test)
77+
use_cc_common_link_test = analysistest.make(_use_cc_common_link_test, attrs = {"expect_pdb": attr.bool()})
6978

7079
def _custom_malloc_test(ctx):
7180
env = analysistest.begin(ctx)
@@ -102,6 +111,18 @@ def _cc_common_link_test_targets():
102111
target = ":bin",
103112
)
104113

114+
rust_binary(
115+
name = "bin_with_pdb",
116+
srcs = ["bin.rs"],
117+
edition = "2018",
118+
features = ["generate_pdb_file"],
119+
)
120+
121+
use_cc_common_link_on_target(
122+
name = "bin_with_cc_common_link_with_pdb",
123+
target = ":bin_with_pdb",
124+
)
125+
105126
rust_shared_library(
106127
name = "cdylib",
107128
srcs = ["lib.rs"],
@@ -142,6 +163,15 @@ def _cc_common_link_test_targets():
142163
target_under_test = ":bin_with_cc_common_link",
143164
)
144165

166+
use_cc_common_link_test(
167+
name = "use_cc_common_link_on_binary_with_pdb",
168+
target_under_test = ":bin_with_cc_common_link_with_pdb",
169+
expect_pdb = select({
170+
"@platforms//os:windows": True,
171+
"//conditions:default": False,
172+
}),
173+
)
174+
145175
use_cc_common_link_test(
146176
name = "use_cc_common_link_on_test",
147177
target_under_test = ":test_with_cc_common_link",
@@ -174,6 +204,7 @@ def cc_common_link_test_suite(name):
174204
name = name,
175205
tests = [
176206
"use_cc_common_link_on_binary",
207+
"use_cc_common_link_on_binary_with_pdb",
177208
"use_cc_common_link_on_test",
178209
"use_cc_common_link_on_crate_test",
179210
"use_cc_common_link_on_cdylib",

0 commit comments

Comments
 (0)