Skip to content

Commit 2d8fd57

Browse files
author
Ariel Ben-Yehuda
authored
Rollup merge of rust-lang#41546 - cuviper:reduced-rust-src, r=alexcrichton
Shrink the rust-src component Before this change, the installable rust-src component had essentially the same contents as the rustc-src dist tarball, just additionally wrapped in a rust-installer. As discussed on [internals], rust-src is only meant to support uses for the standard library, so it doesn't really need the rest of the compiler sources. Now rust-src only contains libstd and its path dependencies, which roughly matches the set of crates that have rust-analysis data. The result is **significantly** smaller, from 36MB to 1.3MB compressed, and from 247MB to 8.5MB uncompressed. [internals]: https://internals.rust-lang.org/t/minimizing-the-rust-src-component/5117
2 parents 14d4aa9 + b9bdb17 commit 2d8fd57

File tree

1 file changed

+61
-27
lines changed

1 file changed

+61
-27
lines changed

src/bootstrap/dist.rs

+61-27
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,11 @@ pub fn rust_src(build: &Build) {
374374

375375
println!("Dist src");
376376

377-
let name = pkgname(build, "rust-src");
378-
let image = tmpdir(build).join(format!("{}-image", name));
379-
let _ = fs::remove_dir_all(&image);
380-
381-
let dst = image.join("lib/rustlib/src");
382-
let dst_src = dst.join("rust");
383-
t!(fs::create_dir_all(&dst_src));
377+
// Make sure that the root folder of tarball has the correct name
378+
let plain_name = format!("rustc-{}-src", build.rust_package_vers());
379+
let plain_dst_src = tmpdir(build).join(&plain_name);
380+
let _ = fs::remove_dir_all(&plain_dst_src);
381+
t!(fs::create_dir_all(&plain_dst_src));
384382

385383
// This is the set of root paths which will become part of the source package
386384
let src_files = [
@@ -429,13 +427,13 @@ pub fn rust_src(build: &Build) {
429427

430428
// Copy the directories using our filter
431429
for item in &src_dirs {
432-
let dst = &dst_src.join(item);
430+
let dst = &plain_dst_src.join(item);
433431
t!(fs::create_dir(dst));
434432
cp_filtered(&build.src.join(item), dst, &filter_fn);
435433
}
436434
// Copy the files normally
437435
for item in &src_files {
438-
copy(&build.src.join(item), &dst_src.join(item));
436+
copy(&build.src.join(item), &plain_dst_src.join(item));
439437
}
440438

441439
// If we're building from git sources, we need to vendor a complete distribution.
@@ -460,10 +458,63 @@ pub fn rust_src(build: &Build) {
460458
// Vendor all Cargo dependencies
461459
let mut cmd = Command::new(&build.cargo);
462460
cmd.arg("vendor")
463-
.current_dir(&dst_src.join("src"));
461+
.current_dir(&plain_dst_src.join("src"));
464462
build.run(&mut cmd);
465463
}
466464

465+
// Create the version file
466+
write_file(&plain_dst_src.join("version"), build.rust_version().as_bytes());
467+
468+
// Create plain source tarball
469+
let tarball = rust_src_location(build);
470+
if let Some(dir) = tarball.parent() {
471+
t!(fs::create_dir_all(dir));
472+
}
473+
let mut cmd = Command::new("tar");
474+
cmd.arg("-czf").arg(sanitize_sh(&tarball))
475+
.arg(&plain_name)
476+
.current_dir(tmpdir(build));
477+
build.run(&mut cmd);
478+
479+
480+
let name = pkgname(build, "rust-src");
481+
let image = tmpdir(build).join(format!("{}-image", name));
482+
let _ = fs::remove_dir_all(&image);
483+
484+
let dst = image.join("lib/rustlib/src");
485+
let dst_src = dst.join("rust");
486+
t!(fs::create_dir_all(&dst_src));
487+
488+
// This is the reduced set of paths which will become the rust-src component
489+
// (essentially libstd and all of its path dependencies)
490+
let std_src_dirs = [
491+
"src/build_helper",
492+
"src/liballoc",
493+
"src/liballoc_jemalloc",
494+
"src/liballoc_system",
495+
"src/libcollections",
496+
"src/libcompiler_builtins",
497+
"src/libcore",
498+
"src/liblibc",
499+
"src/libpanic_abort",
500+
"src/libpanic_unwind",
501+
"src/librand",
502+
"src/librustc_asan",
503+
"src/librustc_lsan",
504+
"src/librustc_msan",
505+
"src/librustc_tsan",
506+
"src/libstd",
507+
"src/libstd_unicode",
508+
"src/libunwind",
509+
"src/rustc/libc_shim",
510+
];
511+
512+
for item in &std_src_dirs {
513+
let dst = &dst_src.join(item);
514+
t!(fs::create_dir_all(dst));
515+
cp_r(&plain_dst_src.join(item), dst);
516+
}
517+
467518
// Create source tarball in rust-installer format
468519
let mut cmd = Command::new(SH_CMD);
469520
cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh")))
@@ -478,23 +529,6 @@ pub fn rust_src(build: &Build) {
478529
.arg("--legacy-manifest-dirs=rustlib,cargo");
479530
build.run(&mut cmd);
480531

481-
// Rename directory, so that root folder of tarball has the correct name
482-
let plain_name = format!("rustc-{}-src", build.rust_package_vers());
483-
let plain_dst_src = tmpdir(build).join(&plain_name);
484-
let _ = fs::remove_dir_all(&plain_dst_src);
485-
t!(fs::create_dir_all(&plain_dst_src));
486-
cp_r(&dst_src, &plain_dst_src);
487-
488-
// Create the version file
489-
write_file(&plain_dst_src.join("version"), build.rust_version().as_bytes());
490-
491-
// Create plain source tarball
492-
let mut cmd = Command::new("tar");
493-
cmd.arg("-czf").arg(sanitize_sh(&rust_src_location(build)))
494-
.arg(&plain_name)
495-
.current_dir(tmpdir(build));
496-
build.run(&mut cmd);
497-
498532
t!(fs::remove_dir_all(&image));
499533
t!(fs::remove_dir_all(&plain_dst_src));
500534
}

0 commit comments

Comments
 (0)