Skip to content

Commit 8e0007f

Browse files
committed
Auto merge of #65474 - Mark-Simulacrum:rustc-dev-split, r=pietroalbini
Split the rustc target libraries into separate rustc-dev component This is re-applies a squashed version of #64823 as well as including #65337 to fix bugs noted after merging the first PR. The second PR is confirmed as fixing windows-gnu, and presumably also fixes other platforms, such as musl (i.e. #65335 should be fixed); `RUSTUP_DIST_SERVER=https://dev-static.rust-lang.org rustup toolchain install nightly-2019-10-16` can be installed to confirm that this is indeed the case.
2 parents 55e0063 + 7ccf492 commit 8e0007f

File tree

6 files changed

+173
-55
lines changed

6 files changed

+173
-55
lines changed

src/bootstrap/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ impl<'a> Builder<'a> {
443443
dist::Rustc,
444444
dist::DebuggerScripts,
445445
dist::Std,
446+
dist::RustcDev,
446447
dist::Analysis,
447448
dist::Src,
448449
dist::PlainSourceTarball,

src/bootstrap/check.rs

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ impl Step for Std {
5555
cargo,
5656
args(builder.kind),
5757
&libstd_stamp(builder, compiler, target),
58+
vec![],
5859
true);
5960

6061
let libdir = builder.sysroot_libdir(compiler, target);
@@ -103,6 +104,7 @@ impl Step for Rustc {
103104
cargo,
104105
args(builder.kind),
105106
&librustc_stamp(builder, compiler, target),
107+
vec![],
106108
true);
107109

108110
let libdir = builder.sysroot_libdir(compiler, target);
@@ -155,6 +157,7 @@ impl Step for CodegenBackend {
155157
cargo,
156158
args(builder.kind),
157159
&codegen_backend_stamp(builder, compiler, target, backend),
160+
vec![],
158161
true);
159162
}
160163
}
@@ -199,6 +202,7 @@ impl Step for Rustdoc {
199202
cargo,
200203
args(builder.kind),
201204
&rustdoc_stamp(builder, compiler, target),
205+
vec![],
202206
true);
203207

204208
let libdir = builder.sysroot_libdir(compiler, target);

src/bootstrap/compile.rs

+41-22
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl Step for Std {
6969
return;
7070
}
7171

72-
builder.ensure(StartupObjects { compiler, target });
72+
let mut target_deps = builder.ensure(StartupObjects { compiler, target });
7373

