Skip to content

Commit 98e4cd5

Browse files
committed
fix: use detected MSVC's link.exe
1 parent c8ef8b6 commit 98e4cd5

File tree

1 file changed

+5
-2
lines changed
  • src/librustc_codegen_llvm/back

1 file changed

+5
-2
lines changed

Diff for: src/librustc_codegen_llvm/back/link.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ pub use rustc_codegen_utils::link::{find_crate_name, filename_for_input, default
6161
// path for MSVC to find its DLLs, and gcc to find its bundled
6262
// toolchain
6363
pub fn get_linker(sess: &Session, linker: &Path, flavor: LinkerFlavor) -> (PathBuf, Command) {
64+
let msvc_tool = windows_registry::find_tool(&sess.opts.target_triple.triple(), "link.exe");
65+
6466
// If our linker looks like a batch script on Windows then to execute this
6567
// we'll need to spawn `cmd` explicitly. This is primarily done to handle
6668
// emscripten where the linker is `emcc.bat` and needs to be spawned as
@@ -73,12 +75,13 @@ pub fn get_linker(sess: &Session, linker: &Path, flavor: LinkerFlavor) -> (PathB
7375
Some(linker) if cfg!(windows) && linker.ends_with(".bat") => Command::bat_script(linker),
7476
_ => match flavor {
7577
LinkerFlavor::Lld(f) => Command::lld(linker, f),
78+
LinkerFlavor::Msvc => {
79+
Command::new(msvc_tool.as_ref().map(|t| t.path()).unwrap_or(linker))
80+
},
7681
_ => Command::new(linker),
7782
}
7883
};
7984

80-
let msvc_tool = windows_registry::find_tool(&sess.opts.target_triple.triple(), "link.exe");
81-
8285
// The compiler's sysroot often has some bundled tools, so add it to the
8386
// PATH for the child.
8487
let mut new_path = sess.host_filesearch(PathKind::All)

0 commit comments

Comments
 (0)