Skip to content

Commit fe6f3fa

Browse files
committed
improve the way bootstrap handles rustlib components
When CI rustc is enabled, bootstrap tries to symlink the rust source (project root) into target sysroot right before copying it from the CI rustc's sysroot. This becomes a problem in CI builders (which we currently don't see because they don't use CI rustc) because the copying part will fail as they run on read-only mode. This change fixes the problem by copying `rustc-src` from the CI rustc sysroot and only symlinking `rustc-src` from the rust source when download-rustc is not enabled. Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent 7b21c18 commit fe6f3fa

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/bootstrap/src/core/build_steps/compile.rs

+26-26
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,10 @@ impl Step for Std {
161161
// This check is specific to testing std itself; see `test::Std` for more details.
162162
&& !self.force_recompile
163163
{
164+
let sysroot = builder.ensure(Sysroot { compiler, force_recompile: false });
164165
cp_rustc_component_to_ci_sysroot(
165166
builder,
166-
compiler,
167+
&sysroot,
167168
builder.config.ci_rust_std_contents(),
168169
);
169170
return;
@@ -797,12 +798,7 @@ impl Step for StartupObjects {
797798
}
798799
}
799800

800-
fn cp_rustc_component_to_ci_sysroot(
801-
builder: &Builder<'_>,
802-
compiler: Compiler,
803-
contents: Vec<String>,
804-
) {
805-
let sysroot = builder.ensure(Sysroot { compiler, force_recompile: false });
801+
fn cp_rustc_component_to_ci_sysroot(builder: &Builder<'_>, sysroot: &Path, contents: Vec<String>) {
806802
let ci_rustc_dir = builder.config.ci_rustc_dir();
807803

808804
for file in contents {
@@ -881,13 +877,7 @@ impl Step for Rustc {
881877
// NOTE: the ABI of the beta compiler is different from the ABI of the downloaded compiler,
882878
// so its artifacts can't be reused.
883879
if builder.download_rustc() && compiler.stage != 0 {
884-
// Copy the existing artifacts instead of rebuilding them.
885-
// NOTE: this path is only taken for tools linking to rustc-dev (including ui-fulldeps tests).
886-
cp_rustc_component_to_ci_sysroot(
887-
builder,
888-
compiler,
889-
builder.config.ci_rustc_dev_contents(),
890-
);
880+
builder.ensure(Sysroot { compiler, force_recompile: false });
891881
return compiler.stage;
892882
}
893883

@@ -1646,19 +1636,29 @@ impl Step for Sysroot {
16461636
);
16471637
}
16481638
}
1649-
// Same for the rustc-src component.
1650-
let sysroot_lib_rustlib_rustcsrc = sysroot.join("lib/rustlib/rustc-src");
1651-
t!(fs::create_dir_all(&sysroot_lib_rustlib_rustcsrc));
1652-
let sysroot_lib_rustlib_rustcsrc_rust = sysroot_lib_rustlib_rustcsrc.join("rust");
1653-
if let Err(e) =
1654-
symlink_dir(&builder.config, &builder.src, &sysroot_lib_rustlib_rustcsrc_rust)
1655-
{
1656-
eprintln!(
1657-
"WARNING: creating symbolic link `{}` to `{}` failed with {}",
1658-
sysroot_lib_rustlib_rustcsrc_rust.display(),
1659-
builder.src.display(),
1660-
e,
1639+
1640+
// Unlike rust-src component, we have to handle rustc-src a bit differently.
1641+
// When using CI rustc, we copy rustc-src component from its sysroot,
1642+
// otherwise we handle it in a similar way what we do for rust-src above.
1643+
if builder.download_rustc() {
1644+
cp_rustc_component_to_ci_sysroot(
1645+
builder,
1646+
&sysroot,
1647+
builder.config.ci_rustc_dev_contents(),
16611648
);
1649+
} else {
1650+
let sysroot_lib_rustlib_rustcsrc = sysroot.join("lib/rustlib/rustc-src");
1651+
t!(fs::create_dir_all(&sysroot_lib_rustlib_rustcsrc));
1652+
let sysroot_lib_rustlib_rustcsrc_rust = sysroot_lib_rustlib_rustcsrc.join("rust");
1653+
if let Err(e) =
1654+
symlink_dir(&builder.config, &builder.src, &sysroot_lib_rustlib_rustcsrc_rust)
1655+
{
1656+
eprintln!(
1657+
"WARNING: creating symbolic link `{}` to `{}` failed with {}",
1658+
sysroot_lib_rustlib_rustcsrc_rust.display(),
1659+
builder.src.display(),
1660+
e,
1661+
);
16621662
}
16631663

16641664
sysroot

0 commit comments

Comments
 (0)