Skip to content

Add bootstrap option to compile a tool with features #142379

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 2 commits into from
Jun 13, 2025
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: 9 additions & 0 deletions bootstrap.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,15 @@
# "miri", "cargo-miri" # for dev/nightly channels
#]

# 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.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.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

Expand Down
15 changes: 14 additions & 1 deletion src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ 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,
Expand All @@ -144,7 +157,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
Expand Down
7 changes: 6 additions & 1 deletion src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, Tool};
use crate::core::config::toml::change_id::ChangeId;
use crate::core::config::toml::rust::{
LldMode, RustOptimize, check_incompatible_options_for_ci_rustc,
Expand Down Expand Up @@ -114,6 +114,9 @@ pub struct Config {
pub bootstrap_cache_path: Option<PathBuf>,
pub extended: bool,
pub tools: Option<HashSet<String>>,
/// 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<String, Tool>,
pub sanitizers: bool,
pub profiler: bool,
pub omit_git_hash: bool,
Expand Down Expand Up @@ -689,6 +692,7 @@ impl Config {
bootstrap_cache_path,
extended,
tools,
tool,
verbose,
sanitizers,
profiler,
Expand Down Expand Up @@ -835,6 +839,7 @@ impl Config {
set(&mut config.full_bootstrap, full_bootstrap);
set(&mut config.extended, extended);
config.tools = tools;
set(&mut config.tool, tool);
set(&mut config.verbose, verbose);
set(&mut config.sanitizers, sanitizers);
set(&mut config.profiler, profiler);
Expand Down
11 changes: 11 additions & 0 deletions src/bootstrap/src/core/config/toml/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,6 +44,7 @@ define_config! {
bootstrap_cache_path: Option<PathBuf> = "bootstrap-cache-path",
extended: Option<bool> = "extended",
tools: Option<HashSet<String>> = "tools",
tool: Option<HashMap<String, Tool>> = "tool",
verbose: Option<usize> = "verbose",
sanitizers: Option<bool> = "sanitizers",
profiler: Option<bool> = "profiler",
Expand Down Expand Up @@ -70,3 +73,11 @@ define_config! {
exclude: Option<Vec<PathBuf>> = "exclude",
}
}

define_config! {
/// Configuration specific for some tool, e.g. which features to enable during build.
#[derive(Default, Clone)]
struct Tool {
features: Option<Vec<String>> = "features",
}
}
5 changes: 5 additions & 0 deletions src/bootstrap/src/utils/change_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.TOOL_NAME.features` to specify the features to compile a tool with",
},
];
Loading