Skip to content

Change bootstrap's tool.TOOL_NAME.features to work on any subcommand #143733

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion bootstrap.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 16 additions & 15 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -136,19 +137,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,
Expand All @@ -157,7 +145,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
Expand Down Expand Up @@ -244,7 +232,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();
Expand All @@ -261,6 +250,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.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
// avoid rebuilding when running tests.
cargo.env("SYSROOT", builder.sysroot(compiler));
Expand Down
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 @@ -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`.",
},
];
Loading