Skip to content

Commit ba34f71

Browse files
committed
Selectively generate pdb
Only generate pdb files for windows if the strip level is set to none.
1 parent ec1b8d7 commit ba34f71

File tree

2 files changed

+69
-20
lines changed

2 files changed

+69
-20
lines changed

rust/private/rustc.bzl

+4-1
Original file line numberDiff line numberDiff line change
@@ -1289,12 +1289,15 @@ def rustc_compile_action(
12891289
if rustc_output:
12901290
action_outputs.append(rustc_output)
12911291

1292+
# Get the compilation mode for the current target.
1293+
compilation_mode = get_compilation_mode_opts(ctx, toolchain)
1294+
12921295
# Rustc generates a pdb file (on Windows) or a dsym folder (on macos) so provide it in an output group for crate
12931296
# types that benefit from having debug information in a separate file.
12941297
pdb_file = None
12951298
dsym_folder = None
12961299
if crate_info.type in ("cdylib", "bin"):
1297-
if toolchain.target_os == "windows":
1300+
if toolchain.target_os == "windows" and compilation_mode.strip_level == "none":
12981301
pdb_file = ctx.actions.declare_file(crate_info.output.basename[:-len(crate_info.output.extension)] + "pdb", sibling = crate_info.output)
12991302
action_outputs.append(pdb_file)
13001303
elif toolchain.target_os == "darwin":

test/unit/debug_info/debug_info_analysis_test.bzl

+65-19
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,61 @@
33
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
44
load("//rust:defs.bzl", "rust_binary", "rust_shared_library", "rust_test")
55

6-
def _pdb_file_test_impl(ctx):
6+
def _pdb_file_test_impl(ctx, expect_pdb_file):
77
env = analysistest.begin(ctx)
88
target = analysistest.target_under_test(env)
9-
109
files = target[DefaultInfo].files.to_list()
10+
11+
if not expect_pdb_file:
12+
asserts.equals(env, len(files), 0)
13+
return analysistest.end(env)
14+
1115
asserts.equals(env, len(files), 1)
1216
file = files[0]
1317
asserts.equals(env, file.extension, "pdb")
14-
1518
return analysistest.end(env)
1619

17-
pdb_file_test = analysistest.make(_pdb_file_test_impl)
20+
21+
22+
def _pdb_file_for_dbg_test_impl(ctx):
23+
"""Test for dbg compilation mode."""
24+
return _pdb_file_test_impl(ctx, True)
25+
26+
pdb_file_dbg_test = analysistest.make(
27+
_pdb_file_for_dbg_test_impl,
28+
config_settings = {
29+
"//command_line_option:compilation_mode": "dbg",
30+
}
31+
)
32+
33+
def _pdb_file_for_fastbuild_test_impl(ctx):
34+
"""Test for fastbuild compilation mode."""
35+
return _pdb_file_test_impl(ctx, True)
36+
37+
pdb_file_fastbuild_test = analysistest.make(
38+
_pdb_file_for_fastbuild_test_impl,
39+
config_settings = {
40+
"//command_line_option:compilation_mode": "fastbuild",
41+
}
42+
)
43+
44+
def _pdb_file_for_opt_test_impl(ctx):
45+
"""Test for opt compilation mode."""
46+
return _pdb_file_test_impl(ctx, False)
47+
48+
pdb_file_opt_test = analysistest.make(
49+
_pdb_file_for_opt_test_impl,
50+
config_settings = {
51+
"//command_line_option:compilation_mode": "opt",
52+
}
53+
)
54+
55+
# Mapping from compilation mode to pdb file test.
56+
pdb_file_tests = {
57+
"dbg": pdb_file_dbg_test,
58+
"fastbuild": pdb_file_fastbuild_test,
59+
"opt": pdb_file_opt_test
60+
}
1861

1962
def _dsym_folder_test_impl(ctx):
2063
env = analysistest.begin(ctx)
@@ -47,11 +90,12 @@ def debug_info_analysis_test_suite(name):
4790
output_group = "pdb_file",
4891
)
4992

50-
pdb_file_test(
51-
name = "lib_pdb_test",
52-
target_under_test = ":mylib.pdb",
53-
target_compatible_with = ["@platforms//os:windows"],
54-
)
93+
for compilation_mode, pdb_test in pdb_file_tests.items():
94+
pdb_test(
95+
name = "lib_pdb_test_{}".format(compilation_mode),
96+
target_under_test = ":mylib.pdb",
97+
target_compatible_with = ["@platforms//os:windows"],
98+
)
5599

56100
native.filegroup(
57101
name = "mylib.dSYM",
@@ -77,11 +121,12 @@ def debug_info_analysis_test_suite(name):
77121
output_group = "pdb_file",
78122
)
79123

80-
pdb_file_test(
81-
name = "bin_pdb_test",
82-
target_under_test = ":mybin.pdb",
83-
target_compatible_with = ["@platforms//os:windows"],
84-
)
124+
for compilation_mode, pdb_test in pdb_file_tests.items():
125+
pdb_test(
126+
name = "bin_pdb_test_{}".format(compilation_mode),
127+
target_under_test = ":mybin.pdb",
128+
target_compatible_with = ["@platforms//os:windows"],
129+
)
85130

86131
native.filegroup(
87132
name = "mybin.dSYM",
@@ -108,11 +153,12 @@ def debug_info_analysis_test_suite(name):
108153
testonly = True,
109154
)
110155

111-
pdb_file_test(
112-
name = "test_pdb_test",
113-
target_under_test = ":mytest.pdb",
114-
target_compatible_with = ["@platforms//os:windows"],
115-
)
156+
for compilation_mode, pdb_test in pdb_file_tests.items():
157+
pdb_test(
158+
name = "test_pdb_test_{}".format(compilation_mode),
159+
target_under_test = ":mytest.pdb",
160+
target_compatible_with = ["@platforms//os:windows"],
161+
)
116162

117163
native.filegroup(
118164
name = "mytest.dSYM",

0 commit comments

Comments
 (0)