Skip to content

Make rust-demangler installable #83529

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

Merged
merged 3 commits into from
Apr 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,11 @@ changelog-seen = 2
# be built if `extended = true`.
#extended = false

# Installs chosen set of extended tools if `extended = true`. By default builds all.
# If chosen tool failed to build the installation fails. If `extended = false`, this
# option is ignored.
#tools = ["cargo", "rls", "clippy", "rustfmt", "analysis", "src"]
# Installs chosen set of extended tools if `extended = true`. By default builds
# all extended tools except `rust-demangler`, unless the target is also being
# built with `profiler = true`. If chosen tool failed to build the installation
# fails. If `extended = false`, this option is ignored.
#tools = ["cargo", "rls", "clippy", "rustfmt", "analysis", "src"] # + "rust-demangler" if `profiler`

# Verbosity level: 0 == not verbose, 1 == verbose, 2 == very verbose
#verbose = 0
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ impl<'a> Builder<'a> {
test::Rustfmt,
test::Miri,
test::Clippy,
test::RustDemangler,
test::CompiletestTest,
test::RustdocJSStd,
test::RustdocJSNotStd,
Expand Down Expand Up @@ -466,6 +467,7 @@ impl<'a> Builder<'a> {
dist::Rls,
dist::RustAnalyzer,
dist::Rustfmt,
dist::RustDemangler,
dist::Clippy,
dist::Miri,
dist::LlvmTools,
Expand All @@ -481,6 +483,7 @@ impl<'a> Builder<'a> {
install::Rls,
install::RustAnalyzer,
install::Rustfmt,
install::RustDemangler,
install::Clippy,
install::Miri,
install::Analysis,
Expand Down
94 changes: 92 additions & 2 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,56 @@ impl Step for Rustfmt {
}
}

#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
pub struct RustDemangler {
pub compiler: Compiler,
pub target: TargetSelection,
}

impl Step for RustDemangler {
type Output = Option<GeneratedTarball>;
const ONLY_HOSTS: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.path("rust-demangler")
}

fn make_run(run: RunConfig<'_>) {
run.builder.ensure(RustDemangler {
compiler: run.builder.compiler_for(
run.builder.top_stage,
run.builder.config.build,
run.target,
),
target: run.target,
});
}

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

// Only build this extended tool if explicitly included in `tools`, or if `profiler = true`
let profiler = builder.config.profiler_enabled(target);
if !builder.config.tools.as_ref().map_or(profiler, |t| t.contains("rust-demangler")) {
return None;
}

let rust_demangler = builder
.ensure(tool::RustDemangler { compiler, target, extra_features: Vec::new() })
.expect("rust-demangler expected to build - in-tree tool");

// Prepare the image directory
let mut tarball = Tarball::new(builder, "rust-demangler", &target.triple);
tarball.set_overlay(OverlayKind::RustDemangler);
tarball.is_preview(true);
tarball.add_file(&rust_demangler, "bin", 0o755);
tarball.add_legal_and_readme_to("share/doc/rust-demangler");
Some(tarball.generate())
}
}

