Skip to content

Commit df9cd17

Browse files
authored
Rollup merge of #125816 - Zalathar:demangler, r=oli-obk
Don't build the `rust-demangler` binary for coverage tests The coverage-run tests invoke `llvm-cov`, which requires us to specify a command-line demangler that it can use to demangle Rust symbol names. Historically this used `src/tools/rust-demangler`, which means that we currently build two different command-line tools to help with the coverage tests (`rust-demangler` and `coverage-dump`). However, it occurred to me that if we add a demangler mode to `coverage-dump` (which is only a handful of lines and no extra dependencies), then we only need to build one helper binary for the coverage tests, and there is no need for tests to build `rust-demangler` at all. --- Note that the `rust-demangler` binary is separate from the `rustc-demangle` crate (which both `rust-demangler` and `coverage-dump` use as a dependency to do the actual demangling). --- So the main benefits/motivations here are: - Slightly faster builds after a fresh checkout or bootstrap bump. - Making it clear that currently no tests actually need the `rust-demangler` binary, since the coverage tests can use their own tool instead.
2 parents 619b3e8 + 54b6849 commit df9cd17

File tree

7 files changed

+38
-31
lines changed

7 files changed

+38
-31
lines changed

src/bootstrap/src/core/build_steps/test.rs

+2-16
Original file line numberDiff line numberDiff line change
@@ -1781,25 +1781,11 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17811781
.arg(builder.ensure(tool::JsonDocLint { compiler: json_compiler, target }));
17821782
}
17831783

1784-
if mode == "coverage-map" {
1785-
let coverage_dump = builder.ensure(tool::CoverageDump {
1786-
compiler: compiler.with_stage(0),
1787-
target: compiler.host,
1788-
});
1784+
if matches!(mode, "coverage-map" | "coverage-run") {
1785+
let coverage_dump = builder.tool_exe(Tool::CoverageDump);
17891786
cmd.arg("--coverage-dump-path").arg(coverage_dump);
17901787
}
17911788

1792-
if mode == "coverage-run" {
1793-
// The demangler doesn't need the current compiler, so we can avoid
1794-
// unnecessary rebuilds by using the bootstrap compiler instead.
1795-
let rust_demangler = builder.ensure(tool::RustDemangler {
1796-
compiler: compiler.with_stage(0),
1797-
target: compiler.host,
1798-
extra_features: Vec::new(),
1799-
});
1800-
cmd.arg("--rust-demangler-path").arg(rust_demangler);
1801-
}
1802-
18031789
cmd.arg("--src-base").arg(builder.src.join("tests").join(suite));
18041790
cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite));
18051791

src/tools/compiletest/src/common.rs

