From efcf0fa9a1fa53d2586e4878bd670ffbbe77644e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Thu, 6 Aug 2026 11:21:43 +0200 Subject: [PATCH] Always statically link std into rustc_driver --- src/bootstrap/src/bin/rustc.rs | 6 ++---- src/bootstrap/src/core/build_steps/compile.rs | 9 ++------- src/bootstrap/src/core/builder/cargo.rs | 8 -------- src/bootstrap/src/core/builder/mod.rs | 6 ------ 4 files changed, 4 insertions(+), 25 deletions(-) diff --git a/src/bootstrap/src/bin/rustc.rs b/src/bootstrap/src/bin/rustc.rs index 427b03100b4a3..3d40e0a86c111 100644 --- a/src/bootstrap/src/bin/rustc.rs +++ b/src/bootstrap/src/bin/rustc.rs @@ -92,10 +92,8 @@ fn main() { // Get the name of the crate we're compiling, if any. let crate_name = parse_value_from_args(&orig_args, "--crate-name"); - // 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") - { + // When compiling `rustc_driver` remove `-C prefer-dynamic` to allow statically linking `std` into it + if crate_name == Some("rustc_driver") { 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 652e797538223..069855bd169ce 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -2349,14 +2349,9 @@ impl CommandLineStep for Assemble { let is_proc_macro = proc_macros.contains(&filename); let is_dylib_or_debug = is_dylib(&f.path()) || is_debug_info(&filename); - // If we link statically to stdlib, do not copy the libstd dynamic library file + // `rustc_driver` statically links to stdlib, so do not copy the libstd dynamic library file let can_be_rustc_dynamic_dep = - if builder.link_std_into_rustc_driver(target_compiler.host) { - let is_std = filename.starts_with("std-") || filename.starts_with("libstd-"); - !is_std - } else { - true - }; + !(filename.starts_with("std-") || filename.starts_with("libstd-")); if is_dylib_or_debug && can_be_rustc_dynamic_dep && !is_proc_macro { builder.copy_link(&f.path(), &rustc_libdir.join(&filename), FileType::Regular); diff --git a/src/bootstrap/src/core/builder/cargo.rs b/src/bootstrap/src/core/builder/cargo.rs index 3a1e4299b5475..a5e0c9afd7cb5 100644 --- a/src/bootstrap/src/core/builder/cargo.rs +++ b/src/bootstrap/src/core/builder/cargo.rs @@ -1435,14 +1435,6 @@ impl Builder<'_> { if matches!(mode, Mode::Std) { rustflags.arg("-Cprefer-dynamic"); } - if matches!(mode, Mode::Rustc) && !self.link_std_into_rustc_driver(target) { - rustflags.arg("-Cprefer-dynamic"); - } - - cargo.env( - "RUSTC_LINK_STD_INTO_RUSTC_DRIVER", - if self.link_std_into_rustc_driver(target) { "1" } else { "0" }, - ); // When building incrementally we default to a lower ThinLTO import limit // (unless explicitly specified otherwise). This will produce a somewhat diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs index 603ef65854cf6..aefee3f3e8e0f 100644 --- a/src/bootstrap/src/core/builder/mod.rs +++ b/src/bootstrap/src/core/builder/mod.rs @@ -1174,12 +1174,6 @@ impl<'a> Builder<'a> { cli_paths::match_paths_to_steps_and_run(self, v, paths); } - /// Returns if `std` should be statically linked into `rustc_driver`. - /// It's currently not done on `windows-gnu` due to linker bugs. - pub fn link_std_into_rustc_driver(&self, target: TargetSelection) -> bool { - !target.triple.ends_with("-windows-gnu") - } - /// Obtain a compiler at a given stage and for a given host (i.e., this is the target that the /// compiler will run on, *not* the target it will build code for). Explicitly does not take /// `Compiler` since all `Compiler` instances are meant to be obtained through this function,