Skip to content

Commit

Permalink
Auto merge of #61212 - alexcrichton:skip-rustc, r=pietroalbini
Browse files Browse the repository at this point in the history
ci: Attempt to skip a full rustc compile on dist*

Currently when we're preparing cross-compiled compilers it can take
quite some time because we have to build the compiler itself three
different times. The first is the normal bootstrap, the second is a
second build for the build platform, and the third is the actual target
architecture compiler. The second compiler was historically built
exclusively for procedural macros, and long ago we didn't actually need
it.

This commit tries out avoiding that second compiled compiler, meaning we
only compile rustc for the build platform only once. Some local testing
shows that this is promising, but bors is of course the ultimate test!
  • Loading branch information
bors committed May 30, 2019
2 parents 4137901 + 7b362bb commit 19e0ddb
Show file tree
Hide file tree
Showing 7 changed files with 253 additions and 224 deletions.
133 changes: 82 additions & 51 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,30 @@ impl<'a> Builder<'a> {
})
}

/// 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 })
}
Expand Down Expand Up @@ -754,11 +778,7 @@ impl<'a> Builder<'a> {
// 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),
Expand Down Expand Up @@ -1358,7 +1378,7 @@ mod __test {

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>()),
Expand All @@ -1373,7 +1393,7 @@ mod __test {
assert_eq!(
first(builder.cache.all::<dist::Std>()),
&[dist::Std {
compiler: Compiler { host: a, stage: 2 },
compiler: Compiler { host: a, stage: 1 },
target: a,
},]
);
Expand All @@ -1392,8 +1412,8 @@ mod __test {
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!(
Expand All @@ -1410,7 +1430,7 @@ mod __test {
first(builder.cache.all::<dist::Std>()),
&[
dist::Std {
compiler: Compiler { host: a, stage: 2 },
compiler: Compiler { host: a, stage: 1 },
target: a,
},
dist::Std {
Expand All @@ -1434,8 +1454,8 @@ mod __test {
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!(
Expand All @@ -1457,18 +1477,52 @@ mod __test {
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,
},
]
);
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"]));
Expand All @@ -1482,9 +1536,9 @@ mod __test {
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!(
Expand All @@ -1510,11 +1564,11 @@ mod __test {
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 {
Expand All @@ -1541,9 +1595,9 @@ mod __test {
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!(
Expand All @@ -1559,11 +1613,11 @@ mod __test {
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 {
Expand All @@ -1587,8 +1641,8 @@ mod __test {
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!(
Expand All @@ -1610,11 +1664,11 @@ mod __test {
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,
},
]
Expand Down Expand Up @@ -1664,10 +1718,6 @@ mod __test {
compiler: Compiler { host: a, stage: 1 },
target: b,
},
compile::Test {
compiler: Compiler { host: a, stage: 2 },
target: b,
},
]
);
assert_eq!(
Expand Down Expand Up @@ -1720,10 +1770,6 @@ mod __test {
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,
Expand Down Expand Up @@ -1758,10 +1804,6 @@ mod __test {
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,
Expand Down Expand Up @@ -1808,9 +1850,6 @@ mod __test {
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 },
},
Expand All @@ -1830,10 +1869,6 @@ mod __test {
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,
Expand All @@ -1860,10 +1895,6 @@ mod __test {
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,
Expand Down
29 changes: 16 additions & 13 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,20 @@ impl Step for Std {

builder.ensure(StartupObjects { compiler, target });

if builder.force_use_stage1(compiler, target) {
let from = builder.compiler(1, builder.config.build);
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
if compiler_to_use != compiler {
builder.ensure(Std {
compiler: from,
compiler: compiler_to_use,
target,
});
builder.info(&format!("Uplifting stage1 std ({} -> {})", from.host, target));
builder.info(&format!("Uplifting stage1 std ({} -> {})", compiler_to_use.host, target));

// Even if we're not building std this stage, the new sysroot must
// still contain the third party objects needed by various targets.
copy_third_party_objects(builder, &compiler, target);

builder.ensure(StdLink {
compiler: from,
compiler: compiler_to_use,
target_compiler: compiler,
target,
});
Expand Down Expand Up @@ -403,15 +403,16 @@ impl Step for Test {
return;
}

if builder.force_use_stage1(compiler, target) {
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
if compiler_to_use != compiler {
builder.ensure(Test {
compiler: builder.compiler(1, builder.config.build),
compiler: compiler_to_use,
target,
});
builder.info(
&format!("Uplifting stage1 test ({} -> {})", builder.config.build, target));
builder.ensure(TestLink {
compiler: builder.compiler(1, builder.config.build),
compiler: compiler_to_use,
target_compiler: compiler,
target,
});
Expand Down Expand Up @@ -529,15 +530,16 @@ impl Step for Rustc {
return;
}

if builder.force_use_stage1(compiler, target) {
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
if compiler_to_use != compiler {
builder.ensure(Rustc {
compiler: builder.compiler(1, builder.config.build),
compiler: compiler_to_use,
target,
});
builder.info(&format!("Uplifting stage1 rustc ({} -> {})",
builder.config.build, target));
builder.ensure(RustcLink {
compiler: builder.compiler(1, builder.config.build),
compiler: compiler_to_use,
target_compiler: compiler,
target,
});
Expand Down Expand Up @@ -687,9 +689,10 @@ impl Step for CodegenBackend {
return;
}

if builder.force_use_stage1(compiler, target) {
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
if compiler_to_use != compiler {
builder.ensure(CodegenBackend {
compiler: builder.compiler(1, builder.config.build),
compiler: compiler_to_use,
target,
backend,
});
Expand Down
Loading

0 comments on commit 19e0ddb

Please sign in to comment.