Skip to content

Commit 82faa9c

Browse files
committed
refactor gating of demangler
1 parent e60b348 commit 82faa9c

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

src/bootstrap/dist.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,13 @@ impl Step for RustDemangler {
12841284
const ONLY_HOSTS: bool = true;
12851285

12861286
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1287-
run.path("rust-demangler")
1287+
// While other tools use `should_build_extended_tool` to decide whether to be run by
1288+
// default or not, `rust-demangler` must be build when *either* it's enabled as a tool like
1289+
// the other ones or if `profiler = true`. Because we don't know the target at this stage
1290+
// we run the step by default when only `extended = true`, and decide whether to actually
1291+
// run it or not later.
1292+
let default = run.builder.config.extended;
1293+
run.path("rust-demangler").default_condition(default)
12881294
}
12891295

12901296
fn make_run(run: RunConfig<'_>) {
@@ -1301,11 +1307,11 @@ impl Step for RustDemangler {
13011307
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
13021308
let compiler = self.compiler;
13031309
let target = self.target;
1304-
assert!(builder.config.extended);
13051310

13061311
// Only build this extended tool if explicitly included in `tools`, or if `profiler = true`
1307-
let profiler = builder.config.profiler_enabled(target);
1308-
if !builder.config.tools.as_ref().map_or(profiler, |t| t.contains("rust-demangler")) {
1312+
let condition = should_build_extended_tool(builder, "rust-demangler")
1313+
|| builder.config.profiler_enabled(target);
1314+
if builder.config.extended && !condition {
13091315
return None;
13101316
}
13111317

@@ -1380,6 +1386,15 @@ impl Step for Extended {
13801386
tarballs.push(builder.ensure(Docs { host: target }));
13811387
}
13821388

1389+
if builder.config.profiler_enabled(target)
1390+
|| should_build_extended_tool(builder, "rust-demangler")
1391+
{
1392+
if let Some(tarball) = builder.ensure(RustDemangler { compiler, target }) {
1393+
tarballs.push(tarball);
1394+
built_tools.insert("rust-demangler");
1395+
}
1396+
}
1397+
13831398
add_tool!("cargo" => Cargo { compiler, target });
13841399
add_tool!("rustfmt" => Rustfmt { compiler, target });
13851400
add_tool!("rls" => Rls { compiler, target });
@@ -1389,7 +1404,6 @@ impl Step for Extended {
13891404
add_tool!("miri" => Miri { compiler, target });
13901405
add_tool!("analysis" => Analysis { compiler, target });
13911406

1392-
let rust_demangler_installer = builder.ensure(RustDemangler { compiler, target });
13931407
let mingw_installer = builder.ensure(Mingw { host: target });
13941408

13951409
let etc = builder.src.join("src/etc/installer");
@@ -1399,8 +1413,6 @@ impl Step for Extended {
13991413
return;
14001414
}
14011415

1402-
tarballs.extend(rust_demangler_installer.clone());
1403-
14041416
if target.contains("pc-windows-gnu") {
14051417
tarballs.push(mingw_installer.unwrap());
14061418
}
@@ -1447,11 +1459,7 @@ impl Step for Extended {
14471459

14481460
let xform = |p: &Path| {
14491461
let mut contents = t!(fs::read_to_string(p));
1450-
if rust_demangler_installer.is_none() {
1451-
contents = filter(&contents, "rust-demangler");
1452-
}
1453-
1454-
for tool in &["rls", "rust-analyzer", "miri", "rustfmt"] {
1462+
for tool in &["rust-demangler", "rls", "rust-analyzer", "miri", "rustfmt"] {
14551463
if !built_tools.contains(tool) {
14561464
contents = filter(&contents, tool);
14571465
}
@@ -1492,10 +1500,7 @@ impl Step for Extended {
14921500
prepare("rust-std");
14931501
prepare("rust-analysis");
14941502
prepare("clippy");
1495-
if rust_demangler_installer.is_some() {
1496-
prepare("rust-demangler");
1497-
}
1498-
for tool in &["rls", "rust-analyzer", "miri"] {
1503+
for tool in &["rust-demangler", "rls", "rust-analyzer", "miri"] {
14991504
if built_tools.contains(tool) {
15001505
prepare(tool);
15011506
}
@@ -1556,10 +1561,7 @@ impl Step for Extended {
15561561
prepare("rust-docs");
15571562
prepare("rust-std");
15581563
prepare("clippy");
1559-
if rust_demangler_installer.is_some() {
1560-
prepare("rust-demangler");
1561-
}
1562-
for tool in &["rls", "rust-analyzer", "miri"] {
1564+
for tool in &["rust-demangler", "rls", "rust-analyzer", "miri"] {
15631565
if built_tools.contains(tool) {
15641566
prepare(tool);
15651567
}
@@ -1696,7 +1698,7 @@ impl Step for Extended {
16961698
.arg("-t")
16971699
.arg(etc.join("msi/remove-duplicates.xsl")),
16981700
);
1699-
if rust_demangler_installer.is_some() {
1701+
if built_tools.contains("rust-demangler") {
17001702
builder.run(
17011703
Command::new(&heat)
17021704
.current_dir(&exe)
@@ -1788,7 +1790,7 @@ impl Step for Extended {
17881790
.arg(&input);
17891791
add_env(builder, &mut cmd, target);
17901792

1791-
if rust_demangler_installer.is_some() {
1793+
if built_tools.contains("rust-demangler") {
17921794
cmd.arg("-dRustDemanglerDir=rust-demangler");
17931795
}
17941796
if built_tools.contains("rls") {
@@ -1813,7 +1815,7 @@ impl Step for Extended {
18131815
candle("CargoGroup.wxs".as_ref());
18141816
candle("StdGroup.wxs".as_ref());
18151817
candle("ClippyGroup.wxs".as_ref());
1816-
if rust_demangler_installer.is_some() {
1818+
if built_tools.contains("rust-demangler") {
18171819
candle("RustDemanglerGroup.wxs".as_ref());
18181820
}
18191821
if built_tools.contains("rls") {
@@ -1862,7 +1864,7 @@ impl Step for Extended {
18621864
if built_tools.contains("rust-analyzer") {
18631865
cmd.arg("RustAnalyzerGroup.wixobj");
18641866
}
1865-
if rust_demangler_installer.is_some() {
1867+
if built_tools.contains("rust-demangler") {
18661868
cmd.arg("RustDemanglerGroup.wixobj");
18671869
}
18681870
if built_tools.contains("miri") {

0 commit comments

Comments
 (0)