#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Extended {
stage: u32,
Expand Down Expand Up @@ -1282,6 +1332,7 @@ impl Step for Extended {
let rustc_installer = builder.ensure(Rustc { compiler: builder.compiler(stage, target) });
let cargo_installer = builder.ensure(Cargo { compiler, target });
let rustfmt_installer = builder.ensure(Rustfmt { compiler, target });
let rust_demangler_installer = builder.ensure(RustDemangler { compiler, target });
let rls_installer = builder.ensure(Rls { compiler, target });
let rust_analyzer_installer = builder.ensure(RustAnalyzer { compiler, target });
let llvm_tools_installer = builder.ensure(LlvmTools { target });
Expand All @@ -1307,9 +1358,10 @@ impl Step for Extended {
let mut tarballs = Vec::new();
tarballs.push(rustc_installer);
tarballs.push(cargo_installer);
tarballs.push(clippy_installer);
tarballs.extend(rust_demangler_installer.clone());
tarballs.extend(rls_installer.clone());
tarballs.extend(rust_analyzer_installer.clone());
tarballs.push(clippy_installer);
tarballs.extend(miri_installer.clone());
tarballs.extend(rustfmt_installer.clone());
tarballs.extend(llvm_tools_installer);
Expand Down Expand Up @@ -1366,6 +1418,9 @@ impl Step for Extended {

let xform = |p: &Path| {
let mut contents = t!(fs::read_to_string(p));
if rust_demangler_installer.is_none() {
contents = filter(&contents, "rust-demangler");
}
if rls_installer.is_none() {
contents = filter(&contents, "rls");
}
Expand Down Expand Up @@ -1414,7 +1469,9 @@ impl Step for Extended {
prepare("rust-std");
prepare("rust-analysis");
prepare("clippy");

if rust_demangler_installer.is_some() {
prepare("rust-demangler");
}
if rls_installer.is_some() {
prepare("rls");
}
Expand Down Expand Up @@ -1462,6 +1519,8 @@ impl Step for Extended {
"rust-analyzer-preview".to_string()
} else if name == "clippy" {
"clippy-preview".to_string()
} else if name == "rust-demangler" {
"rust-demangler-preview".to_string()
} else if name == "miri" {
"miri-preview".to_string()
} else {
Expand All @@ -1479,6 +1538,9 @@ impl Step for Extended {
prepare("rust-docs");
prepare("rust-std");
prepare("clippy");
if rust_demangler_installer.is_some() {
prepare("rust-demangler");
}
if rls_installer.is_some() {
prepare("rls");
}
Expand Down Expand Up @@ -1620,6 +1682,25 @@ impl Step for Extended {
.arg("-t")
.arg(etc.join("msi/remove-duplicates.xsl")),
);
if rust_demangler_installer.is_some() {
builder.run(
Command::new(&heat)
.current_dir(&exe)
.arg("dir")
.arg("rust-demangler")
.args(&heat_flags)
.arg("-cg")
.arg("RustDemanglerGroup")
.arg("-dr")
.arg("RustDemangler")
.arg("-var")
.arg("var.RustDemanglerDir")
.arg("-out")
.arg(exe.join("RustDemanglerGroup.wxs"))
.arg("-t")
.arg(etc.join("msi/remove-duplicates.xsl")),
);
}
if miri_installer.is_some() {
builder.run(
Command::new(&heat)
Expand Down Expand Up @@ -1693,6 +1774,9 @@ impl Step for Extended {
.arg(&input);
add_env(builder, &mut cmd, target);

if rust_demangler_installer.is_some() {
cmd.arg("-dRustDemanglerDir=rust-demangler");
}
if rls_installer.is_some() {
cmd.arg("-dRlsDir=rls");
}
Expand All @@ -1715,6 +1799,9 @@ impl Step for Extended {
candle("CargoGroup.wxs".as_ref());
candle("StdGroup.wxs".as_ref());
candle("ClippyGroup.wxs".as_ref());
if rust_demangler_installer.is_some() {
candle("RustDemanglerGroup.wxs".as_ref());
}
if rls_installer.is_some() {
candle("RlsGroup.wxs".as_ref());
}
Expand Down Expand Up @@ -1761,6 +1848,9 @@ impl Step for Extended {
if rust_analyzer_installer.is_some() {
cmd.arg("RustAnalyzerGroup.wixobj");
}
if rust_demangler_installer.is_some() {
cmd.arg("RustDemanglerGroup.wixobj");
}
if miri_installer.is_some() {
cmd.arg("MiriGroup.wixobj");
}
Expand Down
16 changes: 16 additions & 0 deletions src/bootstrap/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,22 @@ install!((self, builder, _config),
);
}
};
RustDemangler, "rust-demangler", Self::should_build(_config), only_hosts: true, {
// Note: Even though `should_build` may return true for `extended` default tools,
// dist::RustDemangler may still return None, unless the target-dependent `profiler` config
// is also true, or the `tools` array explicitly includes "rust-demangler".
if let Some(tarball) = builder.ensure(dist::RustDemangler {
compiler: self.compiler,
target: self.target
}) {
install_sh(builder, "rust-demangler", self.compiler.stage, Some(self.target), &tarball);
} else {
builder.info(
&format!("skipping Install RustDemangler stage{} ({})",
self.compiler.stage, self.target),
);
}
};
Analysis, "analysis", Self::should_build(_config), only_hosts: false, {
let tarball = builder.ensure(dist::Analysis {
// Find the actual compiler (handling the full bootstrap option) which
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/tarball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub(crate) enum OverlayKind {
Clippy,
Miri,
Rustfmt,
RustDemangler,
RLS,
RustAnalyzer,
}
Expand Down Expand Up @@ -47,6 +48,9 @@ impl OverlayKind {
"src/tools/rustfmt/LICENSE-APACHE",
"src/tools/rustfmt/LICENSE-MIT",
],
OverlayKind::RustDemangler => {
&["src/tools/rust-demangler/README.md", "LICENSE-APACHE", "LICENSE-MIT"]
}
OverlayKind::RLS => &[
"src/tools/rls/README.md",
"src/tools/rls/LICENSE-APACHE",
Expand All @@ -64,6 +68,7 @@ impl OverlayKind {
match self {
OverlayKind::Rust => builder.rust_version(),
OverlayKind::LLVM => builder.rust_version(),
OverlayKind::RustDemangler => builder.release_num("rust-demangler"),
OverlayKind::Cargo => {
builder.cargo_info.version(builder, &builder.release_num("cargo"))
}
Expand Down
56 changes: 55 additions & 1 deletion src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,57 @@ impl Step for Rustfmt {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct RustDemangler {
stage: u32,
host: TargetSelection,
}

impl Step for RustDemangler {
type Output = ();
const ONLY_HOSTS: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.path("src/tools/rust-demangler")
}

fn make_run(run: RunConfig<'_>) {
run.builder.ensure(RustDemangler { stage: run.builder.top_stage, host: run.target });
}

/// Runs `cargo test` for rust-demangler.
fn run(self, builder: &Builder<'_>) {
let stage = self.stage;
let host = self.host;
let compiler = builder.compiler(stage, host);

let rust_demangler = builder
.ensure(tool::RustDemangler { compiler, target: self.host, extra_features: Vec::new() })
.expect("in-tree tool");
let mut cargo = tool::prepare_tool_cargo(
builder,
compiler,
Mode::ToolRustc,
host,
"test",
"src/tools/rust-demangler",
SourceType::InTree,
&[],
);

let dir = testdir(builder, compiler.host);
t!(fs::create_dir_all(&dir));

cargo.env("RUST_DEMANGLER_DRIVER_PATH", rust_demangler);

cargo.arg("--").args(builder.config.cmd.test_args());

cargo.add_rustc_lib_path(builder, compiler);

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

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Miri {
stage: u32,
Expand Down Expand Up @@ -1126,7 +1177,10 @@ note: if you're sure you want to do this, please open an issue as to why. In the
}

if mode == "run-make" && suite.ends_with("fulldeps") {
cmd.arg("--rust-demangler-path").arg(builder.tool_exe(Tool::RustDemangler));
let rust_demangler = builder
.ensure(tool::RustDemangler { compiler, target, extra_features: Vec::new() })
.expect("in-tree tool");
cmd.arg("--rust-demangler-path").arg(rust_demangler);
}

cmd.arg("--src-base").arg(builder.src.join("src/test").join(suite));
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ bootstrap_tool!(
Compiletest, "src/tools/compiletest", "compiletest", is_unstable_tool = true;
BuildManifest, "src/tools/build-manifest", "build-manifest";
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client";
RustDemangler, "src/tools/rust-demangler", "rust-demangler";
RustInstaller, "src/tools/rust-installer", "fabricate", is_external_tool = true;
RustdocTheme, "src/tools/rustdoc-themes", "rustdoc-themes";
ExpandYamlAnchors, "src/tools/expand-yaml-anchors", "expand-yaml-anchors";
Expand Down Expand Up @@ -719,6 +718,7 @@ tool_extended!((self, builder),
});
self.extra_features.push("clippy".to_owned());
};
RustDemangler, rust_demangler, "src/tools/rust-demangler", "rust-demangler", stable=false, in_tree=true, {};
Rustfmt, rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, {};
RustAnalyzer, rust_analyzer, "src/tools/rust-analyzer/crates/rust-analyzer", "rust-analyzer", stable=false, {};
);
Expand Down
6 changes: 5 additions & 1 deletion src/tools/rust-demangler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ edition = "2018"
regex = "1.0"
rustc-demangle = "0.1.17"

[lib]
name = "rust_demangler"
doctest = false

[[bin]]
name = "rust-demangler"
path = "main.rs"
test = false
36 changes: 36 additions & 0 deletions src/tools/rust-demangler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# rust-demangler

_Demangles rustc mangled names._

`rust-demangler` supports the requirements of the [`llvm-cov show -Xdemangler`
option](https://llvm.org/docs/CommandGuide/llvm-cov.html#cmdoption-llvm-cov-show-xdemangler),
to perform Rust-specific symbol demangling:

> _The demangler is expected to read a newline-separated list of symbols from
> stdin and write a newline-separated list of the same length to stdout._

To use `rust-demangler` with `llvm-cov` for example:

```shell
$ TARGET="${PWD}/build/x86_64-unknown-linux-gnu"
$ "${TARGET}"/llvm/bin/llvm-cov show \
--Xdemangler=path/to/rust-demangler \
--instr-profile=main.profdata ./main --show-line-counts-or-regions
```

`rust-demangler` is a Rust "extended tool", used in Rust compiler tests, and
optionally included in Rust distributions that enable coverage profiling. Symbol
demangling is implemented using the
[rustc-demangle](https://crates.io/crates/rustc-demangle) crate.

_(Note, for Rust developers, the third-party tool
[`rustfilt`](https://crates.io/crates/rustfilt) also supports `llvm-cov` symbol
demangling. `rustfilt` is a more generalized tool that searches any body of
text, using pattern matching, to find and demangle Rust symbols.)_

## License

Rust-demangler is distributed under the terms of both the MIT license and the
Apache License (Version 2.0).

See [LICENSE-APACHE](/LICENSE-APACHE) and [LICENSE-MIT](/LICENSE-MIT) for details.
Loading