Skip to content

Commit ed89e6b

Browse files
committed
Address review comments and Windows failure, and make cleaner
1 parent c2a8bfe commit ed89e6b

File tree

6 files changed

+108
-109
lines changed

6 files changed

+108
-109
lines changed

src/bootstrap/dist.rs

+28-24
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ pub struct RustDemangler {
12531253
}
12541254

12551255
impl Step for RustDemangler {
1256-
type Output = GeneratedTarball;
1256+
type Output = Option<GeneratedTarball>;
12571257
const ONLY_HOSTS: bool = true;
12581258

12591259
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
@@ -1271,11 +1271,17 @@ impl Step for RustDemangler {
12711271
});
12721272
}
12731273

1274-
fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
1274+
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
12751275
let compiler = self.compiler;
12761276
let target = self.target;
12771277
assert!(builder.config.extended);
12781278

1279+
// Only build this extended tool if explicitly included in `tools`, or if `profiler = true`
1280+
let profiler = builder.config.profiler_enabled(target);
1281+
if !builder.config.tools.as_ref().map_or(profiler, |t| t.contains("rust-demangler")) {
1282+
return None;
1283+
}
1284+
12791285
let rust_demangler = builder
12801286
.ensure(tool::RustDemangler { compiler, target, extra_features: Vec::new() })
12811287
.expect("rust-demangler expected to build - in-tree tool");
@@ -1286,7 +1292,7 @@ impl Step for RustDemangler {
12861292
tarball.is_preview(true);
12871293
tarball.add_file(&rust_demangler, "bin", 0o755);
12881294
tarball.add_legal_and_readme_to("share/doc/rust-demangler");
1289-
tarball.generate()
1295+
Some(tarball.generate())
12901296
}
12911297
}
12921298

