Skip to content

Commit

Permalink
Provide pdb file for cydlib/bin on Windows in a pdb_file output group
Browse files Browse the repository at this point in the history
I've chose the `pdb_file` name for the output group since it matches
what `cc_binary` uses
(https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java;l=707)

There is one edge case that is not covered here: if the user passes
`/DEBUG:NONE` in the `rustc_flags` no pdb will be generated and I
imagine the build will fail since it's now missing an output. I guess we
could check the `rustc_flags` for it but I don't know if it's the right
place to do so?
  • Loading branch information
ddeville committed Dec 13, 2021
1 parent c1274b6 commit 8b0e966
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
24 changes: 17 additions & 7 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -794,14 +794,22 @@ def rustc_compile_action(

outputs = [crate_info.output]

# For a cdylib that might be added as a dependency to a cc_* target on Windows, it is important to include the
# interface library that rustc generates in the output files.
interface_library = None
if toolchain.os == "windows" and crate_info.type == "cdylib":
# Rustc generates the import library with a `.dll.lib` extension rather than the usual `.lib` one that msvc
# expects (see https://github.com/rust-lang/rust/pull/29520 for more context).
interface_library = ctx.actions.declare_file(crate_info.output.basename + ".lib")
outputs.append(interface_library)
pdb_file = None
if toolchain.os == "windows":
# For a cdylib that might be added as a dependency to a cc_* target on Windows, it is important to include the
# interface library that rustc generates in the output files.
if crate_info.type == "cdylib":
# Rustc generates the import library with a `.dll.lib` extension rather than the usual `.lib` one that msvc
# expects (see https://github.com/rust-lang/rust/pull/29520 for more context).
interface_library = ctx.actions.declare_file(crate_info.output.basename + ".lib")
outputs.append(interface_library)

# rustc always generates a pdb file so provide it in an output group for crate types that are benefit from having
# debug information in a separate file.
if crate_info.type in ("cdylib", "bin"):
pdb_file = ctx.actions.declare_file(crate_info.output.basename.replace(crate_info.output.extension, "pdb"))
outputs.append(pdb_file)

ctx.actions.run(
executable = ctx.executable._process_wrapper,
Expand Down Expand Up @@ -839,6 +847,8 @@ def rustc_compile_action(
]
if toolchain.target_arch != "wasm32":
providers += establish_cc_info(ctx, attr, crate_info, toolchain, cc_toolchain, feature_configuration, interface_library)
if pdb_file:
providers.append(OutputGroupInfo(pdb_file = depset([pdb_file])))

return providers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def win_interface_library_analysis_test_suite(name):
target_compatible_with = ["@platforms//os:windows"],
)

native.filegroup(
name = "mylib.pdb",
srcs = [":mylib"],
output_group = "pdb_file",
)

cc_binary(
name = "mybin",
srcs = ["bin.cc"],
Expand Down

0 comments on commit 8b0e966

Please sign in to comment.