@@ -180,7 +180,7 @@ struct Crate {
180
180
///
181
181
/// These entries currently correspond to the various output directories of the
182
182
/// build system, with each mod generating output in a different directory.
183
- #[ derive( Clone , Copy ) ]
183
+ #[ derive( Clone , Copy , PartialEq , Eq ) ]
184
184
pub enum Mode {
185
185
/// This cargo is going to build the standard library, placing output in the
186
186
/// "stageN-std" directory.
@@ -491,14 +491,35 @@ impl Build {
491
491
// For other crates, however, we know that we've already got a standard
492
492
// library up and running, so we can use the normal compiler to compile
493
493
// build scripts in that situation.
494
- if let Mode :: Libstd = mode {
494
+ if mode == Mode :: Libstd {
495
495
cargo. env ( "RUSTC_SNAPSHOT" , & self . rustc )
496
496
. env ( "RUSTC_SNAPSHOT_LIBDIR" , self . rustc_snapshot_libdir ( ) ) ;
497
497
} else {
498
498
cargo. env ( "RUSTC_SNAPSHOT" , self . compiler_path ( compiler) )
499
499
. env ( "RUSTC_SNAPSHOT_LIBDIR" , self . rustc_libdir ( compiler) ) ;
500
500
}
501
501
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
+
502
523
// Ignore incremental modes except for stage0, since we're
503
524
// not guaranteeing correctness acros builds if the compiler
504
525
// is changing under your feet.`
0 commit comments