7474
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
7575
if compiler_to_use != compiler {
@@ -91,7 +91,7 @@ impl Step for Std {
9191
return;
9292
}
9393

94-
copy_third_party_objects(builder, &compiler, target);
94+
target_deps.extend(copy_third_party_objects(builder, &compiler, target).into_iter());
9595

9696
let mut cargo = builder.cargo(compiler, Mode::Std, target, "build");
9797
std_cargo(builder, &compiler, target, &mut cargo);
@@ -102,6 +102,7 @@ impl Step for Std {
102102
cargo,
103103
vec![],
104104
&libstd_stamp(builder, compiler, target),
105+
target_deps,
105106
false);
106107

107108
builder.ensure(StdLink {
@@ -113,29 +114,36 @@ impl Step for Std {
113114
}
114115

115116
/// Copies third pary objects needed by various targets.
116-
fn copy_third_party_objects(builder: &Builder<'_>, compiler: &Compiler, target: Interned<String>) {
117+
fn copy_third_party_objects(builder: &Builder<'_>, compiler: &Compiler, target: Interned<String>)
118+
-> Vec<PathBuf>
119+
{
117120
let libdir = builder.sysroot_libdir(*compiler, target);
118121

122+
let mut target_deps = vec![];
123+
124+
let mut copy_and_stamp = |sourcedir: &Path, name: &str| {
125+
let target = libdir.join(name);
126+
builder.copy(
127+
&sourcedir.join(name),
128+
&target,
129+
);
130+
target_deps.push(target);
131+
};
132+
119133
// Copies the crt(1,i,n).o startup objects
120134
//
121135
// Since musl supports fully static linking, we can cross link for it even
122136
// with a glibc-targeting toolchain, given we have the appropriate startup
123137
// files. As those shipped with glibc won't work, copy the ones provided by
124138
// musl so we have them on linux-gnu hosts.
125139
if target.contains("musl") {
140+
let srcdir = builder.musl_root(target).unwrap().join("lib");
126141
for &obj in &["crt1.o", "crti.o", "crtn.o"] {
127-
builder.copy(
128-
&builder.musl_root(target).unwrap().join("lib").join(obj),
129-
&libdir.join(obj),
130-
);
142+
copy_and_stamp(&srcdir, obj);
131143
}
132144
} else if target.ends_with("-wasi") {
133-
for &obj in &["crt1.o"] {
134-
builder.copy(
135-
&builder.wasi_root(target).unwrap().join("lib/wasm32-wasi").join(obj),
136-
&libdir.join(obj),
137-
);
138-
}
145+
let srcdir = builder.wasi_root(target).unwrap().join("lib/wasm32-wasi");
146+
copy_and_stamp(&srcdir, "crt1.o");
139147
}
140148

141149
// Copies libunwind.a compiled to be linked wit x86_64-fortanix-unknown-sgx.
@@ -145,11 +153,11 @@ fn copy_third_party_objects(builder: &Builder<'_>, compiler: &Compiler, target:
145153
// which is provided by std for this target.
146154
if target == "x86_64-fortanix-unknown-sgx" {
147155
let src_path_env = "X86_FORTANIX_SGX_LIBS";
148-
let obj = "libunwind.a";
149156
let src = env::var(src_path_env).expect(&format!("{} not found in env", src_path_env));
150-
let src = Path::new(&src).join(obj);
151-
builder.copy(&src, &libdir.join(obj));
157+
copy_and_stamp(Path::new(&src), "libunwind.a");
152158
}
159+
160+
target_deps
153161
}
154162

155163
/// Configure cargo to compile the standard library, adding appropriate env vars
@@ -306,7 +314,7 @@ pub struct StartupObjects {
306314
}
307315

308316
impl Step for StartupObjects {
309-
type Output = ();
317+
type Output = Vec<PathBuf>;
310318

311319
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
312320
run.path("src/rtstartup")
@@ -325,13 +333,15 @@ impl Step for StartupObjects {
325333
/// They don't require any library support as they're just plain old object
326334
/// files, so we just use the nightly snapshot compiler to always build them (as
327335
/// no other compilers are guaranteed to be available).
328-
fn run(self, builder: &Builder<'_>) {
336+
fn run(self, builder: &Builder<'_>) -> Vec<PathBuf> {
329337
let for_compiler = self.compiler;
330338
let target = self.target;
331339
if !target.contains("windows-gnu") {
332-
return
340+
return vec![]
333341
}
334342

343+
let mut target_deps = vec![];
344+
335345
let src_dir = &builder.src.join("src/rtstartup");
336346
let dst_dir = &builder.native_dir(target).join("rtstartup");
337347
let sysroot_dir = &builder.sysroot_libdir(for_compiler, target);
@@ -350,16 +360,22 @@ impl Step for StartupObjects {
350360
.arg(src_file));
351361
}
352362

353-
builder.copy(dst_file, &sysroot_dir.join(file.to_string() + ".o"));
363+
let target = sysroot_dir.join(file.to_string() + ".o");
364+
builder.copy(dst_file, &target);
365+
target_deps.push(target);
354366
}
355367

356368
for obj in ["crt2.o", "dllcrt2.o"].iter() {
357369
let src = compiler_file(builder,
358370
builder.cc(target),
359371
target,
360372
obj);
361-
builder.copy(&src, &sysroot_dir.join(obj));
373+
let target = sysroot_dir.join(obj);
374+
builder.copy(&src, &target);
375+
target_deps.push(target);
362376
}
377+
378+
target_deps
363379
}
364380
}
365381

@@ -437,6 +453,7 @@ impl Step for Rustc {
437453
cargo,
438454
vec![],
439455
&librustc_stamp(builder, compiler, target),
456+
vec![],
440457
false);
441458

442459
builder.ensure(RustcLink {
@@ -585,7 +602,7 @@ impl Step for CodegenBackend {
585602

586603
let tmp_stamp = out_dir.join(".tmp.stamp");
587604

588-
let files = run_cargo(builder, cargo, vec![], &tmp_stamp, false);
605+
let files = run_cargo(builder, cargo, vec![], &tmp_stamp, vec![], false);
589606
if builder.config.dry_run {
590607
return;
591608
}
@@ -941,6 +958,7 @@ pub fn run_cargo(builder: &Builder<'_>,
941958
cargo: Cargo,
942959
tail_args: Vec<String>,
943960
stamp: &Path,
961+
additional_target_deps: Vec<PathBuf>,
944962
is_check: bool)
945963
-> Vec<PathBuf>
946964
{
@@ -1057,6 +1075,7 @@ pub fn run_cargo(builder: &Builder<'_>,
10571075
deps.push((path_to_add.into(), false));
10581076
}
10591077

1078+
deps.extend(additional_target_deps.into_iter().map(|d| (d, false)));
10601079
deps.sort();
10611080
let mut new_contents = Vec::new();
10621081
for (dep, proc_macro) in deps.iter() {

src/bootstrap/dist.rs

+96-33
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,28 @@ impl Step for DebuggerScripts {
637637
}
638638
}
639639

640+
fn skip_host_target_lib(builder: &Builder<'_>, compiler: Compiler) -> bool {
641+
// The only true set of target libraries came from the build triple, so
642+
// let's reduce redundant work by only producing archives from that host.
643+
if compiler.host != builder.config.build {
644+
builder.info("\tskipping, not a build host");
645+
true
646+
} else {
647+
false
648+
}
649+
}
650+
651+
/// Copy stamped files into an image's `target/lib` directory.
652+
fn copy_target_libs(builder: &Builder<'_>, target: &str, image: &Path, stamp: &Path) {
653+
let dst = image.join("lib/rustlib").join(target).join("lib");
654+
t!(fs::create_dir_all(&dst));
655+
for (path, host) in builder.read_stamp_file(stamp) {
656+
if !host || builder.config.build == target {
657+
builder.copy(&path, &dst.join(path.file_name().unwrap()));
658+
}
659+
}
660+
}
661+
640662
#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
641663
pub struct Std {
642664
pub compiler: Compiler,
@@ -667,44 +689,19 @@ impl Step for Std {
667689
let target = self.target;
668690

669691
let name = pkgname(builder, "rust-std");
670-
671-
// The only true set of target libraries came from the build triple, so
672-
// let's reduce redundant work by only producing archives from that host.
673-
if compiler.host != builder.config.build {
674-
builder.info("\tskipping, not a build host");
675-
return distdir(builder).join(format!("{}-{}.tar.gz", name, target));
692+
let archive = distdir(builder).join(format!("{}-{}.tar.gz", name, target));
693+
if skip_host_target_lib(builder, compiler) {
694+
return archive;
676695
}
677696

678-
// We want to package up as many target libraries as possible
679-
// for the `rust-std` package, so if this is a host target we
680-
// depend on librustc and otherwise we just depend on libtest.
681-
if builder.hosts.iter().any(|t| t == target) {
682-
builder.ensure(compile::Rustc { compiler, target });
683-
} else {
684-
builder.ensure(compile::Std { compiler, target });
685-
}
697+
builder.ensure(compile::Std { compiler, target });
686698

687699
let image = tmpdir(builder).join(format!("{}-{}-image", name, target));
688700
let _ = fs::remove_dir_all(&image);
689701

690-
let dst = image.join("lib/rustlib").join(target);
691-
t!(fs::create_dir_all(&dst));
692-
let mut src = builder.sysroot_libdir(compiler, target).to_path_buf();
693-
src.pop(); // Remove the trailing /lib folder from the sysroot_libdir
694-
builder.cp_filtered(&src, &dst, &|path| {
695-
if let Some(name) = path.file_name().and_then(|s| s.to_str()) {
696-
if name == builder.config.rust_codegen_backends_dir.as_str() {
697-
return false
698-
}
699-
if name == "bin" {
700-
return false
701-
}
702-
if name.contains("LLVM") {
703-
return false
704-
}
705-
}
706-
true
707-
});
702+
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
703+
let stamp = compile::libstd_stamp(builder, compiler_to_use, target);
704+
copy_target_libs(builder, &target, &image, &stamp);
708705

709706
let mut cmd = rust_installer(builder);
710707
cmd.arg("generate")
@@ -723,7 +720,73 @@ impl Step for Std {
723720
let _time = timeit(builder);
724721
builder.run(&mut cmd);
725722
builder.remove_dir(&image);
726-
distdir(builder).join(format!("{}-{}.tar.gz", name, target))
723+
archive
724+
}
725+
}
726+
727+
#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
728+
pub struct RustcDev {
729+
pub compiler: Compiler,
730+
pub target: Interned<String>,
731+
}
732+
733+
impl Step for RustcDev {
734+
type Output = PathBuf;
735+
const DEFAULT: bool = true;
736+
const ONLY_HOSTS: bool = true;
737+
738+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
739+
run.path("rustc-dev")
740+
}
741+
742+
fn make_run(run: RunConfig<'_>) {
743+
run.builder.ensure(RustcDev {
744+
compiler: run.builder.compiler_for(
745+
run.builder.top_stage,
746+
run.builder.config.build,
747+
run.target,
748+
),
749+
target: run.target,
750+
});
751+
}
752+
753+
fn run(self, builder: &Builder<'_>) -> PathBuf {
754+
let compiler = self.compiler;
755+
let target = self.target;
756+
757+
let name = pkgname(builder, "rustc-dev");
758+
let archive = distdir(builder).join(format!("{}-{}.tar.gz", name, target));
759+
if skip_host_target_lib(builder, compiler) {
760+
return archive;
761+
}
762+
763+
builder.ensure(compile::Rustc { compiler, target });
764+
765+
let image = tmpdir(builder).join(format!("{}-{}-image", name, target));
766+
let _ = fs::remove_dir_all(&image);
767+
768+
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
769+
let stamp = compile::librustc_stamp(builder, compiler_to_use, target);
770+
copy_target_libs(builder, &target, &image, &stamp);
771+
772+
let mut cmd = rust_installer(builder);
773+
cmd.arg("generate")
774+
.arg("--product-name=Rust")
775+
.arg("--rel-manifest-dir=rustlib")
776+
.arg("--success-message=Rust-is-ready-to-develop.")
777+
.arg("--image-dir").arg(&image)
778+
.arg("--work-dir").arg(&tmpdir(builder))
779+
.arg("--output-dir").arg(&distdir(builder))
780+
.arg(format!("--package-name={}-{}", name, target))
781+
.arg(format!("--component-name=rustc-dev-{}", target))
782+
.arg("--legacy-manifest-dirs=rustlib,cargo");
783+
784+
builder.info(&format!("Dist rustc-dev stage{} ({} -> {})",
785+
compiler.stage, &compiler.host, target));
786+
let _time = timeit(builder);
787+
builder.run(&mut cmd);
788+
builder.remove_dir(&image);
789+
archive
727790
}
728791
}
729792

src/bootstrap/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,7 @@ impl Build {
11371137
pub fn copy(&self, src: &Path, dst: &Path) {
11381138
if self.config.dry_run { return; }
11391139
self.verbose_than(1, &format!("Copy {:?} to {:?}", src, dst));
1140+
if src == dst { return; }
11401141
let _ = fs::remove_file(&dst);
11411142
let metadata = t!(src.symlink_metadata());
11421143
if metadata.file_type().is_symlink() {

0 commit comments

Comments
 (0)