Skip to content

copy rustlib sources instead of using symbolic links #127151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 7 additions & 33 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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`).
Comment on lines 1630 to 1631
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this is going to change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future note for worst-case scenario: We can make this to use copying for CI environments and create symbolic links for non-CI environments.

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
}
Expand Down
56 changes: 29 additions & 27 deletions src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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));
}
Expand Down
Loading