Skip to content

Commit

Permalink
Make linker search logic think we build a normal -pc- target when s…
Browse files Browse the repository at this point in the history
…earching for `link.exe`
  • Loading branch information
seritools committed Feb 21, 2025
1 parent 93b0eae commit 1fe05b6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
8 changes: 3 additions & 5 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ pub(crate) fn get_linker<'a>(
self_contained: bool,
target_cpu: &'a str,
) -> Box<dyn Linker + 'a> {
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
Expand Down
5 changes: 4 additions & 1 deletion src/bootstrap/src/utils/cc_detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@ fn cc2ar(cc: &Path, target: TargetSelection) -> Option<PathBuf> {

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) => {
Expand Down

0 comments on commit 1fe05b6

Please sign in to comment.