Skip to content

Commit

Permalink
Declare pdb output when "generate_pdb_file" is enabled with cc_common…
Browse files Browse the repository at this point in the history
….link

This replicates the behavior of the `cc_binary` rule.
  • Loading branch information
yuzhy8701 committed Feb 12, 2025
1 parent f374c01 commit 57cc03c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
6 changes: 6 additions & 0 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
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
30 changes: 28 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 @@ -65,11 +65,16 @@ def _use_cc_common_link_test(ctx):

output_groups = tut[OutputGroupInfo]
asserts.false(env, hasattr(output_groups, "dsym_folder"), "Expected no dsym_folder output group")
asserts.false(env, hasattr(output_groups, "pdb_file"), "Expected no pdb_file 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 @@ -106,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 @@ -146,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

0 comments on commit 57cc03c

Please sign in to comment.