Skip to content

Commit 4838c00

Browse files
authored
Rollup merge of #142379 - Stypox:bootstrap-tool-config, r=Kobzol
Add bootstrap option to compile a tool with features Add an option to specify which features to build a tool with, e.g. it will be useful to build Miri with tracing enabled: ```toml tool-config.miri.features = ["tracing"] ``` See [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Passing.20--features.20to.20Miri.20build.20using.20.2E.2Fx.2Epy/with/523564773) for the options considered. If the final decision will be different than what I wrote now, I will update the code as needed. The reason why the option is `tool-config.miri.features` instead of something like `tool-features.miri` is to possibly allow adding more tool-specific configurations in the future. I didn't do any validation of the keys of the `tool-config` hashmap, since I saw that no validation is done on the `tools` hashset either. I don't like much the fact that features can be chosen by various places of the codebase: `Step`s can have some fixed `extra_features`, `prepare_tool_cargo` will add features depending on some bootstrapping options, and the newly added option can also contribute features to tools. However I think it is out of scope of this PR to try to refactor all of that (if it even is refactorable), so I left a comment in the codebase explaining all of the sources of features I could find.
2 parents 7cf0870 + 17f69bf commit 4838c00

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

bootstrap.example.toml

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

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

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

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

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+
139152
let mut cargo = prepare_tool_cargo(
140153
builder,
141154
self.compiler,
@@ -144,7 +157,7 @@ impl Step for ToolBuild {
144157
Kind::Build,
145158
path,
146159
self.source_type,
147-
&self.extra_features,
160+
&features,
148161
);
149162

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

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

Lines changed: 6 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, Tool};
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,
@@ -101,6 +101,9 @@ pub struct Config {
101101
pub bootstrap_cache_path: Option<PathBuf>,
102102
pub extended: bool,
103103
pub tools: Option<HashSet<String>>,
104+
/// Specify build configuration specific for some tool, such as enabled features, see [Tool].
105+
/// The key in the map is the name of the tool, and the value is tool-specific configuration.
106+
pub tool: HashMap<String, Tool>,
104107
pub sanitizers: bool,
105108
pub profiler: bool,
106109
pub omit_git_hash: bool,
@@ -676,6 +679,7 @@ impl Config {
676679
bootstrap_cache_path,
677680
extended,
678681
tools,
682+
tool,
679683
verbose,
680684
sanitizers,
681685
profiler,
@@ -822,6 +826,7 @@ impl Config {
822826
set(&mut config.full_bootstrap, full_bootstrap);
823827
set(&mut config.extended, extended);
824828
config.tools = tools;
829+
set(&mut config.tool, tool);
825830
set(&mut config.verbose, verbose);
826831
set(&mut config.sanitizers, sanitizers);
827832
set(&mut config.profiler, profiler);

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

Lines changed: 11 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: Option<HashMap<String, Tool>> = "tool",
4548
verbose: Option<usize> = "verbose",
4649
sanitizers: Option<bool> = "sanitizers",
4750
profiler: Option<bool> = "profiler",
@@ -70,3 +73,11 @@ define_config! {
7073
exclude: Option<Vec<PathBuf>> = "exclude",
7174
}
7275
}
76+
77+
define_config! {
78+
/// Configuration specific for some tool, e.g. which features to enable during build.
79+
#[derive(Default, Clone)]
80+
struct Tool {
81+
features: Option<Vec<String>> = "features",
82+
}
83+
}

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.TOOL_NAME.features` to specify the features to compile a tool with",
428+
},
424429
];

0 commit comments

Comments
 (0)