From d923d87c0117da3a9c00d7c6e29aeea2d497495e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 4 Sep 2024 11:22:43 +0200 Subject: [PATCH] Do not include `libstd.so` in sysroot when we statically link to libstd --- src/bootstrap/src/bin/rustc.rs | 1 - src/bootstrap/src/core/build_steps/compile.rs | 12 ++++++++++-- src/ci/github-actions/jobs.yml | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/bootstrap/src/bin/rustc.rs b/src/bootstrap/src/bin/rustc.rs index d04e2fbeb7853..780979ed98121 100644 --- a/src/bootstrap/src/bin/rustc.rs +++ b/src/bootstrap/src/bin/rustc.rs @@ -95,7 +95,6 @@ fn main() { // When statically linking `std` into `rustc_driver`, remove `-C prefer-dynamic` if env::var("RUSTC_LINK_STD_INTO_RUSTC_DRIVER").unwrap() == "1" && crate_name == Some("rustc_driver") - && stage != "0" { if let Some(pos) = args.iter().enumerate().position(|(i, a)| { a == "-C" && args.get(i + 1).map(|a| a == "prefer-dynamic").unwrap_or(false) diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 1936c91ef83c1..7ba827b8e70e1 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -1876,8 +1876,16 @@ impl Step for Assemble { let src_libdir = builder.sysroot_libdir(build_compiler, host); for f in builder.read_dir(&src_libdir) { let filename = f.file_name().into_string().unwrap(); - if (is_dylib(&filename) || is_debug_info(&filename)) && !proc_macros.contains(&filename) - { + + let is_proc_macro = proc_macros.contains(&filename); + let is_dylib_or_debug = is_dylib(&filename) || is_debug_info(&filename); + + // If we link statically to stdlib, do not copy the libstd dynamic library file + let is_std = filename.starts_with("std-") || filename.starts_with("libstd-"); + let can_be_rustc_dynamic_dep = + !(is_std && builder.link_std_into_rustc_driver(target_compiler.host)); + + if is_dylib_or_debug && can_be_rustc_dynamic_dep && !is_proc_macro { builder.copy_link(&f.path(), &rustc_libdir.join(&filename)); } } diff --git a/src/ci/github-actions/jobs.yml b/src/ci/github-actions/jobs.yml index 4de44c6dd39d7..b6b9968dc7a20 100644 --- a/src/ci/github-actions/jobs.yml +++ b/src/ci/github-actions/jobs.yml @@ -68,7 +68,7 @@ envs: # - not running `opt-dist`'s post-optimization smoke tests on the resulting toolchain # # If you *want* these to happen however, temporarily uncomment it before triggering a try build. - DIST_TRY_BUILD: 1 + # DIST_TRY_BUILD: 1 auto: <<: *production