Skip to content

Commit eaa97a2

Browse files
committed
Skip stage 0 libstd
1 parent a1d4a95 commit eaa97a2

File tree

12 files changed

+118
-57
lines changed

12 files changed

+118
-57
lines changed

src/bootstrap/bin/rustc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ fn main() {
115115
cmd.env("RUSTC_BREAK_ON_ICE", "1");
116116

117117
if let Some(target) = target {
118-
// The stage0 compiler has a special sysroot distinct from what we
119-
// actually downloaded, so we just always pass the `--sysroot` option.
120-
cmd.arg("--sysroot").arg(&sysroot);
118+
if !sysroot.is_empty() {
119+
cmd.arg("--sysroot").arg(&sysroot);
120+
}
121121

122122
// When we build Rust dylibs they're all intended for intermediate
123123
// usage, so make sure we pass the -Cprefer-dynamic flag instead of

src/bootstrap/bootstrap.py

+25-5
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ def __init__(self):
311311
self._download_url = 'https://static.rust-lang.org'
312312
self.rustc_channel = ''
313313
self.build = ''
314+
self.host = ''
315+
self.check = False
314316
self.build_dir = os.path.join(os.getcwd(), "build")
315317
self.clean = False
316318
self.config_toml = ''
@@ -357,6 +359,16 @@ def download_stage0(self):
357359
rustc_channel, self.build)
358360
self._download_stage0_helper(filename, "rust-mingw")
359361

362+
# Download the target libaries used for checking the compiler
363+
if self.check and self.host != '' and self.build != self.host and \
364+
self.rustc().startswith(self.bin_root()):
365+
lib_path = os.path.join(self.bin_root(), "lib", "rustlib", self.host, "lib")
366+
if not os.path.exists(lib_path):
367+
filename = "rust-std-{}-{}.tar.gz".format(
368+
rustc_channel, self.host)
369+
pattern = "rust-std-{}".format(self.host)
370+
self._download_stage0_helper(filename, pattern)
371+
360372
if self.cargo().startswith(self.bin_root()) and \
361373
(not os.path.exists(self.cargo()) or
362374
self.program_out_of_date(self.cargo_stamp())):
@@ -366,6 +378,8 @@ def download_stage0(self):
366378
with open(self.cargo_stamp(), 'w') as cargo_stamp:
367379
cargo_stamp.write(self.date)
368380

381+
shutil.rmtree(os.path.join(self.build_dir, "cache"), ignore_errors=True)
382+
369383
def _download_stage0_helper(self, filename, pattern):
370384
cache_dst = os.path.join(self.build_dir, "cache")
371385
rustc_cache = os.path.join(cache_dst, self.date)
@@ -451,7 +465,7 @@ def rustc_stamp(self):
451465
452466
>>> rb = RustBuild()
453467
>>> rb.build_dir = "build"
454-
>>> rb.rustc_stamp() == os.path.join("build", "stage0", ".rustc-stamp")
468+
>>> rb.rustc_stamp() == os.path.join("build", "base", ".rustc-stamp")
455469
True
456470
"""
457471
return os.path.join(self.bin_root(), '.rustc-stamp')
@@ -461,7 +475,7 @@ def cargo_stamp(self):
461475
462476
>>> rb = RustBuild()
463477
>>> rb.build_dir = "build"
464-
>>> rb.cargo_stamp() == os.path.join("build", "stage0", ".cargo-stamp")
478+
>>> rb.cargo_stamp() == os.path.join("build", "base", ".cargo-stamp")
465479
True
466480
"""
467481
return os.path.join(self.bin_root(), '.cargo-stamp')
@@ -478,16 +492,19 @@ def bin_root(self):
478492
479493
>>> rb = RustBuild()
480494
>>> rb.build_dir = "build"
481-
>>> rb.bin_root() == os.path.join("build", "stage0")
495+
>>> rb.bin_root() == os.path.join("build", "base")
482496
True
483497
484498
When the 'build' property is given should be a nested directory:
485499
486500
>>> rb.build = "devel"
487-
>>> rb.bin_root() == os.path.join("build", "devel", "stage0")
501+
>>> rb.bin_root() == os.path.join("build", "base", "devel")
488502
True
489503
"""
490-
return os.path.join(self.build_dir, self.build, "stage0")
504+
if self.build == "":
505+
return os.path.join(self.build_dir, "base")
506+
else:
507+
return os.path.join(self.build_dir, "base", self.build)
491508

492509
def get_toml(self, key):
493510
"""Returns the value of the given key in config.toml, otherwise returns None
@@ -710,6 +727,7 @@ def bootstrap(help_triggered):
710727
parser = argparse.ArgumentParser(description='Build rust')
711728
parser.add_argument('--config')
712729
parser.add_argument('--build')
730+
parser.add_argument('--host')
713731
parser.add_argument('--src')
714732
parser.add_argument('--clean', action='store_true')
715733
parser.add_argument('-v', '--verbose', action='count', default=0)
@@ -773,6 +791,8 @@ def bootstrap(help_triggered):
773791
build.update_submodules()
774792

775793
# Fetch/build the bootstrap
794+
build.host = args.host or ''
795+
build.check = 'check' in sys.argv
776796
build.build = args.build or build.build_triple()
777797
build.download_stage0()
778798
sys.stdout.flush()

src/bootstrap/builder.rs

+9-22
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl<'a> Builder<'a> {
326326
}};
327327
}
328328
match kind {
329-
Kind::Build => describe!(compile::Std, compile::Test, compile::Rustc,
329+
Kind::Build => describe!(check::Test, compile::Std, compile::Test, compile::Rustc,
330330
compile::StartupObjects, tool::BuildManifest, tool::Rustbook, tool::ErrorIndex,
331331
tool::UnstableBookGen, tool::Tidy, tool::Linkchecker, tool::CargoTest,
332332
tool::Compiletest, tool::RemoteTestServer, tool::RemoteTestClient,
@@ -624,6 +624,13 @@ impl<'a> Builder<'a> {
624624
}
625625

626626
let want_rustdoc = self.doc_tests != DocTests::No;
627+
let sysroot = if compiler.stage == 0 && !(mode == Mode::Libstd || mode == Mode::Libtest) {
628+
// Use the bootstrap compiler's sysroot for stage0
629+
// unless we are checking libstd and libtest
630+
INTERNER.intern_path(PathBuf::new())
631+
} else {
632+
self.sysroot(compiler)
633+
};
627634

628635
// Customize the compiler we're running. Specify the compiler to cargo
629636
// as our shim and then pass it some various options used to configure
@@ -637,7 +644,7 @@ impl<'a> Builder<'a> {
637644
.env("RUSTC_STAGE", stage.to_string())
638645
.env("RUSTC_DEBUG_ASSERTIONS",
639646
self.config.rust_debug_assertions.to_string())
640-
.env("RUSTC_SYSROOT", self.sysroot(compiler))
647+
.env("RUSTC_SYSROOT", sysroot)
641648
.env("RUSTC_LIBDIR", self.rustc_libdir(compiler))
642649
.env("RUSTC_RPATH", self.config.rust_rpath.to_string())
643650
.env("RUSTDOC", self.out.join("bootstrap/debug/rustdoc"))
@@ -1225,10 +1232,6 @@ mod __test {
12251232
},
12261233
]);
12271234
assert_eq!(first(builder.cache.all::<compile::Test>()), &[
1228-
compile::Test {
1229-
compiler: Compiler { host: a, stage: 0 },
1230-
target: a,
1231-
},
12321235
compile::Test {
12331236
compiler: Compiler { host: a, stage: 1 },
12341237
target: a,
@@ -1310,10 +1313,6 @@ mod __test {
13101313
]);
13111314

13121315
assert_eq!(first(builder.cache.all::<compile::Test>()), &[
1313-
compile::Test {
1314-
compiler: Compiler { host: a, stage: 0 },
1315-
target: a,
1316-
},
13171316
compile::Test {
13181317
compiler: Compiler { host: a, stage: 1 },
13191318
target: a,
@@ -1326,10 +1325,6 @@ mod __test {
13261325
compiler: Compiler { host: b, stage: 2 },
13271326
target: a,
13281327
},
1329-
compile::Test {
1330-
compiler: Compiler { host: a, stage: 0 },
1331-
target: b,
1332-
},
13331328
compile::Test {
13341329
compiler: Compiler { host: a, stage: 1 },
13351330
target: b,
@@ -1403,10 +1398,6 @@ mod __test {
14031398
]);
14041399

14051400
assert_eq!(first(builder.cache.all::<compile::Test>()), &[
1406-
compile::Test {
1407-
compiler: Compiler { host: a, stage: 0 },
1408-
target: a,
1409-
},
14101401
compile::Test {
14111402
compiler: Compiler { host: a, stage: 1 },
14121403
target: a,
@@ -1419,10 +1410,6 @@ mod __test {
14191410
compiler: Compiler { host: b, stage: 2 },
14201411
target: a,
14211412
},
1422-
compile::Test {
1423-
compiler: Compiler { host: a, stage: 0 },
1424-
target: b,
1425-
},
14261413
compile::Test {
14271414
compiler: Compiler { host: a, stage: 1 },
14281415
target: b,

src/bootstrap/check.rs

+2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ impl Step for Test {
175175
let compiler = builder.compiler(0, builder.config.build);
176176
let target = self.target;
177177

178+
builder.ensure(Std { target });
179+
178180
let out_dir = builder.stage_out(compiler, Mode::Libtest);
179181
builder.clear_if_dirty(&out_dir, &libstd_stamp(builder, compiler, target));
180182

src/bootstrap/compile.rs

+69-20
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,9 @@ impl Step for TestLink {
438438

439439
#[derive(Debug, PartialOrd, Ord, Copy, Clone, PartialEq, Eq, Hash)]
440440
pub struct Rustc {
441+
/// The target which our new compiler will run on
441442
pub target: Interned<String>,
443+
/// The compiler we're using to compile rustc
442444
pub compiler: Compiler,
443445
}
444446

@@ -467,7 +469,9 @@ impl Step for Rustc {
467469
let compiler = self.compiler;
468470
let target = self.target;
469471

470-
builder.ensure(Test { compiler, target });
472+
if compiler.stage != 0 {
473+
builder.ensure(Test { compiler, target });
474+
}
471475

472476
if builder.force_use_stage1(compiler, target) {
473477
builder.ensure(Rustc {
@@ -485,13 +489,18 @@ impl Step for Rustc {
485489
}
486490

487491
// Ensure that build scripts have a std to link against.
488-
builder.ensure(Std {
489-
compiler: builder.compiler(self.compiler.stage, builder.config.build),
490-
target: builder.config.build,
491-
});
492+
if compiler.stage != 0 {
493+
builder.ensure(Std {
494+
compiler: builder.compiler(self.compiler.stage, builder.config.build),
495+
target: builder.config.build,
496+
});
497+
}
492498
let cargo_out = builder.cargo_out(compiler, Mode::Librustc, target);
493-
builder.clear_if_dirty(&cargo_out, &libstd_stamp(builder, compiler, target));
494-
builder.clear_if_dirty(&cargo_out, &libtest_stamp(builder, compiler, target));
499+
500+
if compiler.stage != 0 {
501+
builder.clear_if_dirty(&cargo_out, &libstd_stamp(builder, compiler, target));
502+
builder.clear_if_dirty(&cargo_out, &libtest_stamp(builder, compiler, target));
503+
}
495504

496505
let mut cargo = builder.cargo(compiler, Mode::Librustc, target, "build");
497506
rustc_cargo(builder, &mut cargo);
@@ -843,17 +852,9 @@ impl Step for Sysroot {
843852

844853
/// Returns the sysroot for the `compiler` specified that *this build system
845854
/// generates*.
846-
///
847-
/// That is, the sysroot for the stage0 compiler is not what the compiler
848-
/// thinks it is by default, but it's the same as the default for stages
849-
/// 1-3.
850855
fn run(self, builder: &Builder) -> Interned<PathBuf> {
851856
let compiler = self.compiler;
852-
let sysroot = if compiler.stage == 0 {
853-
builder.out.join(&compiler.host).join("stage0-sysroot")
854-
} else {
855-
builder.out.join(&compiler.host).join(format!("stage{}", compiler.stage))
856-
};
857+
let sysroot = builder.out.join(&compiler.host).join(format!("stage{}", compiler.stage));
857858
let _ = fs::remove_dir_all(&sysroot);
858859
t!(fs::create_dir_all(&sysroot));
859860
INTERNER.intern_path(sysroot)
@@ -883,8 +884,9 @@ impl Step for Assemble {
883884
/// compiler.
884885
fn run(self, builder: &Builder) -> Compiler {
885886
let target_compiler = self.target_compiler;
887+
let stage = target_compiler.stage;
886888

887-
if target_compiler.stage == 0 {
889+
if stage == 0 {
888890
assert_eq!(builder.config.build, target_compiler.host,
889891
"Cannot obtain compiler for non-native build triple at stage 0");
890892
// The stage 0 compiler for the build triple is always pre-built.
@@ -921,8 +923,10 @@ impl Step for Assemble {
921923
for stage in 0..min(target_compiler.stage, builder.config.keep_stage.unwrap()) {
922924
let target_compiler = builder.compiler(stage, target_compiler.host);
923925
let target = target_compiler.host;
924-
builder.ensure(StdLink { compiler, target_compiler, target });
925-
builder.ensure(TestLink { compiler, target_compiler, target });
926+
if stage != 1 {
927+
builder.ensure(StdLink { compiler, target_compiler, target });
928+
builder.ensure(TestLink { compiler, target_compiler, target });
929+
}
926930
builder.ensure(RustcLink { compiler, target_compiler, target });
927931
}
928932
} else {
@@ -947,7 +951,6 @@ impl Step for Assemble {
947951
None
948952
};
949953

950-
let stage = target_compiler.stage;
951954
let host = target_compiler.host;
952955
builder.info(&format!("Assembling stage{} compiler ({})", stage, host));
953956

@@ -963,6 +966,16 @@ impl Step for Assemble {
963966
}
964967
}
965968

969+
if stage == 1 {
970+
// Copy the dynamic libraries from the bootstrap compiler
971+
// which are needed to run the stage1 compiler
972+
copy_libs_from_bootstrap(
973+
builder,
974+
build_compiler,
975+
&sysroot_libdir,
976+
&["std", "test", "term"]);
977+
}
978+
966979
copy_codegen_backends_to_sysroot(builder,
967980
build_compiler,
968981
target_compiler);
@@ -983,6 +996,37 @@ impl Step for Assemble {
983996
}
984997
}
985998

999+
fn copy_libs_from_bootstrap(
1000+
builder: &Builder,
1001+
compiler: Compiler,
1002+
out_dir: &Path,
1003+
libs: &[&str])
1004+
{
1005+
if builder.config.dry_run {
1006+
return;
1007+
}
1008+
1009+
let base_libdir = builder.config
1010+
.initial_rustc.parent().unwrap()
1011+
.parent().unwrap()
1012+
.join("lib").join("rustlib").join(compiler.host).join("lib");
1013+
t!(fs::create_dir_all(&out_dir));
1014+
let mut files: Vec<PathBuf> = Vec::new();
1015+
for f in t!(fs::read_dir(&base_libdir)).map(|f| t!(f)) {
1016+
let filename = f.file_name().into_string().unwrap();
1017+
let should_copy = is_dylib(&filename) && libs.iter().any(|lib| {
1018+
filename.starts_with(&format!("{}-", lib)) ||
1019+
filename.starts_with(&format!("lib{}-", lib))
1020+
});
1021+
if !should_copy {
1022+
continue;
1023+
}
1024+
let dest = &out_dir.join(filename);
1025+
builder.copy(&f.path(), &dest);
1026+
files.push(dest.into());
1027+
}
1028+
}
1029+
9861030
/// Link some files into a rustc sysroot.
9871031
///
9881032
/// For a particular stage this will link the file listed in `stamp` into the
@@ -1122,6 +1166,11 @@ pub fn run_cargo(builder: &Builder, cargo: &mut Command, stamp: &Path, is_check:
11221166
deps.push(path_to_add.into());
11231167
}
11241168

1169+
update_stamp_file(builder, stamp, deps)
1170+
}
1171+
1172+
pub fn update_stamp_file(builder: &Builder, stamp: &Path, mut deps: Vec<PathBuf>) -> Vec<PathBuf>
1173+
{
11251174
// Now we want to update the contents of the stamp file, if necessary. First
11261175
// we read off the previous contents along with its mtime. If our new
11271176
// contents (the list of files to copy) is different or if any dep's mtime

src/bootstrap/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ impl Config {
364364
config.src = Config::path_from_python("SRC");
365365
config.out = Config::path_from_python("BUILD_DIR");
366366

367-
let stage0_root = config.out.join(&config.build).join("stage0/bin");
367+
let stage0_root = config.out.join("base").join(&config.build).join("bin");
368368
config.initial_rustc = stage0_root.join(exe("rustc", &config.build));
369369
config.initial_cargo = stage0_root.join(exe("cargo", &config.build));
370370

0 commit comments

Comments
 (0)