Skip to content

Commit 1d93a6c

Browse files
committed
Fix handlebars failure by using the rustbuild feature less indiscriminately.
1 parent dc63eff commit 1d93a6c

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/bootstrap/bin/rustc.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ fn main() {
7979
cmd.args(&args)
8080
.arg("--cfg")
8181
.arg(format!("stage{}", stage))
82-
.arg("--cfg").arg("rustbuild")
8382
.env(bootstrap::util::dylib_path_var(),
8483
env::join_paths(&dylib_path).unwrap());
8584

@@ -95,6 +94,13 @@ fn main() {
9594
cmd.arg("-Cprefer-dynamic");
9695
}
9796

97+
// Pass the `rustbuild` feature flag to crates which rustbuild is
98+
// building. See the comment in bootstrap/lib.rs where this env var is
99+
// set for more details.
100+
if env::var_os("RUSTBUILD_UNSTABLE").is_some() {
101+
cmd.arg("--cfg").arg("rustbuild");
102+
}
103+
98104
// Help the libc crate compile by assisting it in finding the MUSL
99105
// native libraries.
100106
if let Some(s) = env::var_os("MUSL_ROOT") {

src/bootstrap/lib.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ struct Crate {
180180
///
181181
/// These entries currently correspond to the various output directories of the
182182
/// build system, with each mod generating output in a different directory.
183-
#[derive(Clone, Copy)]
183+
#[derive(Clone, Copy, PartialEq, Eq)]
184184
pub enum Mode {
185185
/// This cargo is going to build the standard library, placing output in the
186186
/// "stageN-std" directory.
@@ -491,14 +491,35 @@ impl Build {
491491
// For other crates, however, we know that we've already got a standard
492492
// library up and running, so we can use the normal compiler to compile
493493
// build scripts in that situation.
494-
if let Mode::Libstd = mode {
494+
if mode == Mode::Libstd {
495495
cargo.env("RUSTC_SNAPSHOT", &self.rustc)
496496
.env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_snapshot_libdir());
497497
} else {
498498
cargo.env("RUSTC_SNAPSHOT", self.compiler_path(compiler))
499499
.env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_libdir(compiler));
500500
}
501501

502+
// There are two invariants we try must maintain:
503+
// * stable crates cannot depend on unstable crates (general Rust rule),
504+
// * crates that end up in the sysroot must be unstable (rustbuild rule).
505+
//
506+
// In order to do enforce the latter, we pass the env var
507+
// `RUSTBUILD_UNSTABLE` down the line for any crates which will end up
508+
// in the sysroot. We read this in bootstrap/bin/rustc.rs and if it is
509+
// set, then we pass the `rustbuild` feature to rustc when building the
510+
// the crate.
511+
//
512+
// In turn, crates that can be used here should recognise the `rustbuild`
513+
// feature and opt-in to `rustc_private`.
514+
//
515+
// We can't always pass `rustbuild` because crates which are outside of
516+
// the comipiler, libs, and tests are stable and we don't want to make
517+
// their deps unstable (since this would break the first invariant
518+
// above).
519+
if mode != Mode::Tool {
520+
cargo.env("RUSTBUILD_UNSTABLE", "1");
521+
}
522+
502523
// Ignore incremental modes except for stage0, since we're
503524
// not guaranteeing correctness acros builds if the compiler
504525
// is changing under your feet.`

0 commit comments

Comments
 (0)