Skip to content

Commit

Permalink
Make ./x.py <cmd> compiler/<crate> aware of the crate's features
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Aug 30, 2024
1 parent 0d63418 commit dba3f06
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl Step for Rustc {
self.override_build_kind.unwrap_or(builder.kind),
);

rustc_cargo(builder, &mut cargo, target, &compiler);
rustc_cargo(builder, &mut cargo, target, &compiler, &self.crates);

// For ./x.py clippy, don't run with --all-targets because
// linting tests and benchmarks can produce very noisy results
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl Step for Rustc {
Kind::Clippy,
);

rustc_cargo(builder, &mut cargo, target, &compiler);
rustc_cargo(builder, &mut cargo, target, &compiler, &self.crates);

// Explicitly pass -p for all compiler crates -- this will force cargo
// to also lint the tests/benches/examples for these crates, rather
Expand Down
5 changes: 3 additions & 2 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ impl Step for Rustc {
Kind::Build,
);

rustc_cargo(builder, &mut cargo, target, &compiler);
rustc_cargo(builder, &mut cargo, target, &compiler, &self.crates);

// NB: all RUSTFLAGS should be added to `rustc_cargo()` so they will be
// consistently applied by check/doc/test modes too.
Expand Down Expand Up @@ -1042,10 +1042,11 @@ pub fn rustc_cargo(
cargo: &mut Cargo,
target: TargetSelection,
compiler: &Compiler,
crates: &[String],
) {
cargo
.arg("--features")
.arg(builder.rustc_features(builder.kind, target))
.arg(builder.rustc_features(builder.kind, target, crates))
.arg("--manifest-path")
.arg(builder.src.join("compiler/rustc/Cargo.toml"));

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ impl Step for Rustc {
// see https://github.com/rust-lang/rust/pull/122066#issuecomment-1983049222
// cargo.rustdocflag("--generate-link-to-definition");

compile::rustc_cargo(builder, &mut cargo, target, &compiler);
compile::rustc_cargo(builder, &mut cargo, target, &compiler, &self.crates);
cargo.arg("-Zskip-rustdoc-fingerprint");

// Only include compiler crates, no dependencies of those, such as `libc`.
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2692,7 +2692,7 @@ impl Step for Crate {
}
}
Mode::Rustc => {
compile::rustc_cargo(builder, &mut cargo, target, &compiler);
compile::rustc_cargo(builder, &mut cargo, target, &compiler, &self.crates);
}
_ => panic!("can only test libraries"),
};
Expand Down
10 changes: 9 additions & 1 deletion src/bootstrap/src/core/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::BTreeMap;
use std::path::PathBuf;

use serde_derive::Deserialize;
Expand All @@ -21,6 +22,7 @@ struct Package {
manifest_path: String,
dependencies: Vec<Dependency>,
targets: Vec<Target>,
features: BTreeMap<String, Vec<String>>,
}

/// For more information, see the output of
Expand Down Expand Up @@ -51,7 +53,13 @@ pub fn build(build: &mut Build) {
.map(|dep| dep.name)
.collect();
let has_lib = package.targets.iter().any(|t| t.kind.iter().any(|k| k == "lib"));
let krate = Crate { name: name.clone(), deps, path, has_lib };
let krate = Crate {
name: name.clone(),
deps,
path,
has_lib,
features: package.features.keys().cloned().collect(),
};
let relative_path = krate.local_path(build);
build.crates.insert(name.clone(), krate);
let existing_path = build.crate_paths.insert(relative_path, name);
Expand Down
21 changes: 16 additions & 5 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ struct Crate {
deps: HashSet<String>,
path: PathBuf,
has_lib: bool,
features: Vec<String>,
}

impl Crate {
Expand Down Expand Up @@ -666,16 +667,25 @@ impl Build {
}

/// Gets the space-separated set of activated features for the compiler.
fn rustc_features(&self, kind: Kind, target: TargetSelection) -> String {
fn rustc_features(&self, kind: Kind, target: TargetSelection, crates: &[String]) -> String {
let possible_features_by_crates: HashSet<_> = crates
.iter()
.flat_map(|krate| &self.crates[krate].features)
.map(std::ops::Deref::deref)
.collect();
let mut features = vec![];
if self.config.jemalloc {
if self.config.jemalloc && possible_features_by_crates.contains("jemalloc") {
features.push("jemalloc");
}
if self.config.llvm_enabled(target) || kind == Kind::Check {
if (self.config.llvm_enabled(target) || kind == Kind::Check)
&& possible_features_by_crates.contains("llvm")
{
features.push("llvm");
}
// keep in sync with `bootstrap/compile.rs:rustc_cargo_env`
if self.config.rustc_parallel {
if self.config.rustc_parallel
&& possible_features_by_crates.contains("rustc_use_parallel_compiler")
{
features.push("rustc_use_parallel_compiler");
}

Expand All @@ -684,7 +694,8 @@ impl Build {
// which is everything (including debug/trace/etc.)
// if its unset, if debug_assertions is on, then debug_logging will also be on
// as well as tracing *ignoring* this feature when debug_assertions is on
if !self.config.rust_debug_logging {
if !self.config.rust_debug_logging && possible_features_by_crates.contains("max_level_info")
{
features.push("max_level_info");
}

Expand Down

0 comments on commit dba3f06

Please sign in to comment.