From 0cd6ec970dbe07f6c6a39482d4a6674d4623a0c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gammels=C3=A6ter?= Date: Thu, 11 Jun 2026 13:38:18 +0200 Subject: [PATCH] Fix coverage for crates with mixed sources Crates with generated sources are compiled from the output tree, so their coverage mapping records bazel-out/... paths, which Bazel's lcov merger silently drops. Remap the prefix away so coverage paths come out workspace-relative. --- rust/private/rustc.bzl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index 5b99bae9e2..0496efd827 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -1303,6 +1303,15 @@ def construct_arguments( # https://doc.rust-lang.org/rustc/instrument-coverage.html rustc_flags.add("--codegen=instrument-coverage") + # Crates with generated sources are compiled from the output tree (see + # `transform_sources`), so the coverage mapping records their files + # with a bazel-out/... prefix. Bazel's lcov merger silently drops all + # coverage for such crates, so we remap the prefix away. Skipped when + # `remap_path_prefix` is None (rustdoc), since rustdoc only supports + # `--remap-path-prefix` behind `-Zunstable-options`. + if remap_path_prefix != None: + rustc_flags.add("--remap-path-prefix={}/=".format(ctx.bin_dir.path)) + if toolchain._experimental_link_std_dylib: rustc_flags.add("--codegen=prefer-dynamic")