]> git.lizzy.rs Git - rust.git/blobdiff - src/bootstrap/builder.rs
Rollup merge of #60187 - tmandry:generator-optimization, r=eddyb
[rust.git] / src / bootstrap / builder.rs
index 198b7dbc3f9d42cc0fb84da8e7023eaa60973eaa..2281a45e014a9cb0d89ddb4004bc8ae01c274076 100644 (file)
@@ -59,7 +59,7 @@ pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash {
 
     const DEFAULT: bool = false;
 
-    /// Run this rule for all hosts without cross compiling.
+    /// If true, then this rule should be skipped if --target was specified, but --host was not
     const ONLY_HOSTS: bool = false;
 
     /// Primary function to execute this rule. Can call `builder.ensure()`
@@ -163,7 +163,7 @@ fn maybe_run(&self, builder: &Builder<'_>, pathset: &PathSet) {
 
         // Determine the targets participating in this rule.
         let targets = if self.only_hosts {
-            if !builder.config.run_host_only {
+            if builder.config.skip_only_host_steps {
                 return; // don't run anything
             } else {
                 &builder.hosts
@@ -581,6 +581,30 @@ pub fn compiler(&self, stage: u32, host: Interned<String>) -> Compiler {
         })
     }
 
+    /// Similar to `compiler`, except handles the full-bootstrap option to
+    /// silently use the stage1 compiler instead of a stage2 compiler if one is
+    /// requested.
+    ///
+    /// Note that this does *not* have the side effect of creating
+    /// `compiler(stage, host)`, unlike `compiler` above which does have such
+    /// a side effect. The returned compiler here can only be used to compile
+    /// new artifacts, it can't be used to rely on the presence of a particular
+    /// sysroot.
+    ///
+    /// See `force_use_stage1` for documentation on what each argument is.
+    pub fn compiler_for(
+        &self,
+        stage: u32,
+        host: Interned<String>,
+        target: Interned<String>,
+    ) -> Compiler {
+        if self.build.force_use_stage1(Compiler { stage, host }, target) {
+            self.compiler(1, self.config.build)
+        } else {
+            self.compiler(stage, host)
+        }
+    }
+
     pub fn sysroot(&self, compiler: Compiler) -> Interned<PathBuf> {
         self.ensure(compile::Sysroot { compiler })
     }
@@ -754,11 +778,7 @@ pub fn cargo(
         // This is for the original compiler, but if we're forced to use stage 1, then
         // std/test/rustc stamps won't exist in stage 2, so we need to get those from stage 1, since
         // we copy the libs forward.
-        let cmp = if self.force_use_stage1(compiler, target) {
-            self.compiler(1, compiler.host)
-        } else {
-            compiler
-        };
+        let cmp = self.compiler_for(compiler.stage, compiler.host, target);
 
         let libstd_stamp = match cmd {
             "check" | "clippy" | "fix" => check::libstd_stamp(self, cmp, target),
@@ -1318,7 +1338,7 @@ fn configure(host: &[&str], target: &[&str]) -> Config {
         let mut config = Config::default_opts();
         // don't save toolstates
         config.save_toolstates = None;
-        config.run_host_only = true;
+        config.skip_only_host_steps = false;
         config.dry_run = true;
         // try to avoid spurious failures in dist where we create/delete each others file
         let dir = config.out.join("tmp-rustbuild-tests").join(
@@ -1358,7 +1378,7 @@ fn dist_baseline() {
 
         assert_eq!(
             first(builder.cache.all::<dist::Docs>()),
-            &[dist::Docs { stage: 2, host: a },]
+            &[dist::Docs { host: a },]
         );
         assert_eq!(
             first(builder.cache.all::<dist::Mingw>()),
@@ -1373,7 +1393,7 @@ fn dist_baseline() {
         assert_eq!(
             first(builder.cache.all::<dist::Std>()),
             &[dist::Std {
-                compiler: Compiler { host: a, stage: 2 },
+                compiler: Compiler { host: a, stage: 1 },
                 target: a,
             },]
         );
@@ -1392,8 +1412,8 @@ fn dist_with_targets() {
         assert_eq!(
             first(builder.cache.all::<dist::Docs>()),
             &[
-                dist::Docs { stage: 2, host: a },
-                dist::Docs { stage: 2, host: b },
+                dist::Docs { host: a },
+                dist::Docs { host: b },
             ]
         );
         assert_eq!(
@@ -1410,7 +1430,7 @@ fn dist_with_targets() {
             first(builder.cache.all::<dist::Std>()),
             &[
                 dist::Std {
-                    compiler: Compiler { host: a, stage: 2 },
+                    compiler: Compiler { host: a, stage: 1 },
                     target: a,
                 },
                 dist::Std {
@@ -1434,8 +1454,8 @@ fn dist_with_hosts() {
         assert_eq!(
             first(builder.cache.all::<dist::Docs>()),
             &[
-                dist::Docs { stage: 2, host: a },
-                dist::Docs { stage: 2, host: b },
+                dist::Docs { host: a },
+                dist::Docs { host: b },
             ]
         );
         assert_eq!(
@@ -1457,11 +1477,11 @@ fn dist_with_hosts() {
             first(builder.cache.all::<dist::Std>()),
             &[
                 dist::Std {
-                    compiler: Compiler { host: a, stage: 2 },
+                    compiler: Compiler { host: a, stage: 1 },
                     target: a,
                 },
                 dist::Std {
-                    compiler: Compiler { host: a, stage: 2 },
+                    compiler: Compiler { host: a, stage: 1 },
                     target: b,
                 },
             ]
@@ -1469,6 +1489,40 @@ fn dist_with_hosts() {
         assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
     }
 
+    #[test]
+    fn dist_only_cross_host() {
+        let a = INTERNER.intern_str("A");
+        let b = INTERNER.intern_str("B");
+        let mut build = Build::new(configure(&["B"], &[]));
+        build.config.docs = false;
+        build.config.extended = true;
+        build.hosts = vec![b];
+        let mut builder = Builder::new(&build);
+        builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
+
+        assert_eq!(
+            first(builder.cache.all::<dist::Rustc>()),
+            &[
+                dist::Rustc {
+                    compiler: Compiler { host: b, stage: 2 }
+                },
+            ]
+        );
+        assert_eq!(
+            first(builder.cache.all::<compile::Rustc>()),
+            &[
+                compile::Rustc {
+                    compiler: Compiler { host: a, stage: 0 },
+                    target: a,
+                },
+                compile::Rustc {
+                    compiler: Compiler { host: a, stage: 1 },
+                    target: b,
+                },
+            ]
+        );
+    }
+
     #[test]
     fn dist_with_targets_and_hosts() {
         let build = Build::new(configure(&["B"], &["C"]));
@@ -1482,9 +1536,9 @@ fn dist_with_targets_and_hosts() {
         assert_eq!(
             first(builder.cache.all::<dist::Docs>()),
             &[
-                dist::Docs { stage: 2, host: a },
-                dist::Docs { stage: 2, host: b },
-                dist::Docs { stage: 2, host: c },
+                dist::Docs { host: a },
+                dist::Docs { host: b },
+                dist::Docs { host: c },
             ]
         );
         assert_eq!(
@@ -1510,11 +1564,11 @@ fn dist_with_targets_and_hosts() {
             first(builder.cache.all::<dist::Std>()),
             &[
                 dist::Std {
-                    compiler: Compiler { host: a, stage: 2 },
+                    compiler: Compiler { host: a, stage: 1 },
                     target: a,
                 },
                 dist::Std {
-                    compiler: Compiler { host: a, stage: 2 },
+                    compiler: Compiler { host: a, stage: 1 },
                     target: b,
                 },
                 dist::Std {
@@ -1529,7 +1583,7 @@ fn dist_with_targets_and_hosts() {
     #[test]
     fn dist_with_target_flag() {
         let mut config = configure(&["B"], &["C"]);
-        config.run_host_only = false; // as-if --target=C was passed
+        config.skip_only_host_steps = true; // as-if --target=C was passed
         let build = Build::new(config);
         let mut builder = Builder::new(&build);
         builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
@@ -1541,9 +1595,9 @@ fn dist_with_target_flag() {
         assert_eq!(
             first(builder.cache.all::<dist::Docs>()),
             &[
-                dist::Docs { stage: 2, host: a },
-                dist::Docs { stage: 2, host: b },
-                dist::Docs { stage: 2, host: c },
+                dist::Docs { host: a },
+                dist::Docs { host: b },
+                dist::Docs { host: c },
             ]
         );
         assert_eq!(
@@ -1559,11 +1613,11 @@ fn dist_with_target_flag() {
             first(builder.cache.all::<dist::Std>()),
             &[
                 dist::Std {
-                    compiler: Compiler { host: a, stage: 2 },
+                    compiler: Compiler { host: a, stage: 1 },
                     target: a,
                 },
                 dist::Std {
-                    compiler: Compiler { host: a, stage: 2 },
+                    compiler: Compiler { host: a, stage: 1 },
                     target: b,
                 },
                 dist::Std {
@@ -1587,8 +1641,8 @@ fn dist_with_same_targets_and_hosts() {
         assert_eq!(
             first(builder.cache.all::<dist::Docs>()),
             &[
-                dist::Docs { stage: 2, host: a },
-                dist::Docs { stage: 2, host: b },
+                dist::Docs { host: a },
+                dist::Docs { host: b },
             ]
         );
         assert_eq!(
@@ -1610,11 +1664,11 @@ fn dist_with_same_targets_and_hosts() {
             first(builder.cache.all::<dist::Std>()),
             &[
                 dist::Std {
-                    compiler: Compiler { host: a, stage: 2 },
+                    compiler: Compiler { host: a, stage: 1 },
                     target: a,
                 },
                 dist::Std {
-                    compiler: Compiler { host: a, stage: 2 },
+                    compiler: Compiler { host: a, stage: 1 },
                     target: b,
                 },
             ]
@@ -1664,10 +1718,6 @@ fn dist_with_same_targets_and_hosts() {
                     compiler: Compiler { host: a, stage: 1 },
                     target: b,
                 },
-                compile::Test {
-                    compiler: Compiler { host: a, stage: 2 },
-                    target: b,
-                },
             ]
         );
         assert_eq!(
@@ -1720,10 +1770,6 @@ fn build_default() {
                     compiler: Compiler { host: b, stage: 2 },
                     target: a,
                 },
-                compile::Rustc {
-                    compiler: Compiler { host: a, stage: 0 },
-                    target: b,
-                },
                 compile::Rustc {
                     compiler: Compiler { host: a, stage: 1 },
                     target: b,
@@ -1758,10 +1804,6 @@ fn build_default() {
                     compiler: Compiler { host: b, stage: 2 },
                     target: a,
                 },
-                compile::Test {
-                    compiler: Compiler { host: a, stage: 0 },
-                    target: b,
-                },
                 compile::Test {
                     compiler: Compiler { host: a, stage: 1 },
                     target: b,
@@ -1789,7 +1831,7 @@ fn build_default() {
     #[test]
     fn build_with_target_flag() {
         let mut config = configure(&["B"], &["C"]);
-        config.run_host_only = false;
+        config.skip_only_host_steps = true;
         let build = Build::new(config);
         let mut builder = Builder::new(&build);
         builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]);
@@ -1808,9 +1850,6 @@ fn build_with_target_flag() {
                 compile::Assemble {
                     target_compiler: Compiler { host: a, stage: 1 },
                 },
-                compile::Assemble {
-                    target_compiler: Compiler { host: b, stage: 1 },
-                },
                 compile::Assemble {
                     target_compiler: Compiler { host: a, stage: 2 },
                 },
@@ -1830,10 +1869,6 @@ fn build_with_target_flag() {
                     compiler: Compiler { host: a, stage: 1 },
                     target: a,
                 },
-                compile::Rustc {
-                    compiler: Compiler { host: a, stage: 0 },
-                    target: b,
-                },
                 compile::Rustc {
                     compiler: Compiler { host: a, stage: 1 },
                     target: b,
@@ -1860,10 +1895,6 @@ fn build_with_target_flag() {
                     compiler: Compiler { host: b, stage: 2 },
                     target: a,
                 },
-                compile::Test {
-                    compiler: Compiler { host: a, stage: 0 },
-                    target: b,
-                },
                 compile::Test {
                     compiler: Compiler { host: a, stage: 1 },
                     target: b,