Skip to content

Commit 63bba3a

Browse files
authored
Unrolled build for #143733
Rollup merge of #143733 - Stypox:bootstrap-tool-config-any, r=Kobzol Change bootstrap's `tool.TOOL_NAME.features` to work on any subcommand This is a followup to #142379 to make the bootstrap option `tool.TOOL_NAME.features` work on any subcommand instead of just build (so also run/test/...). I also made the `TOOL_NAME` comparisons look at the tool path instead of the tool name to determine to which tool a `TOOL_NAME` refers to, so you can specify tools by path like in other places of the bootstrap (e.g. `tool."tools/miri".features`).
2 parents 64b185e + 940aa20 commit 63bba3a

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

bootstrap.example.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@
392392
# For example, to build Miri with tracing support, use `tool.miri.features = ["tracing"]`
393393
#
394394
# The default value for the `features` array is `[]`. However, please note that other flags in
395-
# `bootstrap.toml` might influence the features enabled for some tools.
395+
# `bootstrap.toml` might influence the features enabled for some tools. Also, enabling features
396+
# in tools which are not part of the internal "extra-features" preset might not always work.
396397
#build.tool.TOOL_NAME.features = [FEATURE1, FEATURE2]
397398

398399
# Verbosity level: 0 == not verbose, 1 == verbose, 2 == very verbose, 3 == print environment variables on each rustc invocation

src/bootstrap/src/core/build_steps/tool.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//! Each Rust tool **MUST** utilize `ToolBuild` inside their `Step` logic,
1010
//! return `ToolBuildResult` and should never prepare `cargo` invocations manually.
1111
12+
use std::ffi::OsStr;
1213
use std::path::PathBuf;
1314
use std::{env, fs};
1415

@@ -136,19 +137,6 @@ impl Step for ToolBuild {
136137
_ => panic!("unexpected Mode for tool build"),
137138
}
138139

139-
// build.tool.TOOL_NAME.features in bootstrap.toml allows specifying which features to
140-
// enable for a specific tool. `extra_features` instead is not controlled by the toml and
141-
// provides features that are always enabled for a specific tool (e.g. "in-rust-tree" for
142-
// rust-analyzer). Finally, `prepare_tool_cargo` might add more features to adapt the build
143-
// to the chosen flags (e.g. "all-static" for cargo if `cargo_native_static` is true).
144-
let mut features = builder
145-
.config
146-
.tool
147-
.get(self.tool)
148-
.and_then(|tool| tool.features.clone())
149-
.unwrap_or_default();
150-
features.extend(self.extra_features.clone());
151-
152140
let mut cargo = prepare_tool_cargo(
153141
builder,
154142
self.compiler,
@@ -157,7 +145,7 @@ impl Step for ToolBuild {
157145
Kind::Build,
158146
path,
159147
self.source_type,
160-
&features,
148+
&self.extra_features,
161149
);
162150

163151
// The stage0 compiler changes infrequently and does not directly depend on code
@@ -244,7 +232,8 @@ pub fn prepare_tool_cargo(
244232
) -> CargoCommand {
245233
let mut cargo = builder::Cargo::new(builder, compiler, mode, source_type, target, cmd_kind);
246234

247-
let dir = builder.src.join(path);
235+
let path = PathBuf::from(path);
236+
let dir = builder.src.join(&path);
248237
cargo.arg("--manifest-path").arg(dir.join("Cargo.toml"));
249238

250239
let mut features = extra_features.to_vec();
@@ -261,6 +250,18 @@ pub fn prepare_tool_cargo(
261250
}
262251
}
263252

253+
// build.tool.TOOL_NAME.features in bootstrap.toml allows specifying which features to enable
254+
// for a specific tool. `extra_features` instead is not controlled by the toml and provides
255+
// features that are always enabled for a specific tool (e.g. "in-rust-tree" for rust-analyzer).
256+
// Finally, `prepare_tool_cargo` above here might add more features to adapt the build
257+
// to the chosen flags (e.g. "all-static" for cargo if `cargo_native_static` is true).
258+
builder
259+
.config
260+
.tool
261+
.iter()
262+
.filter(|(tool_name, _)| path.file_name().and_then(OsStr::to_str) == Some(tool_name))
263+
.for_each(|(_, tool)| features.extend(tool.features.clone().unwrap_or_default()));
264+
264265
// clippy tests need to know about the stage sysroot. Set them consistently while building to
265266
// avoid rebuilding when running tests.
266267
cargo.env("SYSROOT", builder.sysroot(compiler));

src/bootstrap/src/utils/change_tracker.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,4 +471,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
471471
severity: ChangeSeverity::Info,
472472
summary: "A --compile-time-deps flag has been added to reduce the time it takes rust-analyzer to start",
473473
},
474+
ChangeInfo {
475+
change_id: 143733,
476+
severity: ChangeSeverity::Info,
477+
summary: "Option `tool.TOOL_NAME.features` now works on any subcommand, not just `build`.",
478+
},
474479
];

0 commit comments

Comments
 (0)