Skip to content

Commit

Permalink
Selectively generate pdb
Browse files Browse the repository at this point in the history
Only generate pdb files for windows if the strip level is set to
none.
  • Loading branch information
matte1 committed Apr 2, 2024
1 parent 15f3f76 commit 246de8a
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 23 deletions.
5 changes: 4 additions & 1 deletion rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1289,12 +1289,15 @@ def rustc_compile_action(
if rustc_output:
action_outputs.append(rustc_output)

# Get the compilation mode for the current target.
compilation_mode = get_compilation_mode_opts(ctx, toolchain)

# Rustc generates a pdb file (on Windows) or a dsym folder (on macos) so provide it in an output group for crate
# 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 toolchain.target_os == "windows":
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)
elif toolchain.target_os == "darwin":
Expand Down
96 changes: 74 additions & 22 deletions test/unit/debug_info/debug_info_analysis_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,61 @@
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
load("//rust:defs.bzl", "rust_binary", "rust_shared_library", "rust_test")

def _pdb_file_test_impl(ctx):
def _pdb_file_test_impl(ctx, expect_pdb_file):
env = analysistest.begin(ctx)
target = analysistest.target_under_test(env)

files = target[DefaultInfo].files.to_list()

if not expect_pdb_file:
asserts.equals(env, len(files), 0)
return analysistest.end(env)

asserts.equals(env, len(files), 1)
file = files[0]
asserts.equals(env, file.extension, "pdb")

return analysistest.end(env)

pdb_file_test = analysistest.make(_pdb_file_test_impl)


def _pdb_file_for_dbg_test_impl(ctx):
"""Test for dbg compilation mode."""
return _pdb_file_test_impl(ctx, True)

pdb_file_dbg_test = analysistest.make(
_pdb_file_for_dbg_test_impl,
config_settings = {
"//command_line_option:compilation_mode": "dbg",
}
)

def _pdb_file_for_fastbuild_test_impl(ctx):
"""Test for fastbuild compilation mode."""
return _pdb_file_test_impl(ctx, True)

pdb_file_fastbuild_test = analysistest.make(
_pdb_file_for_fastbuild_test_impl,
config_settings = {
"//command_line_option:compilation_mode": "fastbuild",
}
)

def _pdb_file_for_opt_test_impl(ctx):
"""Test for opt compilation mode."""
return _pdb_file_test_impl(ctx, False)

pdb_file_opt_test = analysistest.make(
_pdb_file_for_opt_test_impl,
config_settings = {
"//command_line_option:compilation_mode": "opt",
}
)

# Mapping from compilation mode to pdb file test.
pdb_file_tests = {
"dbg": pdb_file_dbg_test,
"fastbuild": pdb_file_fastbuild_test,
"opt": pdb_file_opt_test
}

def _dsym_folder_test_impl(ctx):
env = analysistest.begin(ctx)
Expand Down Expand Up @@ -47,11 +90,12 @@ def debug_info_analysis_test_suite(name):
output_group = "pdb_file",
)

pdb_file_test(
name = "lib_pdb_test",
target_under_test = ":mylib.pdb",
target_compatible_with = ["@platforms//os:windows"],
)
for compilation_mode, pdb_test in pdb_file_tests.items():
pdb_test(
name = "lib_pdb_test_{}".format(compilation_mode),
target_under_test = ":mylib.pdb",
target_compatible_with = ["@platforms//os:windows"],
)

native.filegroup(
name = "mylib.dSYM",
Expand All @@ -77,11 +121,12 @@ def debug_info_analysis_test_suite(name):
output_group = "pdb_file",
)

pdb_file_test(
name = "bin_pdb_test",
target_under_test = ":mybin.pdb",
target_compatible_with = ["@platforms//os:windows"],
)
for compilation_mode, pdb_test in pdb_file_tests.items():
pdb_test(
name = "bin_pdb_test_{}".format(compilation_mode),
target_under_test = ":mybin.pdb",
target_compatible_with = ["@platforms//os:windows"],
)

native.filegroup(
name = "mybin.dSYM",
Expand All @@ -108,11 +153,12 @@ def debug_info_analysis_test_suite(name):
testonly = True,
)

pdb_file_test(
name = "test_pdb_test",
target_under_test = ":mytest.pdb",
target_compatible_with = ["@platforms//os:windows"],
)
for compilation_mode, pdb_test in pdb_file_tests.items():
pdb_test(
name = "test_pdb_test_{}".format(compilation_mode),
target_under_test = ":mytest.pdb",
target_compatible_with = ["@platforms//os:windows"],
)

native.filegroup(
name = "mytest.dSYM",
Expand All @@ -130,11 +176,17 @@ def debug_info_analysis_test_suite(name):
native.test_suite(
name = name,
tests = [
":lib_pdb_test",
":lib_dsym_test",
":bin_pdb_test",
":bin_dsym_test",
":test_pdb_test",
":test_dsym_test",
] + [
":lib_pdb_test_{}".format(compilation_mode)
for compilation_mode in pdb_file_tests
] + [
":bin_pdb_test_{}".format(compilation_mode)
for compilation_mode in pdb_file_tests
] + [
":test_pdb_test_{}".format(compilation_mode)
for compilation_mode in pdb_file_tests
],
)

0 comments on commit 246de8a

Please sign in to comment.