Skip to content

Commit 214abf2

Browse files
committed
rustc: Spawn cmd /c emcc.bat explicitly
In rust-lang#42436 the behavior for spawning processes on Windows was tweaked slightly to fix various bugs, but this caused rust-lang#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 rust-lang#42791
1 parent 65bf0e2 commit 214abf2

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
@@ -106,14 +106,32 @@ pub fn build_link_meta(incremental_hashes_map: &IncrementalHashesMap) -> LinkMet
106106
pub fn get_linker(sess: &Session) -> (String, Command, Vec<(OsString, OsString)>) {
107107
let envs = vec![("PATH".into(), command_path(sess))];
108108

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

0 commit comments

Comments
 (0)