Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel Coverage failing to generate lcov with --@rules_rust//rust/settings:experimental_use_cc_common_link=true #2729

Open
Ryang20718 opened this issue Jul 6, 2024 · 1 comment · May be fixed by #2836
Labels

Comments

@Ryang20718
Copy link

Ryang20718 commented Jul 6, 2024

bazel coverage with the following additional build setting leads to .dat files not getting generated

build --@rules_rust//rust/settings:experimental_use_cc_common_link=true

To repro, first see code cov is generated on main.

git clone https://github.com/bazelbuild/rules_rust.git
bazelisk coverage //test/inline_test_with_deps/... 
cat bazel-out/_coverage/_coverage_report.dat

With this newly added flag, code coverage fails

bazelisk coverage //test/inline_test_with_deps/... --@rules_rust//rust/settings:experimental_use_cc_common_link=true
cat bazel-out/_coverage/_coverage_report.dat

reproable on bazel 7.2.1 and 6.5

@Ryang20718
Copy link
Author

Ryang20718 commented Aug 31, 2024

I’m attempting to debug why --@rules_rust//rust/settings:experimental_use_cc_common_link=true causes coverage instrumentation to fail to generate on rules_rust (0.49.3)

leveraging bazel’s -s --sandbox_debug, I’m seeing the main diff is --codegen=link-arg=--coverage (i think 😓 )

i.e, for a running bazel coverage on a rust_test without this flag --@rules_rust//rust/settings:experimental_use_cc_common_link=true enabled

bazel-out/k8-opt-exec-2B5CBBC6/bin/external/rules_rust/util/process_wrapper/process_wrapper
--arg-file
bazel-out/k8-opt/bin/external/crate_index__serde-1.0.204/serde_build_script.linksearchpaths
<snip>'--codegen=linker=/usr/bin/gcc'
'--codegen=link-arg=--coverage'
'--codegen=link-arg=-fuse-ld=gold'
'--codegen=link-arg=-Wl,-no-as-needed'
'--codegen=link-arg=-Wl,-z,relro,-z,now'
'--codegen=link-arg=-B/usr/bin'
'--codegen=link-arg=-pass-exit-codes'
'--codegen=link-arg=-lstdc++'
'--codegen=link-arg=-lm'
'--codegen=link-arg=-Wl,--gc-sections'
'--extern=serde=bazel-out/k8-opt/bin/external/crate_index__serde-1.0.204/libserde-1107839584.rlib'
'--extern=thiserror=bazel-out/k8-opt/bin/external/crate_index__thiserror-1.0.63/libthiserror-1171055757.rlib'
'-Ldependency=bazel-out/k8-opt-exec-2B5CBBC6/bin/external/crate_index__serde_derive-1.0.204'
'-Ldependency=bazel-out/k8-opt/bin/external/crate_index__serde-1.0.204'
'-Ldependency=bazel-out/k8-opt-exec-2B5CBBC6/bin/external/crate_index__thiserror-impl-1.0.63'
'-Ldependency=bazel-out/k8-opt/bin/external/crate_index__thiserror-1.0.63'
'--codegen=instrument-coverage'
'-Ctarget-cpu=x86-64-v3'
'-Cforce-frame-pointers=y'
'-Cforce-unwind-tables=y')

With this flag enabled, we don’t see codegen=link-arg=--coverage at all

I think it has to do with this:

if ctx.executable._process_wrapper:
# Run as normal
ctx.actions.run(
executable = ctx.executable._process_wrapper,
inputs = compile_inputs,
outputs = action_outputs,
env = env,
arguments = args.all,
mnemonic = "Rustc",
progress_message = "Compiling Rust {} {}{} ({} files)".format(
crate_info.type,
ctx.label.name,
formatted_version,
len(crate_info.srcs.to_list()),
),
toolchain = "@rules_rust//rust:toolchain_type",
)

I think we need to build and link these artifacts

if experimental_use_cc_common_link:
obj_ext = ".o"
output_o = ctx.actions.declare_file(crate_info.name + obj_ext, sibling = crate_info.output)
outputs = [output_o]

with --coverage flags, but I’m not entirely sure where those should be added? Wondering if I’m heading down the right direction?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants