Skip to content

Commit 7176ab4

Browse files
authored
Add libLLVM to coverage runfiles (#3546)
Fixes #2760
1 parent 31d8c8a commit 7176ab4

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

rust/private/repository_utils.bzl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@ def BUILD_for_clippy(target_triple):
172172
)
173173

174174
_build_file_for_llvm_tools = """\
175+
filegroup(
176+
name = "llvm_lib",
177+
srcs = glob(
178+
["lib/rustlib/{target_triple}/lib/libLLVM*.so*"],
179+
allow_empty = True,
180+
),
181+
visibility = ["//visibility:public"],
182+
)
183+
175184
filegroup(
176185
name = "llvm_cov_bin",
177186
srcs = ["lib/rustlib/{target_triple}/bin/llvm-cov{binary_ext}"],
@@ -255,6 +264,7 @@ rust_toolchain(
255264
cargo_clippy = "//:cargo_clippy_bin",
256265
llvm_cov = {llvm_cov_label},
257266
llvm_profdata = {llvm_profdata_label},
267+
llvm_lib = {llvm_lib_label},
258268
rustc_lib = "//:rustc_lib",
259269
allocator_library = {allocator_library},
260270
global_allocator_library = {global_allocator_library},
@@ -322,9 +332,11 @@ def BUILD_for_rust_toolchain(
322332
rustfmt_label = "\"//:rustfmt_bin\""
323333
llvm_cov_label = "None"
324334
llvm_profdata_label = "None"
335+
llvm_lib_label = "None"
325336
if include_llvm_tools:
326337
llvm_cov_label = "\"//:llvm_cov_bin\""
327338
llvm_profdata_label = "\"//:llvm_profdata_bin\""
339+
llvm_lib_label = "\"//:llvm_lib\""
328340
allocator_library_label = "None"
329341
if allocator_library:
330342
allocator_library_label = "\"{allocator_library}\"".format(allocator_library = allocator_library)
@@ -346,6 +358,7 @@ def BUILD_for_rust_toolchain(
346358
rustfmt_label = rustfmt_label,
347359
llvm_cov_label = llvm_cov_label,
348360
llvm_profdata_label = llvm_profdata_label,
361+
llvm_lib_label = llvm_lib_label,
349362
extra_rustc_flags = extra_rustc_flags,
350363
extra_exec_rustc_flags = extra_exec_rustc_flags,
351364
opt_level = opt_level,

rust/private/rustc.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@ def rustc_compile_action(
15251525

15261526
coverage_runfiles = []
15271527
if toolchain.llvm_cov and ctx.configuration.coverage_enabled and crate_info.is_test:
1528-
coverage_runfiles = [toolchain.llvm_cov, toolchain.llvm_profdata]
1528+
coverage_runfiles = [toolchain.llvm_cov, toolchain.llvm_profdata] + toolchain.llvm_lib
15291529

15301530
experimental_use_coverage_metadata_files = toolchain._experimental_use_coverage_metadata_files
15311531

rust/toolchain.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ def _rust_toolchain_impl(ctx):
716716
make_libstd_and_allocator_ccinfo = make_ccinfo,
717717
llvm_cov = ctx.file.llvm_cov,
718718
llvm_profdata = ctx.file.llvm_profdata,
719+
llvm_lib = ctx.files.llvm_lib,
719720
lto = lto,
720721
make_variables = make_variable_info,
721722
rust_doc = sysroot.rustdoc,
@@ -863,6 +864,11 @@ rust_toolchain = rule(
863864
allow_single_file = True,
864865
cfg = "exec",
865866
),
867+
"llvm_lib": attr.label(
868+
doc = "The location of the `libLLVM` shared object files. If `llvm_cov` is None, this can be None as well and rust code is not instrumented for coverage.",
869+
allow_files = True,
870+
cfg = "exec",
871+
),
866872
"llvm_tools": attr.label(
867873
doc = "LLVM tools that are shipped with the Rust toolchain.",
868874
allow_files = True,

0 commit comments

Comments
 (0)