From f4805b45e94ed7b5d64bd1ad4198f89f32ff8de8 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Sun, 30 Jun 2024 10:55:51 +0300 Subject: [PATCH 1/2] abstract rustlib source copying logic from `dist` Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/dist.rs | 56 +++++++++++----------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index 08795efe5bb4c..21fd08ea370a7 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -711,16 +711,8 @@ impl Step for RustcDev { let stamp = compile::librustc_stamp(builder, compiler_to_use, target); copy_target_libs(builder, target, tarball.image_dir(), &stamp); + copy_rustlib_rustc_src(builder, &tarball.image_dir().join("lib/rustlib/rustc-src/rust")); let src_files = &["Cargo.lock"]; - // This is the reduced set of paths which will become the rustc-dev component - // (essentially the compiler crates and all of their path dependencies). - copy_src_dirs( - builder, - &builder.src, - &["compiler"], - &[], - &tarball.image_dir().join("lib/rustlib/rustc-src/rust"), - ); for file in src_files { tarball.add_file(builder.src.join(file), "lib/rustlib/rustc-src/rust", 0o644); } @@ -787,6 +779,33 @@ impl Step for Analysis { } } +pub fn copy_rustlib_rustc_src(builder: &Builder<'_>, dst: &Path) { + // This is the reduced set of paths which will become the rustc-dev component + // (essentially the compiler crates and all of their path dependencies). + copy_src_dirs(builder, &builder.src, &["compiler"], &[], dst); +} + +pub fn copy_rustlib_src(builder: &Builder<'_>, dst: &Path) { + // This is the reduced set of paths which will become the rust-src component + // (essentially libstd and all of its path dependencies). + copy_src_dirs( + builder, + &builder.src, + &["library", "src/llvm-project/libunwind"], + &[ + // not needed and contains symlinks which rustup currently + // chokes on when unpacking. + "library/backtrace/crates", + // these are 30MB combined and aren't necessary for building + // the standard library. + "library/stdarch/Cargo.toml", + "library/stdarch/crates/stdarch-verify", + "library/stdarch/crates/intrinsic-test", + ], + dst, + ); +} + /// Use the `builder` to make a filtered copy of `base`/X for X in (`src_dirs` - `exclude_dirs`) to /// `dst_dir`. fn copy_src_dirs( @@ -918,24 +937,7 @@ impl Step for Src { let dst_src = tarball.image_dir().join("lib/rustlib/src/rust"); let src_files = ["Cargo.lock"]; - // This is the reduced set of paths which will become the rust-src component - // (essentially libstd and all of its path dependencies). - copy_src_dirs( - builder, - &builder.src, - &["library", "src/llvm-project/libunwind"], - &[ - // not needed and contains symlinks which rustup currently - // chokes on when unpacking. - "library/backtrace/crates", - // these are 30MB combined and aren't necessary for building - // the standard library. - "library/stdarch/Cargo.toml", - "library/stdarch/crates/stdarch-verify", - "library/stdarch/crates/intrinsic-test", - ], - &dst_src, - ); + copy_rustlib_src(builder, &dst_src); for file in src_files.iter() { builder.copy_link(&builder.src.join(file), &dst_src.join(file)); } From c4c4d686242fd9b5d0f989faa2d136b354ff4add Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Sun, 30 Jun 2024 10:56:33 +0300 Subject: [PATCH 2/2] copy rustlib sources instead of using symbolic links There are certain cases where we need to add things to the rustlib source paths in CI builders. When the rustlib sources are symbolically linked to `/checkout`, we can't make any modifications because `/checkout` is mounted as read-only in containers. This change updates the bootstrap to copy the rustlib directories instead of linking them, so we can put/link things into rustlib directories when needed. Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/compile.rs | 40 ++++--------------- 1 file changed, 7 insertions(+), 33 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index a6172589dbb0f..1a03238b0ee9f 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -29,7 +29,7 @@ use crate::core::builder::{Builder, Kind, PathSet, RunConfig, ShouldRun, Step, T use crate::core::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection}; use crate::utils::exec::BootstrapCommand; use crate::utils::helpers::{ - exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, output, symlink_dir, t, up_to_date, + exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, output, t, up_to_date, }; use crate::LLVM_TOOLS; use crate::{CLang, Compiler, DependencyType, GitRepo, Mode}; @@ -1624,42 +1624,16 @@ impl Step for Sysroot { }); } - // Symlink the source root into the same location inside the sysroot, + // Copy the source root into the same location inside the sysroot, // where `rust-src` component would go (`$sysroot/lib/rustlib/src/rust`), // so that any tools relying on `rust-src` also work for local builds, // and also for translating the virtual `/rustc/$hash` back to the real // directory (for running tests with `rust.remap-debuginfo = true`). - let sysroot_lib_rustlib_src = sysroot.join("lib/rustlib/src"); - t!(fs::create_dir_all(&sysroot_lib_rustlib_src)); - let sysroot_lib_rustlib_src_rust = sysroot_lib_rustlib_src.join("rust"); - if let Err(e) = symlink_dir(&builder.config, &builder.src, &sysroot_lib_rustlib_src_rust) { - eprintln!( - "WARNING: creating symbolic link `{}` to `{}` failed with {}", - sysroot_lib_rustlib_src_rust.display(), - builder.src.display(), - e, - ); - if builder.config.rust_remap_debuginfo { - eprintln!( - "WARNING: some `tests/ui` tests will fail when lacking `{}`", - sysroot_lib_rustlib_src_rust.display(), - ); - } - } - // Same for the rustc-src component. - let sysroot_lib_rustlib_rustcsrc = sysroot.join("lib/rustlib/rustc-src"); - t!(fs::create_dir_all(&sysroot_lib_rustlib_rustcsrc)); - let sysroot_lib_rustlib_rustcsrc_rust = sysroot_lib_rustlib_rustcsrc.join("rust"); - if let Err(e) = - symlink_dir(&builder.config, &builder.src, &sysroot_lib_rustlib_rustcsrc_rust) - { - eprintln!( - "WARNING: creating symbolic link `{}` to `{}` failed with {}", - sysroot_lib_rustlib_rustcsrc_rust.display(), - builder.src.display(), - e, - ); - } + let rustlib_src_rust = sysroot.join("lib/rustlib/src/rust"); + dist::copy_rustlib_src(builder, &rustlib_src_rust); + + let rustlib_rustcsrc_rust = sysroot.join("lib/rustlib/rustc-src/rust"); + dist::copy_rustlib_rustc_src(builder, &rustlib_rustcsrc_rust); sysroot }