Skip to content

Commit 05be48b

Browse files
authored
Rollup merge of rust-lang#38459 - nagisa:rustbuild-exec, r=alexcrichton
Use exec for the wrapper on UNIXes This not only avoids the small – and unnecessary – constant overhead for each compiler invocation, but also helps somewhat by only having “correct” rustc processes to look for in `/proc/`. This also makes the wrapper behave effectively as a regular exec wrapper its intended to be. I also took liberty to change the fallback error code from `1` to `0xfe` (now only relevant on windows) so that when people complain about “compiler exited with code 254”, its obvious where the issue lies (wrapper losing the exit code somehow). r? @alexcrichton
2 parents fda41c6 + b3b2f1b commit 05be48b

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/bootstrap/bin/rustc.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extern crate bootstrap;
3030
use std::env;
3131
use std::ffi::OsString;
3232
use std::path::PathBuf;
33-
use std::process::Command;
33+
use std::process::{Command, ExitStatus};
3434

3535
fn main() {
3636
let args = env::args_os().skip(1).collect::<Vec<_>>();
@@ -180,8 +180,19 @@ fn main() {
180180
}
181181

182182
// Actually run the compiler!
183-
std::process::exit(match cmd.status() {
184-
Ok(s) => s.code().unwrap_or(1),
183+
std::process::exit(match exec_cmd(&mut cmd) {
184+
Ok(s) => s.code().unwrap_or(0xfe),
185185
Err(e) => panic!("\n\nfailed to run {:?}: {}\n\n", cmd, e),
186186
})
187187
}
188+
189+
#[cfg(unix)]
190+
fn exec_cmd(cmd: &mut Command) -> ::std::io::Result<ExitStatus> {
191+
use std::os::unix::process::CommandExt;
192+
Err(cmd.exec())
193+
}
194+
195+
#[cfg(not(unix))]
196+
fn exec_cmd(cmd: &mut Command) -> ::std::io::Result<ExitStatus> {
197+
cmd.status()
198+
}

0 commit comments

Comments
 (0)