Skip to content

Commit 000d90b

Browse files
committed
Auto merge of #64823 - cuviper:min-std, r=Mark-Simulacrum
minimize the rust-std component This changes the `rust-std` dist component to only include the artifacts of compiling the `libstd` step, as listed in `.libstd.stamp`. This does include `test` and `proc-macro` as well. The remaining _unstable_ libraries that are built as part of `rustc` are packaged into a new `rustc-dev` component, intended for use in the development of closely related tools (clippy, miri, rls). Here are the component sizes from the [try build](https://dev-static.rust-lang.org/dist/2019-10-07/index.html): | Name | Size | --- | --- | rust-std-nightly-x86_64-unknown-linux-gnu.tar.gz | 23.94 MiB | rust-std-nightly-x86_64-unknown-linux-gnu.tar.xz | 17.4 MiB | rustc-dev-nightly-x86_64-unknown-linux-gnu.tar.gz | 182.03 MiB | rustc-dev-nightly-x86_64-unknown-linux-gnu.tar.xz | 157.91 MiB Fixes #61978 Fixes #62486
2 parents 898f36c + d305254 commit 000d90b

File tree

3 files changed

+127
-33
lines changed

3 files changed

+127
-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

+30
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);
@@ -426,6 +427,13 @@ impl Builder {
426427
"rls-preview", "rust-src", "llvm-tools-preview",
427428
"lldb-preview", "rust-analysis", "miri-preview"
428429
]);
430+
431+
// The compiler libraries are not stable for end users, but `rustc-dev` was only recently
432+
// split out of `rust-std`. We'll include it by default as a transition for nightly users.
433+
if self.rust_release == "nightly" {
434+
self.extend_profile("default", &mut manifest.profiles, &["rustc-dev"]);
435+
self.extend_profile("complete", &mut manifest.profiles, &["rustc-dev"]);
436+
}
429437
}
430438

431439
fn add_renames_to(&self, manifest: &mut Manifest) {
@@ -481,6 +489,15 @@ impl Builder {
481489
components.push(host_component("rust-mingw"));
482490
}
483491

492+
// The compiler libraries are not stable for end users, but `rustc-dev` was only recently
493+
// split out of `rust-std`. We'll include it by default as a transition for nightly users,
494+
// but ship it as an optional component on the beta and stable channels.
495+
if self.rust_release == "nightly" {
496+
components.push(host_component("rustc-dev"));
497+
} else {
498+
extensions.push(host_component("rustc-dev"));
499+
}
500+
484501
// Tools are always present in the manifest,
485502
// but might be marked as unavailable if they weren't built.
486503
extensions.extend(vec![
@@ -498,6 +515,11 @@ impl Builder {
498515
.filter(|&&target| target != host)
499516
.map(|target| Component::from_str("rust-std", target))
500517
);
518+
extensions.extend(
519+
HOSTS.iter()
520+
.filter(|&&target| target != host)
521+
.map(|target| Component::from_str("rustc-dev", target))
522+
);
501523
extensions.push(Component::from_str("rust-src", "*"));
502524

503525
// If the components/extensions don't actually exist for this
@@ -534,6 +556,14 @@ impl Builder {
534556
dst.insert(profile_name.to_owned(), pkgs.iter().map(|s| (*s).to_owned()).collect());
535557
}
536558

559+
fn extend_profile(&mut self,
560+
profile_name: &str,
561+
dst: &mut BTreeMap<String, Vec<String>>,
562+
pkgs: &[&str]) {
563+
dst.get_mut(profile_name).expect("existing profile")
564+
.extend(pkgs.iter().map(|s| (*s).to_owned()));
565+
}
566+
537567
fn package(&mut self,
538568
pkgname: &str,
539569
dst: &mut BTreeMap<String, Package>,

0 commit comments

Comments
 (0)