-3
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,6 @@ pub struct Config {
187187
/// The rustdoc executable.
188188
pub rustdoc_path: Option<PathBuf>,
189189

190-
/// The rust-demangler executable.
191-
pub rust_demangler_path: Option<PathBuf>,
192-
193190
/// The coverage-dump executable.
194191
pub coverage_dump_path: Option<PathBuf>,
195192

src/tools/compiletest/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ pub fn parse_config(args: Vec<String>) -> Config {
4646
.reqopt("", "run-lib-path", "path to target shared libraries", "PATH")
4747
.reqopt("", "rustc-path", "path to rustc to use for compiling", "PATH")
4848
.optopt("", "rustdoc-path", "path to rustdoc to use for compiling", "PATH")
49-
.optopt("", "rust-demangler-path", "path to rust-demangler to use in tests", "PATH")
5049
.optopt("", "coverage-dump-path", "path to coverage-dump to use in tests", "PATH")
5150
.reqopt("", "python", "path to python to use for doc tests", "PATH")
5251
.optopt("", "jsondocck-path", "path to jsondocck to use for doc tests", "PATH")
@@ -232,7 +231,6 @@ pub fn parse_config(args: Vec<String>) -> Config {
232231
run_lib_path: make_absolute(opt_path(matches, "run-lib-path")),
233232
rustc_path: opt_path(matches, "rustc-path"),
234233
rustdoc_path: matches.opt_str("rustdoc-path").map(PathBuf::from),
235-
rust_demangler_path: matches.opt_str("rust-demangler-path").map(PathBuf::from),
236234
coverage_dump_path: matches.opt_str("coverage-dump-path").map(PathBuf::from),
237235
python: matches.opt_str("python").unwrap(),
238236
jsondocck_path: matches.opt_str("jsondocck-path"),
@@ -337,7 +335,6 @@ pub fn log_config(config: &Config) {
337335
logv(c, format!("run_lib_path: {:?}", config.run_lib_path));
338336
logv(c, format!("rustc_path: {:?}", config.rustc_path.display()));
339337
logv(c, format!("rustdoc_path: {:?}", config.rustdoc_path));
340-
logv(c, format!("rust_demangler_path: {:?}", config.rust_demangler_path));
341338
logv(c, format!("src_base: {:?}", config.src_base.display()));
342339
logv(c, format!("build_base: {:?}", config.build_base.display()));
343340
logv(c, format!("stage_id: {}", config.stage_id));

src/tools/compiletest/src/runtest.rs

-4
Original file line numberDiff line numberDiff line change
@@ -3561,10 +3561,6 @@ impl<'test> TestCx<'test> {
35613561
cmd.env("RUSTDOC", cwd.join(rustdoc));
35623562
}
35633563

3564-
if let Some(ref rust_demangler) = self.config.rust_demangler_path {
3565-
cmd.env("RUST_DEMANGLER", cwd.join(rust_demangler));
3566-
}
3567-
35683564
if let Some(ref node) = self.config.nodejs {
35693565
cmd.env("NODE", node);
35703566
}

src/tools/compiletest/src/runtest/coverage.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ use crate::common::{UI_COVERAGE, UI_COVERAGE_MAP};
1010
use crate::runtest::{static_regex, Emit, ProcRes, TestCx, WillExecute};
1111

1212
impl<'test> TestCx<'test> {
13+
fn coverage_dump_path(&self) -> &Path {
14+
self.config
15+
.coverage_dump_path
16+
.as_deref()
17+
.unwrap_or_else(|| self.fatal("missing --coverage-dump"))
18+
}
19+
1320
pub(crate) fn run_coverage_map_test(&self) {
14-
let Some(coverage_dump_path) = &self.config.coverage_dump_path else {
15-
self.fatal("missing --coverage-dump");
16-
};
21+
let coverage_dump_path = self.coverage_dump_path();
1722

1823
let (proc_res, llvm_ir_path) = self.compile_test_and_save_ir();
1924
if !proc_res.status.success() {
@@ -102,8 +107,10 @@ impl<'test> TestCx<'test> {
102107
let proc_res = self.run_llvm_tool("llvm-cov", |cmd| {
103108
cmd.args(["show", "--format=text", "--show-line-counts-or-regions"]);
104109

105-
cmd.arg("--Xdemangler");
106-
cmd.arg(self.config.rust_demangler_path.as_ref().unwrap());
110+
// Specify the demangler binary and its arguments.
111+
let coverage_dump_path = self.coverage_dump_path();
112+
cmd.arg("--Xdemangler").arg(coverage_dump_path);
113+
cmd.arg("--Xdemangler").arg("--demangle");
107114

108115
cmd.arg("--instr-profile");
109116
cmd.arg(&profdata_path);

src/tools/coverage-dump/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ The output format is mostly arbitrary, so it's OK to change the output as long
66
as any affected tests are also re-blessed. However, the output should be
77
consistent across different executions on different platforms, so avoid
88
printing any information that is platform-specific or non-deterministic.
9+
10+
## Demangle mode
11+
12+
When run as `coverage-dump --demangle`, this tool instead functions as a
13+
command-line demangler that can be invoked by `llvm-cov`.

src/tools/coverage-dump/src/main.rs

+19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ fn main() -> anyhow::Result<()> {
77

88
let args = std::env::args().collect::<Vec<_>>();
99

10+
// The coverage-dump tool already needs `rustc_demangle` in order to read
11+
// coverage metadata, so it's very easy to also have a separate mode that
12+
// turns it into a command-line demangler for use by coverage-run tests.
13+
if &args[1..] == &["--demangle"] {
14+
return demangle();
15+
}
16+
1017
let llvm_ir_path = args.get(1).context("LLVM IR file not specified")?;
1118
let llvm_ir = std::fs::read_to_string(llvm_ir_path).context("couldn't read LLVM IR file")?;
1219

@@ -15,3 +22,15 @@ fn main() -> anyhow::Result<()> {
1522

1623
Ok(())
1724
}
25+
26+
fn demangle() -> anyhow::Result<()> {
27+
use std::fmt::Write as _;
28+
29+
let stdin = std::io::read_to_string(std::io::stdin())?;
30+
let mut output = String::with_capacity(stdin.len());
31+
for line in stdin.lines() {
32+
writeln!(output, "{:#}", rustc_demangle::demangle(line))?;
33+
}
34+
print!("{output}");
35+
Ok(())
36+
}

0 commit comments

Comments
 (0)