From 8dac423f827611ae3090078cdb2b3f54b677d8eb Mon Sep 17 00:00:00 2001 From: Stypox Date: Wed, 11 Jun 2025 21:50:21 +0200 Subject: [PATCH 1/2] Add bootstrap option to compile a tool with features --- bootstrap.example.toml | 8 ++++++++ src/bootstrap/src/core/build_steps/tool.rs | 16 +++++++++++++++- src/bootstrap/src/core/config/config.rs | 5 ++++- src/bootstrap/src/core/config/toml/build.rs | 10 ++++++++++ src/bootstrap/src/utils/change_tracker.rs | 5 +++++ 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/bootstrap.example.toml b/bootstrap.example.toml index 1371fd6442f96..17044816c01c0 100644 --- a/bootstrap.example.toml +++ b/bootstrap.example.toml @@ -381,6 +381,14 @@ # "miri", "cargo-miri" # for dev/nightly channels #] +# Specify build configuration specific for some tool, such as enabled features. +# +# For example, to build Miri with tracing support, use `tool-config.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. +#tool-config.TOOL_NAME.features = [FEATURE1, FEATURE2] + # Verbosity level: 0 == not verbose, 1 == verbose, 2 == very verbose, 3 == print environment variables on each rustc invocation #verbose = 0 diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index 717accb399adc..102e96a414497 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -136,6 +136,20 @@ impl Step for ToolBuild { _ => panic!("unexpected Mode for tool build"), } + // build.tool-config.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 + // instead 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_config + .get(self.tool) + .and_then(|tool_config| tool_config.features.clone()) + .unwrap_or_default(); + features.extend(self.extra_features.clone()); + let mut cargo = prepare_tool_cargo( builder, self.compiler, @@ -144,7 +158,7 @@ impl Step for ToolBuild { Kind::Build, path, self.source_type, - &self.extra_features, + &features, ); // The stage0 compiler changes infrequently and does not directly depend on code diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 7f52697e6c7c6..b1af6908c4123 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -35,7 +35,7 @@ pub use crate::core::config::flags::Subcommand; use crate::core::config::flags::{Color, Flags}; use crate::core::config::target_selection::TargetSelectionList; use crate::core::config::toml::TomlConfig; -use crate::core::config::toml::build::Build; +use crate::core::config::toml::build::{Build, ToolConfig}; use crate::core::config::toml::change_id::ChangeId; use crate::core::config::toml::rust::{ LldMode, RustOptimize, check_incompatible_options_for_ci_rustc, @@ -114,6 +114,7 @@ pub struct Config { pub bootstrap_cache_path: Option, pub extended: bool, pub tools: Option>, + pub tool_config: HashMap, pub sanitizers: bool, pub profiler: bool, pub omit_git_hash: bool, @@ -689,6 +690,7 @@ impl Config { bootstrap_cache_path, extended, tools, + tool_config, verbose, sanitizers, profiler, @@ -835,6 +837,7 @@ impl Config { set(&mut config.full_bootstrap, full_bootstrap); set(&mut config.extended, extended); config.tools = tools; + set(&mut config.tool_config, tool_config); set(&mut config.verbose, verbose); set(&mut config.sanitizers, sanitizers); set(&mut config.profiler, profiler); diff --git a/src/bootstrap/src/core/config/toml/build.rs b/src/bootstrap/src/core/config/toml/build.rs index 85ded3c87d916..a530843471dee 100644 --- a/src/bootstrap/src/core/config/toml/build.rs +++ b/src/bootstrap/src/core/config/toml/build.rs @@ -6,6 +6,8 @@ //! various feature flags. These options apply across different stages and components //! unless specifically overridden by other configuration sections or command-line flags. +use std::collections::HashMap; + use serde::{Deserialize, Deserializer}; use crate::core::config::toml::ReplaceOpt; @@ -42,6 +44,7 @@ define_config! { bootstrap_cache_path: Option = "bootstrap-cache-path", extended: Option = "extended", tools: Option> = "tools", + tool_config: Option> = "tool-config", verbose: Option = "verbose", sanitizers: Option = "sanitizers", profiler: Option = "profiler", @@ -70,3 +73,10 @@ define_config! { exclude: Option> = "exclude", } } + +define_config! { + #[derive(Default, Clone)] + struct ToolConfig { + features: Option> = "features", + } +} diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs index e939a8362ada7..b6ba4b03add72 100644 --- a/src/bootstrap/src/utils/change_tracker.rs +++ b/src/bootstrap/src/utils/change_tracker.rs @@ -421,4 +421,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[ severity: ChangeSeverity::Info, summary: "Added new bootstrap flag `--skip-std-check-if-no-download-rustc` that skips std checks when download-rustc is unavailable. Mainly intended for developers to reduce RA overhead.", }, + ChangeInfo { + change_id: 142379, + severity: ChangeSeverity::Info, + summary: "Added new option `tool-config.TOOL_NAME.features` to specify the features to compile a tool with", + }, ]; From 17f69bfda0f38939bd3f2a8ae697ad8a7d5004f7 Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 12 Jun 2025 13:53:22 +0200 Subject: [PATCH 2/2] Rename tool-config to tool and add docs --- bootstrap.example.toml | 5 +++-- src/bootstrap/src/core/build_steps/tool.rs | 15 +++++++-------- src/bootstrap/src/core/config/config.rs | 10 ++++++---- src/bootstrap/src/core/config/toml/build.rs | 5 +++-- src/bootstrap/src/utils/change_tracker.rs | 2 +- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/bootstrap.example.toml b/bootstrap.example.toml index 17044816c01c0..19cf360b0fb8b 100644 --- a/bootstrap.example.toml +++ b/bootstrap.example.toml @@ -382,12 +382,13 @@ #] # Specify build configuration specific for some tool, such as enabled features. +# This option has no effect on which tools are enabled: refer to the `tools` option for that. # -# For example, to build Miri with tracing support, use `tool-config.miri.features = ["tracing"]` +# 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. -#tool-config.TOOL_NAME.features = [FEATURE1, FEATURE2] +#tool.TOOL_NAME.features = [FEATURE1, FEATURE2] # Verbosity level: 0 == not verbose, 1 == verbose, 2 == very verbose, 3 == print environment variables on each rustc invocation #verbose = 0 diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index 102e96a414497..0c2446acc4eac 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -136,17 +136,16 @@ impl Step for ToolBuild { _ => panic!("unexpected Mode for tool build"), } - // build.tool-config.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 - // instead 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). + // 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_config + .tool .get(self.tool) - .and_then(|tool_config| tool_config.features.clone()) + .and_then(|tool| tool.features.clone()) .unwrap_or_default(); features.extend(self.extra_features.clone()); diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index b1af6908c4123..de6ba74e19582 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -35,7 +35,7 @@ pub use crate::core::config::flags::Subcommand; use crate::core::config::flags::{Color, Flags}; use crate::core::config::target_selection::TargetSelectionList; use crate::core::config::toml::TomlConfig; -use crate::core::config::toml::build::{Build, ToolConfig}; +use crate::core::config::toml::build::{Build, Tool}; use crate::core::config::toml::change_id::ChangeId; use crate::core::config::toml::rust::{ LldMode, RustOptimize, check_incompatible_options_for_ci_rustc, @@ -114,7 +114,9 @@ pub struct Config { pub bootstrap_cache_path: Option, pub extended: bool, pub tools: Option>, - pub tool_config: HashMap, + /// Specify build configuration specific for some tool, such as enabled features, see [Tool]. + /// The key in the map is the name of the tool, and the value is tool-specific configuration. + pub tool: HashMap, pub sanitizers: bool, pub profiler: bool, pub omit_git_hash: bool, @@ -690,7 +692,7 @@ impl Config { bootstrap_cache_path, extended, tools, - tool_config, + tool, verbose, sanitizers, profiler, @@ -837,7 +839,7 @@ impl Config { set(&mut config.full_bootstrap, full_bootstrap); set(&mut config.extended, extended); config.tools = tools; - set(&mut config.tool_config, tool_config); + set(&mut config.tool, tool); set(&mut config.verbose, verbose); set(&mut config.sanitizers, sanitizers); set(&mut config.profiler, profiler); diff --git a/src/bootstrap/src/core/config/toml/build.rs b/src/bootstrap/src/core/config/toml/build.rs index a530843471dee..98e1194de728b 100644 --- a/src/bootstrap/src/core/config/toml/build.rs +++ b/src/bootstrap/src/core/config/toml/build.rs @@ -44,7 +44,7 @@ define_config! { bootstrap_cache_path: Option = "bootstrap-cache-path", extended: Option = "extended", tools: Option> = "tools", - tool_config: Option> = "tool-config", + tool: Option> = "tool", verbose: Option = "verbose", sanitizers: Option = "sanitizers", profiler: Option = "profiler", @@ -75,8 +75,9 @@ define_config! { } define_config! { + /// Configuration specific for some tool, e.g. which features to enable during build. #[derive(Default, Clone)] - struct ToolConfig { + struct Tool { features: Option> = "features", } } diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs index b6ba4b03add72..93e01a58077e0 100644 --- a/src/bootstrap/src/utils/change_tracker.rs +++ b/src/bootstrap/src/utils/change_tracker.rs @@ -424,6 +424,6 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[ ChangeInfo { change_id: 142379, severity: ChangeSeverity::Info, - summary: "Added new option `tool-config.TOOL_NAME.features` to specify the features to compile a tool with", + summary: "Added new option `tool.TOOL_NAME.features` to specify the features to compile a tool with", }, ];