Skip to content

Commit 8dac423

Browse files
committed
Add bootstrap option to compile a tool with features
1 parent 2b0274c commit 8dac423

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

bootstrap.example.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,14 @@
381381
# "miri", "cargo-miri" # for dev/nightly channels
382382
#]
383383

384+
# Specify build configuration specific for some tool, such as enabled features.
385+
#
386+
# For example, to build Miri with tracing support, use `tool-config.miri.features = ["tracing"]`
387+
#
388+
# The default value for the `features` array is `[]`. However, please note that other flags in
389+
# `bootstrap.toml` might influence the features enabled for some tools.
390+
#tool-config.TOOL_NAME.features = [FEATURE1, FEATURE2]
391+
384392
# Verbosity level: 0 == not verbose, 1 == verbose, 2 == very verbose, 3 == print environment variables on each rustc invocation
385393
#verbose = 0
386394

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@ impl Step for ToolBuild {
136136
_ => panic!("unexpected Mode for tool build"),
137137
}
138138

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

150164
// The stage0 compiler changes infrequently and does not directly depend on code

src/bootstrap/src/core/config/config.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub use crate::core::config::flags::Subcommand;
3535
use crate::core::config::flags::{Color, Flags};
3636
use crate::core::config::target_selection::TargetSelectionList;
3737
use crate::core::config::toml::TomlConfig;
38-
use crate::core::config::toml::build::Build;
38+
use crate::core::config::toml::build::{Build, ToolConfig};
3939
use crate::core::config::toml::change_id::ChangeId;
4040
use crate::core::config::toml::rust::{
4141
LldMode, RustOptimize, check_incompatible_options_for_ci_rustc,
@@ -114,6 +114,7 @@ pub struct Config {
114114
pub bootstrap_cache_path: Option<PathBuf>,
115115
pub extended: bool,
116116
pub tools: Option<HashSet<String>>,
117+
pub tool_config: HashMap<String, ToolConfig>,
117118
pub sanitizers: bool,
118119
pub profiler: bool,
119120
pub omit_git_hash: bool,
@@ -689,6 +690,7 @@ impl Config {
689690
bootstrap_cache_path,
690691
extended,
691692
tools,
693+
tool_config,
692694
verbose,
693695
sanitizers,
694696
profiler,
@@ -835,6 +837,7 @@ impl Config {
835837
set(&mut config.full_bootstrap, full_bootstrap);
836838
set(&mut config.extended, extended);
837839
config.tools = tools;
840+
set(&mut config.tool_config, tool_config);
838841
set(&mut config.verbose, verbose);
839842
set(&mut config.sanitizers, sanitizers);
840843
set(&mut config.profiler, profiler);

src/bootstrap/src/core/config/toml/build.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//! various feature flags. These options apply across different stages and components
77
//! unless specifically overridden by other configuration sections or command-line flags.
88
9+
use std::collections::HashMap;
10+
911
use serde::{Deserialize, Deserializer};
1012

1113
use crate::core::config::toml::ReplaceOpt;
@@ -42,6 +44,7 @@ define_config! {
4244
bootstrap_cache_path: Option<PathBuf> = "bootstrap-cache-path",
4345
extended: Option<bool> = "extended",
4446
tools: Option<HashSet<String>> = "tools",
47+
tool_config: Option<HashMap<String, ToolConfig>> = "tool-config",
4548
verbose: Option<usize> = "verbose",
4649
sanitizers: Option<bool> = "sanitizers",
4750
profiler: Option<bool> = "profiler",
@@ -70,3 +73,10 @@ define_config! {
7073
exclude: Option<Vec<PathBuf>> = "exclude",
7174
}
7275
}
76+
77+
define_config! {
78+
#[derive(Default, Clone)]
79+
struct ToolConfig {
80+
features: Option<Vec<String>> = "features",
81+
}
82+
}

src/bootstrap/src/utils/change_tracker.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,4 +421,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
421421
severity: ChangeSeverity::Info,
422422
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.",
423423
},
424+
ChangeInfo {
425+
change_id: 142379,
426+
severity: ChangeSeverity::Info,
427+
summary: "Added new option `tool-config.TOOL_NAME.features` to specify the features to compile a tool with",
428+
},
424429
];

0 commit comments

Comments
 (0)