Skip to content
Merged
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
6 changes: 2 additions & 4 deletions src/bootstrap/src/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Comment thread
Kobzol marked this conversation as resolved.
if let Some(pos) = args.iter().enumerate().position(|(i, a)| {
a == "-C" && args.get(i + 1).map(|a| a == "prefer-dynamic").unwrap_or(false)
}) {
Expand Down
9 changes: 2 additions & 7 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 0 additions & 8 deletions src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions src/bootstrap/src/core/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading