Skip to content

Commit 39e3add

Browse files
committed
Make ./x.py <cmd> compiler/<crate> aware of the crate's features
1 parent 0d63418 commit 39e3add

File tree

7 files changed

+30
-12
lines changed

7 files changed

+30
-12
lines changed

src/bootstrap/src/core/build_steps/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl Step for Rustc {
228228
self.override_build_kind.unwrap_or(builder.kind),
229229
);
230230

231-
rustc_cargo(builder, &mut cargo, target, &compiler);
231+
rustc_cargo(builder, &mut cargo, target, &compiler, &self.crates);
232232

233233
// For ./x.py clippy, don't run with --all-targets because
234234
// linting tests and benchmarks can produce very noisy results

src/bootstrap/src/core/build_steps/clippy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl Step for Rustc {
197197
Kind::Clippy,
198198
);
199199

200-
rustc_cargo(builder, &mut cargo, target, &compiler);
200+
rustc_cargo(builder, &mut cargo, target, &compiler, &self.crates);
201201

202202
// Explicitly pass -p for all compiler crates -- this will force cargo
203203
// to also lint the tests/benches/examples for these crates, rather

src/bootstrap/src/core/build_steps/compile.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ impl Step for Rustc {
983983
Kind::Build,
984984
);
985985

986-
rustc_cargo(builder, &mut cargo, target, &compiler);
986+
rustc_cargo(builder, &mut cargo, target, &compiler, &self.crates);
987987

988988
// NB: all RUSTFLAGS should be added to `rustc_cargo()` so they will be
989989
// consistently applied by check/doc/test modes too.
@@ -1042,10 +1042,11 @@ pub fn rustc_cargo(
10421042
cargo: &mut Cargo,
10431043
target: TargetSelection,
10441044
compiler: &Compiler,
1045+
crates: &[String],
10451046
) {
10461047
cargo
10471048
.arg("--features")
1048-
.arg(builder.rustc_features(builder.kind, target))
1049+
.arg(builder.rustc_features(builder.kind, target, crates))
10491050
.arg("--manifest-path")
10501051
.arg(builder.src.join("compiler/rustc/Cargo.toml"));
10511052

src/bootstrap/src/core/build_steps/doc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ impl Step for Rustc {
826826
// see https://github.com/rust-lang/rust/pull/122066#issuecomment-1983049222
827827
// cargo.rustdocflag("--generate-link-to-definition");
828828

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

832832
// Only include compiler crates, no dependencies of those, such as `libc`.

src/bootstrap/src/core/build_steps/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2692,7 +2692,7 @@ impl Step for Crate {
26922692
}
26932693
}
26942694
Mode::Rustc => {
2695-
compile::rustc_cargo(builder, &mut cargo, target, &compiler);
2695+
compile::rustc_cargo(builder, &mut cargo, target, &compiler, &self.crates);
26962696
}
26972697
_ => panic!("can only test libraries"),
26982698
};

src/bootstrap/src/core/metadata.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::collections::BTreeMap;
12
use std::path::PathBuf;
23

34
use serde_derive::Deserialize;
@@ -21,6 +22,7 @@ struct Package {
2122
manifest_path: String,
2223
dependencies: Vec<Dependency>,
2324
targets: Vec<Target>,
25+
features: BTreeMap<String, Vec<String>>,
2426
}
2527

2628
/// For more information, see the output of
@@ -51,7 +53,13 @@ pub fn build(build: &mut Build) {
5153
.map(|dep| dep.name)
5254
.collect();
5355
let has_lib = package.targets.iter().any(|t| t.kind.iter().any(|k| k == "lib"));
54-
let krate = Crate { name: name.clone(), deps, path, has_lib };
56+
let krate = Crate {
57+
name: name.clone(),
58+
deps,
59+
path,
60+
has_lib,
61+
features: package.features.keys().cloned().collect(),
62+
};
5563
let relative_path = krate.local_path(build);
5664
build.crates.insert(name.clone(), krate);
5765
let existing_path = build.crate_paths.insert(relative_path, name);

src/bootstrap/src/lib.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ struct Crate {
183183
deps: HashSet<String>,
184184
path: PathBuf,
185185
has_lib: bool,
186+
features: Vec<String>,
186187
}
187188

188189
impl Crate {
@@ -666,16 +667,24 @@ impl Build {
666667
}
667668

668669
/// Gets the space-separated set of activated features for the compiler.
669-
fn rustc_features(&self, kind: Kind, target: TargetSelection) -> String {
670+
fn rustc_features(&self, kind: Kind, target: TargetSelection, crates: &[String]) -> String {
671+
let possible_features_by_crates: HashSet<_> = crates
672+
.iter()
673+
.flat_map(|krate| &self.crates[krate].features)
674+
.map(std::ops::Deref::deref)
675+
.collect();
676+
let check = |feature: &str| -> bool {
677+
crates.is_empty() || possible_features_by_crates.contains(feature)
678+
};
670679
let mut features = vec![];
671-
if self.config.jemalloc {
680+
if self.config.jemalloc && check("jemalloc") {
672681
features.push("jemalloc");
673682
}
674-
if self.config.llvm_enabled(target) || kind == Kind::Check {
683+
if (self.config.llvm_enabled(target) || kind == Kind::Check) && check("llvm") {
675684
features.push("llvm");
676685
}
677686
// keep in sync with `bootstrap/compile.rs:rustc_cargo_env`
678-
if self.config.rustc_parallel {
687+
if self.config.rustc_parallel && check("rustc_use_parallel_compiler") {
679688
features.push("rustc_use_parallel_compiler");
680689
}
681690

@@ -684,7 +693,7 @@ impl Build {
684693
// which is everything (including debug/trace/etc.)
685694
// if its unset, if debug_assertions is on, then debug_logging will also be on
686695
// as well as tracing *ignoring* this feature when debug_assertions is on
687-
if !self.config.rust_debug_logging {
696+
if !self.config.rust_debug_logging && check("max_level_info") {
688697
features.push("max_level_info");
689698
}
690699

0 commit comments

Comments
 (0)