@@ -1326,14 +1332,7 @@ impl Step for Extended {
13261332
let rustc_installer = builder.ensure(Rustc { compiler: builder.compiler(stage, target) });
13271333
let cargo_installer = builder.ensure(Cargo { compiler, target });
13281334
let rustfmt_installer = builder.ensure(Rustfmt { compiler, target });
1329-
let profiler = builder.config.profiler_enabled(target);
1330-
let install_rust_demangler =
1331-
builder.config.tools.as_ref().map_or(profiler, |t| t.contains("rust-demangler"));
1332-
let rust_demangler_installer = if install_rust_demangler {
1333-
Some(builder.ensure(RustDemangler { compiler, target }))
1334-
} else {
1335-
None
1336-
};
1335+
let rust_demangler_installer = builder.ensure(RustDemangler { compiler, target });
13371336
let rls_installer = builder.ensure(Rls { compiler, target });
13381337
let rust_analyzer_installer = builder.ensure(RustAnalyzer { compiler, target });
13391338
let llvm_tools_installer = builder.ensure(LlvmTools { target });
@@ -1359,14 +1358,12 @@ impl Step for Extended {
13591358
let mut tarballs = Vec::new();
13601359
tarballs.push(rustc_installer);
13611360
tarballs.push(cargo_installer);
1361+
tarballs.push(clippy_installer);
1362+
tarballs.extend(rust_demangler_installer.clone());
13621363
tarballs.extend(rls_installer.clone());
13631364
tarballs.extend(rust_analyzer_installer.clone());
1364-
tarballs.push(clippy_installer);
13651365
tarballs.extend(miri_installer.clone());
13661366
tarballs.extend(rustfmt_installer.clone());
1367-
if let Some(rust_demangler_installer) = rust_demangler_installer {
1368-
tarballs.push(rust_demangler_installer);
1369-
}
13701367
tarballs.extend(llvm_tools_installer);
13711368
if let Some(analysis_installer) = analysis_installer {
13721369
tarballs.push(analysis_installer);
@@ -1421,6 +1418,9 @@ impl Step for Extended {
14211418

14221419
let xform = |p: &Path| {
14231420
let mut contents = t!(fs::read_to_string(p));
1421+
if rust_demangler_installer.is_none() {
1422+
contents = filter(&contents, "rust-demangler");
1423+
}
14241424
if rls_installer.is_none() {
14251425
contents = filter(&contents, "rls");
14261426
}
@@ -1468,11 +1468,10 @@ impl Step for Extended {
14681468
prepare("rust-docs");
14691469
prepare("rust-std");
14701470
prepare("rust-analysis");
1471-
if install_rust_demangler {
1471+
prepare("clippy");
1472+
if rust_demangler_installer.is_some() {
14721473
prepare("rust-demangler");
14731474
}
1474-
prepare("clippy");
1475-
14761475
if rls_installer.is_some() {
14771476
prepare("rls");
14781477
}
@@ -1520,6 +1519,8 @@ impl Step for Extended {
15201519
"rust-analyzer-preview".to_string()
15211520
} else if name == "clippy" {
15221521
"clippy-preview".to_string()
1522+
} else if name == "rust-demangler" {
1523+
"rust-demangler-preview".to_string()
15231524
} else if name == "miri" {
15241525
"miri-preview".to_string()
15251526
} else {
@@ -1534,12 +1535,12 @@ impl Step for Extended {
15341535
prepare("rustc");
15351536
prepare("cargo");
15361537
prepare("rust-analysis");
1537-
if install_rust_demangler {
1538-
prepare("rust-demangler");
1539-
}
15401538
prepare("rust-docs");
15411539
prepare("rust-std");
15421540
prepare("clippy");
1541+
if rust_demangler_installer.is_some() {
1542+
prepare("rust-demangler");
1543+
}
15431544
if rls_installer.is_some() {
15441545
prepare("rls");
15451546
}
@@ -1681,7 +1682,7 @@ impl Step for Extended {
16811682
.arg("-t")
16821683
.arg(etc.join("msi/remove-duplicates.xsl")),
16831684
);
1684-
if install_rust_demangler {
1685+
if rust_demangler_installer.is_some() {
16851686
builder.run(
16861687
Command::new(&heat)
16871688
.current_dir(&exe)
@@ -1773,6 +1774,9 @@ impl Step for Extended {
17731774
.arg(&input);
17741775
add_env(builder, &mut cmd, target);
17751776

1777+
if rust_demangler_installer.is_some() {
1778+
cmd.arg("-dRustDemanglerDir=rust-demangler");
1779+
}
17761780
if rls_installer.is_some() {
17771781
cmd.arg("-dRlsDir=rls");
17781782
}
@@ -1795,7 +1799,7 @@ impl Step for Extended {
17951799
candle("CargoGroup.wxs".as_ref());
17961800
candle("StdGroup.wxs".as_ref());
17971801
candle("ClippyGroup.wxs".as_ref());
1798-
if install_rust_demangler {
1802+
if rust_demangler_installer.is_some() {
17991803
candle("RustDemanglerGroup.wxs".as_ref());
18001804
}
18011805
if rls_installer.is_some() {
@@ -1844,7 +1848,7 @@ impl Step for Extended {
18441848
if rust_analyzer_installer.is_some() {
18451849
cmd.arg("RustAnalyzerGroup.wixobj");
18461850
}
1847-
if install_rust_demangler {
1851+
if rust_demangler_installer.is_some() {
18481852
cmd.arg("RustDemanglerGroup.wixobj");
18491853
}
18501854
if miri_installer.is_some() {

src/bootstrap/install.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,14 @@ install!((self, builder, _config),
190190
);
191191
}
192192
};
193-
RustDemangler,
194-
"rust-demangler",
195-
Self::should_build(_config),
196-
only_hosts: true,
197-
{
198-
let profiler = builder.config.profiler_enabled(self.target);
199-
let install_rust_demangler =
200-
builder.config.tools.as_ref().map_or(profiler, |t| t.contains("rust-demangler"));
201-
if install_rust_demangler {
202-
let tarball = builder.ensure(
203-
dist::RustDemangler { compiler: self.compiler, target: self.target }
204-
);
193+
RustDemangler, "rust-demangler", Self::should_build(_config), only_hosts: true, {
194+
// Note: Even though `should_build` may return true for `extended` default tools,
195+
// dist::RustDemangler may still return None, unless the target-dependent `profiler` config
196+
// is also true, or the `tools` array explicitly includes "rust-demangler".
197+
if let Some(tarball) = builder.ensure(dist::RustDemangler {
198+
compiler: self.compiler,
199+
target: self.target
200+
}) {
205201
install_sh(builder, "rust-demangler", self.compiler.stage, Some(self.target), &tarball);
206202
} else {
207203
builder.info(

src/bootstrap/tarball.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl OverlayKind {
6868
match self {
6969
OverlayKind::Rust => builder.rust_version(),
7070
OverlayKind::LLVM => builder.rust_version(),
71-
OverlayKind::RustDemangler => builder.rust_version(),
71+
OverlayKind::RustDemangler => builder.release_num("rust-demangler"),
7272
OverlayKind::Cargo => {
7373
builder.cargo_info.version(builder, &builder.release_num("cargo"))
7474
}

src/bootstrap/test.rs

+3
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ impl Step for RustDemangler {
393393
t!(fs::create_dir_all(&dir));
394394

395395
cargo.env("RUST_DEMANGLER_DRIVER_PATH", rust_demangler);
396+
397+
cargo.arg("--").args(builder.config.cmd.test_args());
398+
396399
cargo.add_rustc_lib_path(builder, compiler);
397400

398401
builder.run(&mut cargo.into());

src/tools/rust-demangler/README.md

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
# rust-demangler
22

3-
Demangles rustc mangled names.
3+
_Demangles rustc mangled names._
44

5-
This tool uses the [rustc-demangle](https://crates.io/crates/rustc-demangle)
6-
crate to convert an input buffer of newline-separated mangled names into their
7-
demangled translations.
5+
`rust-demangler` supports the requirements of the [`llvm-cov show -Xdemangler`
6+
option](https://llvm.org/docs/CommandGuide/llvm-cov.html#cmdoption-llvm-cov-show-xdemangler),
7+
to perform Rust-specific symbol demangling:
88

9-
This tool takes a list of mangled names (one per line) on standard input, and
10-
prints a corresponding list of demangled names. The tool is designed to support
11-
programs that can leverage a third-party demangler, such as `llvm-cov`, via the
12-
`-Xdemangler=<path-to-demangler>` option.
9+
> _The demangler is expected to read a newline-separated list of symbols from
10+
> stdin and write a newline-separated list of the same length to stdout._
1311
14-
To use `rust-demangler` with `llvm-cov` for example, add the `-Xdemangler=...`
15-
option:
12+
To use `rust-demangler` with `llvm-cov` for example:
1613

1714
```shell
1815
$ TARGET="${PWD}/build/x86_64-unknown-linux-gnu"
@@ -21,6 +18,16 @@ $ "${TARGET}"/llvm/bin/llvm-cov show \
2118
--instr-profile=main.profdata ./main --show-line-counts-or-regions
2219
```
2320

21+
`rust-demangler` is a Rust "extended tool", used in Rust compiler tests, and
22+
optionally included in Rust distributions that enable coverage profiling. Symbol
23+
demangling is implemented using the
24+
[rustc-demangle](https://crates.io/crates/rustc-demangle) crate.
25+
26+
_(Note, for Rust developers, the third-party tool
27+
[`rustfilt`](https://crates.io/crates/rustfilt) also supports `llvm-cov` symbol
28+
demangling. `rustfilt` is a more generalized tool that searches any body of
29+
text, using pattern matching, to find and demangle Rust symbols.)_
30+
2431
## License
2532

2633
Rust-demangler is distributed under the terms of both the MIT license and the

src/tools/rust-demangler/tests/lib.rs

+51-62
Original file line numberDiff line numberDiff line change
@@ -22,74 +22,63 @@ _RNvC9backtrace3foo.llvm.A5310EB9
2222
_RNvNtNtNtNtCs92dm3009vxr_4rand4rngs7adapter9reseeding4fork23FORK_HANDLER_REGISTERED.0.0
2323
";
2424

25+
const DEMANGLED_OUTPUT: &str = r"
26+
123foo[0]::bar
27+
utf8_idents[317d481089b8c8fe]::საჭმელად_გემრიელი_სადილი
28+
cc[4d6468d6c9fd4bb3]::spawn::{closure#0}::{closure#0}
29+
<core[846817f741e54dfd]::slice::Iter<u8> as core[846817f741e54dfd]::iter::iterator::Iterator>::rposition::<core[846817f741e54dfd]::slice::memchr::memrchr::{closure#1}>::{closure#0}
30+
alloc[f15a878b47eb696b]::alloc::box_free::<dyn alloc[f15a878b47eb696b]::boxed::FnBox<(), Output = ()>>
31+
INtC8arrayvec8ArrayVechKj7b_E
32+
<const_generic[317d481089b8c8fe]::Unsigned<11: u8>>
33+
<const_generic[317d481089b8c8fe]::Signed<152: i16>>
34+
<const_generic[317d481089b8c8fe]::Signed<-11: i8>>
35+
<const_generic[317d481089b8c8fe]::Bool<false: bool>>
36+
<const_generic[317d481089b8c8fe]::Bool<true: bool>>
37+
<const_generic[317d481089b8c8fe]::Char<'v': char>>
38+
<const_generic[317d481089b8c8fe]::Char<'\n': char>>
39+
<const_generic[317d481089b8c8fe]::Char<'∂': char>>
40+
<const_generic[317d481089b8c8fe]::Foo<_>>::foo::FOO
41+
foo[0]
42+
foo[0]
43+
backtrace[0]::foo
44+
rand[693ea8e72247470f]::rngs::adapter::reseeding::fork::FORK_HANDLER_REGISTERED.0.0
45+
";
46+
47+
const DEMANGLED_OUTPUT_NO_CRATE_DISAMBIGUATORS: &str = r"
48+
123foo[0]::bar
49+
utf8_idents::საჭმელად_გემრიელი_სადილი
50+
cc::spawn::{closure#0}::{closure#0}
51+
<core::slice::Iter<u8> as core::iter::iterator::Iterator>::rposition::<core::slice::memchr::memrchr::{closure#1}>::{closure#0}
52+
alloc::alloc::box_free::<dyn alloc::boxed::FnBox<(), Output = ()>>
53+
INtC8arrayvec8ArrayVechKj7b_E
54+
<const_generic::Unsigned<11: u8>>
55+
<const_generic::Signed<152: i16>>
56+
<const_generic::Signed<-11: i8>>
57+
<const_generic::Bool<false: bool>>
58+
<const_generic::Bool<true: bool>>
59+
<const_generic::Char<'v': char>>
60+
<const_generic::Char<'\n': char>>
61+
<const_generic::Char<'∂': char>>
62+
<const_generic::Foo<_>>::foo::FOO
63+
foo[0]
64+
foo[0]
65+
backtrace[0]::foo
66+
rand::rngs::adapter::reseeding::fork::FORK_HANDLER_REGISTERED.0.0
67+
";
68+
2569
#[test]
2670
fn test_demangle_lines() {
2771
let demangled_lines = demangle_lines(MANGLED_INPUT.lines(), None);
28-
let mut iter = demangled_lines.iter();
29-
assert_eq!("", iter.next().unwrap());
30-
assert_eq!("123foo[0]::bar", iter.next().unwrap());
31-
assert_eq!("utf8_idents[317d481089b8c8fe]::საჭმელად_გემრიელი_სადილი", iter.next().unwrap());
32-
assert_eq!("cc[4d6468d6c9fd4bb3]::spawn::{closure#0}::{closure#0}", iter.next().unwrap());
33-
assert_eq!(
34-
"<core[846817f741e54dfd]::slice::Iter<u8> as core[846817f741e54dfd]::iter::iterator::Iterator>::rposition::<core[846817f741e54dfd]::slice::memchr::memrchr::{closure#1}>::{closure#0}",
35-
iter.next().unwrap()
36-
);
37-
assert_eq!(
38-
"alloc[f15a878b47eb696b]::alloc::box_free::<dyn alloc[f15a878b47eb696b]::boxed::FnBox<(), Output = ()>>",
39-
iter.next().unwrap()
40-
);
41-
assert_eq!("INtC8arrayvec8ArrayVechKj7b_E", iter.next().unwrap());
42-
assert_eq!("<const_generic[317d481089b8c8fe]::Unsigned<11: u8>>", iter.next().unwrap());
43-
assert_eq!("<const_generic[317d481089b8c8fe]::Signed<152: i16>>", iter.next().unwrap());
44-
assert_eq!("<const_generic[317d481089b8c8fe]::Signed<-11: i8>>", iter.next().unwrap());
45-
assert_eq!("<const_generic[317d481089b8c8fe]::Bool<false: bool>>", iter.next().unwrap());
46-
assert_eq!("<const_generic[317d481089b8c8fe]::Bool<true: bool>>", iter.next().unwrap());
47-
assert_eq!("<const_generic[317d481089b8c8fe]::Char<'v': char>>", iter.next().unwrap());
48-
assert_eq!("<const_generic[317d481089b8c8fe]::Char<'\\n': char>>", iter.next().unwrap());
49-
assert_eq!("<const_generic[317d481089b8c8fe]::Char<'∂': char>>", iter.next().unwrap());
50-
assert_eq!("<const_generic[317d481089b8c8fe]::Foo<_>>::foo::FOO", iter.next().unwrap());
51-
assert_eq!("foo[0]", iter.next().unwrap());
52-
assert_eq!("foo[0]", iter.next().unwrap());
53-
assert_eq!("backtrace[0]::foo", iter.next().unwrap());
54-
assert_eq!(
55-
"rand[693ea8e72247470f]::rngs::adapter::reseeding::fork::FORK_HANDLER_REGISTERED.0.0",
56-
iter.next().unwrap()
57-
);
58-
assert!(iter.next().is_none());
72+
for (expected, actual) in DEMANGLED_OUTPUT.lines().zip(demangled_lines) {
73+
assert_eq!(expected, actual);
74+
}
5975
}
6076

6177
#[test]
6278
fn test_demangle_lines_no_crate_disambiguators() {
6379
let demangled_lines = demangle_lines(MANGLED_INPUT.lines(), Some(create_disambiguator_re()));
64-
let mut iter = demangled_lines.iter();
65-
assert_eq!("", iter.next().unwrap());
66-
assert_eq!("123foo[0]::bar", iter.next().unwrap());
67-
assert_eq!("utf8_idents::საჭმელად_გემრიელი_სადილი", iter.next().unwrap());
68-
assert_eq!("cc::spawn::{closure#0}::{closure#0}", iter.next().unwrap());
69-
assert_eq!(
70-
"<core::slice::Iter<u8> as core::iter::iterator::Iterator>::rposition::<core::slice::memchr::memrchr::{closure#1}>::{closure#0}",
71-
iter.next().unwrap()
72-
);
73-
assert_eq!(
74-
"alloc::alloc::box_free::<dyn alloc::boxed::FnBox<(), Output = ()>>",
75-
iter.next().unwrap()
76-
);
77-
assert_eq!("INtC8arrayvec8ArrayVechKj7b_E", iter.next().unwrap());
78-
assert_eq!("<const_generic::Unsigned<11: u8>>", iter.next().unwrap());
79-
assert_eq!("<const_generic::Signed<152: i16>>", iter.next().unwrap());
80-
assert_eq!("<const_generic::Signed<-11: i8>>", iter.next().unwrap());
81-
assert_eq!("<const_generic::Bool<false: bool>>", iter.next().unwrap());
82-
assert_eq!("<const_generic::Bool<true: bool>>", iter.next().unwrap());
83-
assert_eq!("<const_generic::Char<'v': char>>", iter.next().unwrap());
84-
assert_eq!("<const_generic::Char<'\\n': char>>", iter.next().unwrap());
85-
assert_eq!("<const_generic::Char<'∂': char>>", iter.next().unwrap());
86-
assert_eq!("<const_generic::Foo<_>>::foo::FOO", iter.next().unwrap());
87-
assert_eq!("foo[0]", iter.next().unwrap());
88-
assert_eq!("foo[0]", iter.next().unwrap());
89-
assert_eq!("backtrace[0]::foo", iter.next().unwrap());
90-
assert_eq!(
91-
"rand::rngs::adapter::reseeding::fork::FORK_HANDLER_REGISTERED.0.0",
92-
iter.next().unwrap()
93-
);
94-
assert!(iter.next().is_none());
80+
for (expected, actual) in DEMANGLED_OUTPUT_NO_CRATE_DISAMBIGUATORS.lines().zip(demangled_lines)
81+
{
82+
assert_eq!(expected, actual);
83+
}
9584
}

0 commit comments

Comments
 (0)