Skip to content

Commit

Permalink
Support dsym_folder output group in tests (#1703)
Browse files Browse the repository at this point in the history
Unclear why #1072 explicitly didn't allow tests to generate dsym files via the `dsym_folder` output group.

This change allows them to do so and make debugging easier on macos.
 
Manual verification on macos:

```
bazel build -c dbg //test/unit/debug_info:myrusttest
rust-lldb bazel-bin/test/unit/debug_info/test-2282882243/myrusttest \
    --one-line "image list" \
    --one-line "exit" | \
    grep DWARF &>/dev/null && echo "dSYM module loaded"
```

should print `dSYM module loaded`
  • Loading branch information
chancila committed Dec 22, 2022
1 parent 90c5b6e commit 8bc9f78
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,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") and not crate_info.is_test:
if crate_info.type in ("cdylib", "bin"):
if toolchain.os == "windows":
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
36 changes: 35 additions & 1 deletion test/unit/debug_info/debug_info_analysis_test.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Analysis tests for debug info in cdylib and bin targets."""

load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
load("//rust:defs.bzl", "rust_binary", "rust_shared_library")
load("//rust:defs.bzl", "rust_binary", "rust_shared_library", "rust_test")

def _pdb_file_test_impl(ctx):
env = analysistest.begin(ctx)
Expand Down Expand Up @@ -95,12 +95,46 @@ def debug_info_analysis_test_suite(name):
target_compatible_with = ["@platforms//os:macos"],
)

rust_test(
name = "myrusttest",
srcs = ["test.rs"],
edition = "2018",
)

native.filegroup(
name = "mytest.pdb",
srcs = [":myrusttest"],
output_group = "pdb_file",
testonly = True,
)

pdb_file_test(
name = "test_pdb_test",
target_under_test = ":mytest.pdb",
target_compatible_with = ["@platforms//os:windows"],
)

native.filegroup(
name = "mytest.dSYM",
srcs = [":myrusttest"],
output_group = "dsym_folder",
testonly = True,
)

dsym_folder_test(
name = "test_dsym_test",
target_under_test = ":mytest.dSYM",
target_compatible_with = ["@platforms//os:macos"],
)

native.test_suite(
name = name,
tests = [
":lib_pdb_test",
":lib_dsym_test",
":bin_pdb_test",
":bin_dsym_test",
":test_pdb_test",
":test_dsym_test",
],
)
4 changes: 4 additions & 0 deletions test/unit/debug_info/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[test]
fn test() {
eprintln!("test");
}

0 comments on commit 8bc9f78

Please sign in to comment.