Skip to content

Commit 5cad391

Browse files
committed
rustc: Spawn cmd /c emcc.bat explicitly
In #42436 the behavior for spawning processes on Windows was tweaked slightly to fix various bugs, but this caused #42791 as a regression, namely that to spawn batch scripts they need to be manually spawned with `cmd /c` instead now. This updates the compiler to handle this case explicitly for Emscripten. Closes #42791
1 parent 824952f commit 5cad391

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/librustc_trans/back/link.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,32 @@ pub fn build_link_meta(incremental_hashes_map: &IncrementalHashesMap) -> LinkMet
107107
pub fn get_linker(sess: &Session) -> (String, Command, Vec<(OsString, OsString)>) {
108108
let envs = vec![("PATH".into(), command_path(sess))];
109109

110+
// If our linker looks like a batch script on Windows then to execute this
111+
// we'll need to spawn `cmd` explicitly. This is primarily done to handle
112+
// emscripten where the linker is `emcc.bat` and needs to be spawned as
113+
// `cmd /c emcc.bat ...`.
114+
//
115+
// This worked historically but is needed manually since #42436 (regression
116+
// was tagged as #42791) and some more info can be found on #44443 for
117+
// emscripten itself.
118+
let cmd = |linker: &str| {
119+
if cfg!(windows) && linker.ends_with(".bat") {
120+
let mut cmd = Command::new("cmd");
121+
cmd.arg("/c").arg(linker);
122+
cmd
123+
} else {
124+
Command::new(linker)
125+
}
126+
};
127+
110128
if let Some(ref linker) = sess.opts.cg.linker {
111-
(linker.clone(), Command::new(linker), envs)
129+
(linker.clone(), cmd(linker), envs)
112130
} else if sess.target.target.options.is_like_msvc {
113131
let (cmd, envs) = msvc_link_exe_cmd(sess);
114132
("link.exe".to_string(), cmd, envs)
115133
} else {
116134
let linker = &sess.target.target.options.linker;
117-
(linker.clone(), Command::new(&linker), envs)
135+
(linker.clone(), cmd(linker), envs)
118136
}
119137
}
120138

0 commit comments

Comments
 (0)