1
Fork 0

Do not include libstd.so in sysroot when we statically link to libstd

This commit is contained in:
Jakub Beránek 2024-09-04 11:22:43 +02:00
parent fd1f8aa05d
commit 2cf155924f
No known key found for this signature in database
GPG key ID: 909CD0D26483516B
2 changed files with 17 additions and 2 deletions

View file

@ -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)

View file

@ -1923,8 +1923,24 @@ 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
// Currently, we do not avoid the copy on Windows, as it seems to be causing issues in
// post-optimization stage0 tests.
let can_be_rustc_dynamic_dep = if builder
.link_std_into_rustc_driver(target_compiler.host)
&& !target_compiler.host.is_windows()
{
let is_std = filename.starts_with("std-") || filename.starts_with("libstd-");
!is_std
} else {
true
};
if is_dylib_or_debug && can_be_rustc_dynamic_dep && !is_proc_macro {
builder.copy_link(&f.path(), &rustc_libdir.join(&filename));
}
}