Skip to content

Commit 1fe05b6

Browse files
committed
Make linker search logic think we build a normal -pc- target when searching for link.exe
1 parent 93b0eae commit 1fe05b6

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,12 +1008,10 @@ fn link_natively(
10081008
&& (code < 1000 || code > 9999)
10091009
{
10101010
let is_vs_installed = windows_registry::find_vs_version().is_ok();
1011+
let tuple =
1012+
sess.opts.target_triple.tuple().to_owned().replace("rust9x", "pc");
10111013
// FIXME(cc-rs#1265) pass only target arch to find_tool()
1012-
let has_linker = windows_registry::find_tool(
1013-
sess.opts.target_triple.tuple(),
1014-
"link.exe",
1015-
)
1016-
.is_some();
1014+
let has_linker = windows_registry::find_tool(&tuple, "link.exe").is_some();
10171015

10181016
sess.dcx().emit_note(errors::LinkExeUnexpectedError);
10191017
if is_vs_installed && has_linker {

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ pub(crate) fn get_linker<'a>(
5050
self_contained: bool,
5151
target_cpu: &'a str,
5252
) -> Box<dyn Linker + 'a> {
53+
let tuple = sess.opts.target_triple.tuple().to_owned().replace("rust9x", "pc");
5354
// FIXME(cc-rs#1265) pass only target arch to find_tool()
54-
let msvc_tool = windows_registry::find_tool(sess.opts.target_triple.tuple(), "link.exe");
55+
let msvc_tool = windows_registry::find_tool(&tuple, "link.exe");
5556

5657
// If our linker looks like a batch script on Windows then to execute this
5758
// we'll need to spawn `cmd` explicitly. This is primarily done to handle

src/bootstrap/src/utils/cc_detect.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,16 @@ fn cc2ar(cc: &Path, target: TargetSelection) -> Option<PathBuf> {
7272

7373
fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build {
7474
let mut cfg = cc::Build::new();
75+
76+
let triple = target.triple.to_owned().replace("rust9x", "pc");
77+
7578
cfg.cargo_metadata(false)
7679
.opt_level(2)
7780
.warnings(false)
7881
.debug(false)
7982
// Compress debuginfo
8083
.flag_if_supported("-gz")
81-
.target(&target.triple)
84+
.target(&triple)
8285
.host(&build.build.triple);
8386
match build.crt_static(target) {
8487
Some(a) => {

0 commit comments

Comments
 (0)