From 1fe05b6df9e323ed762441d9168cf8cf67603f7f Mon Sep 17 00:00:00 2001 From: Dennis Duda Date: Fri, 29 Nov 2024 19:29:19 +0100 Subject: [PATCH] Make linker search logic think we build a normal `-pc-` target when searching for `link.exe` --- compiler/rustc_codegen_ssa/src/back/link.rs | 8 +++----- compiler/rustc_codegen_ssa/src/back/linker.rs | 3 ++- src/bootstrap/src/utils/cc_detect.rs | 5 ++++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index e2081ad75633c..a31ca33d1996f 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1008,12 +1008,10 @@ fn link_natively( && (code < 1000 || code > 9999) { let is_vs_installed = windows_registry::find_vs_version().is_ok(); + let tuple = + sess.opts.target_triple.tuple().to_owned().replace("rust9x", "pc"); // FIXME(cc-rs#1265) pass only target arch to find_tool() - let has_linker = windows_registry::find_tool( - sess.opts.target_triple.tuple(), - "link.exe", - ) - .is_some(); + let has_linker = windows_registry::find_tool(&tuple, "link.exe").is_some(); sess.dcx().emit_note(errors::LinkExeUnexpectedError); if is_vs_installed && has_linker { diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index 3c6513ca26bb1..2ab278899e86e 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -50,8 +50,9 @@ pub(crate) fn get_linker<'a>( self_contained: bool, target_cpu: &'a str, ) -> Box { + let tuple = sess.opts.target_triple.tuple().to_owned().replace("rust9x", "pc"); // FIXME(cc-rs#1265) pass only target arch to find_tool() - let msvc_tool = windows_registry::find_tool(sess.opts.target_triple.tuple(), "link.exe"); + let msvc_tool = windows_registry::find_tool(&tuple, "link.exe"); // If our linker looks like a batch script on Windows then to execute this // we'll need to spawn `cmd` explicitly. This is primarily done to handle diff --git a/src/bootstrap/src/utils/cc_detect.rs b/src/bootstrap/src/utils/cc_detect.rs index 4aec554b4321a..4ec8283942c6d 100644 --- a/src/bootstrap/src/utils/cc_detect.rs +++ b/src/bootstrap/src/utils/cc_detect.rs @@ -72,13 +72,16 @@ fn cc2ar(cc: &Path, target: TargetSelection) -> Option { fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build { let mut cfg = cc::Build::new(); + + let triple = target.triple.to_owned().replace("rust9x", "pc"); + cfg.cargo_metadata(false) .opt_level(2) .warnings(false) .debug(false) // Compress debuginfo .flag_if_supported("-gz") - .target(&target.triple) + .target(&triple) .host(&build.build.triple); match build.crt_static(target) { Some(a) => {