From 937ef9381c45e9cad5fc31bdc85224b7f6e13df1 Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 10 Jul 2025 14:33:32 +0200 Subject: [PATCH 1/3] Bootstrap's `tool.TOOL_NAME.features` now works on any subcommand --- src/bootstrap/src/core/build_steps/tool.rs | 30 +++++++++++----------- src/bootstrap/src/utils/change_tracker.rs | 5 ++++ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index 5de1b472d7940..e3a0ab212a3f7 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -136,19 +136,6 @@ impl Step for ToolBuild { _ => panic!("unexpected Mode for tool build"), } - // build.tool.TOOL_NAME.features in bootstrap.toml allows specifying which features to - // enable for a specific tool. `extra_features` instead is not controlled by the toml and - // provides features that are always enabled for a specific tool (e.g. "in-rust-tree" for - // rust-analyzer). Finally, `prepare_tool_cargo` might add more features to adapt the build - // to the chosen flags (e.g. "all-static" for cargo if `cargo_native_static` is true). - let mut features = builder - .config - .tool - .get(self.tool) - .and_then(|tool| tool.features.clone()) - .unwrap_or_default(); - features.extend(self.extra_features.clone()); - let mut cargo = prepare_tool_cargo( builder, self.compiler, @@ -157,7 +144,7 @@ impl Step for ToolBuild { Kind::Build, path, self.source_type, - &features, + &self.extra_features, ); // The stage0 compiler changes infrequently and does not directly depend on code @@ -244,7 +231,8 @@ pub fn prepare_tool_cargo( ) -> CargoCommand { let mut cargo = builder::Cargo::new(builder, compiler, mode, source_type, target, cmd_kind); - let dir = builder.src.join(path); + let path = PathBuf::from(path); + let dir = builder.src.join(&path); cargo.arg("--manifest-path").arg(dir.join("Cargo.toml")); let mut features = extra_features.to_vec(); @@ -261,6 +249,18 @@ pub fn prepare_tool_cargo( } } + // build.tool.TOOL_NAME.features in bootstrap.toml allows specifying which features to enable + // for a specific tool. `extra_features` instead is not controlled by the toml and provides + // features that are always enabled for a specific tool (e.g. "in-rust-tree" for rust-analyzer). + // Finally, `prepare_tool_cargo` above here might add more features to adapt the build + // to the chosen flags (e.g. "all-static" for cargo if `cargo_native_static` is true). + builder + .config + .tool + .iter() + .filter(|(tool_name, _)| path.ends_with(tool_name)) + .for_each(|(_, tool)| features.extend(tool.features.clone().unwrap_or_default())); + // clippy tests need to know about the stage sysroot. Set them consistently while building to // avoid rebuilding when running tests. cargo.env("SYSROOT", builder.sysroot(compiler)); diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs index c5d460ac55bf8..1f6ed8129da8b 100644 --- a/src/bootstrap/src/utils/change_tracker.rs +++ b/src/bootstrap/src/utils/change_tracker.rs @@ -471,4 +471,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[ severity: ChangeSeverity::Info, summary: "A --compile-time-deps flag has been added to reduce the time it takes rust-analyzer to start", }, + ChangeInfo { + change_id: 143733, + severity: ChangeSeverity::Info, + summary: "Option `tool.TOOL_NAME.features` now works on any subcommand, not just `build`.", + }, ]; From b3ed03529fe7c846c6a7e6ef7382439a0ce4247e Mon Sep 17 00:00:00 2001 From: Stypox Date: Sun, 13 Jul 2025 08:46:49 +0200 Subject: [PATCH 2/3] Only compare tool name to apply features to --- src/bootstrap/src/core/build_steps/tool.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index e3a0ab212a3f7..8271be1675f6f 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -9,6 +9,7 @@ //! Each Rust tool **MUST** utilize `ToolBuild` inside their `Step` logic, //! return `ToolBuildResult` and should never prepare `cargo` invocations manually. +use std::ffi::OsStr; use std::path::PathBuf; use std::{env, fs}; @@ -258,7 +259,7 @@ pub fn prepare_tool_cargo( .config .tool .iter() - .filter(|(tool_name, _)| path.ends_with(tool_name)) + .filter(|(tool_name, _)| path.file_name().and_then(OsStr::to_str) == Some(tool_name)) .for_each(|(_, tool)| features.extend(tool.features.clone().unwrap_or_default())); // clippy tests need to know about the stage sysroot. Set them consistently while building to From 940aa204086ad4efa3b5151b1363610c9ccf28d9 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sun, 13 Jul 2025 08:47:38 +0200 Subject: [PATCH 3/3] Add comment about features not part of "extra-features" --- bootstrap.example.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bootstrap.example.toml b/bootstrap.example.toml index b59f112bdfb83..73e93ccbe4202 100644 --- a/bootstrap.example.toml +++ b/bootstrap.example.toml @@ -392,7 +392,8 @@ # For example, to build Miri with tracing support, use `tool.miri.features = ["tracing"]` # # The default value for the `features` array is `[]`. However, please note that other flags in -# `bootstrap.toml` might influence the features enabled for some tools. +# `bootstrap.toml` might influence the features enabled for some tools. Also, enabling features +# in tools which are not part of the internal "extra-features" preset might not always work. #build.tool.TOOL_NAME.features = [FEATURE1, FEATURE2] # Verbosity level: 0 == not verbose, 1 == verbose, 2 == very verbose, 3 == print environment variables on each rustc invocation