Skip to content

Commit 3a05616

Browse files
cuviperMark-Simulacrum
authored andcommitted
minimize the rust-std component
This splits out a rustc-dev component with the compiler crates, and keeps the status quo of default installed files on nightly. The default changing to not install compiler libraries by default is left for a future pull request. However, on stable and beta, this does remove the compiler libraries from the set of libraries installed by default, as they are never needed there (per our stability story, they "cannot" be used).
1 parent 446e5e5 commit 3a05616

File tree

3 files changed

+112
-33
lines changed

3 files changed

+112
-33
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/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/tools/build-manifest/src/main.rs

+15
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ impl Builder {
399399
fn add_packages_to(&mut self, manifest: &mut Manifest) {
400400
let mut package = |name, targets| self.package(name, &mut manifest.pkg, targets);
401401
package("rustc", HOSTS);
402+
package("rustc-dev", HOSTS);
402403
package("cargo", HOSTS);
403404
package("rust-mingw", MINGW);
404405
package("rust-std", TARGETS);
@@ -481,6 +482,15 @@ impl Builder {
481482
components.push(host_component("rust-mingw"));
482483
}
483484

485+
// The compiler libraries are not stable for end users, but `rustc-dev` was only recently
486+
// split out of `rust-std`. We'll include it by default as a transition for nightly users,
487+
// but ship it as an optional component on the beta and stable channels.
488+
if self.rust_release == "nightly" {
489+
components.push(host_component("rustc-dev"));
490+
} else {
491+
extensions.push(host_component("rustc-dev"));
492+
}
493+
484494
// Tools are always present in the manifest,
485495
// but might be marked as unavailable if they weren't built.
486496
extensions.extend(vec![
@@ -498,6 +508,11 @@ impl Builder {
498508
.filter(|&&target| target != host)
499509
.map(|target| Component::from_str("rust-std", target))
500510
);
511+
extensions.extend(
512+
HOSTS.iter()
513+
.filter(|&&target| target != host)
514+
.map(|target| Component::from_str("rustc-dev", target))
515+
);
501516
extensions.push(Component::from_str("rust-src", "*"));
502517

503518
// If the components/extensions don't actually exist for this

0 commit comments

Comments
 (0)