Skip to content

Commit

Permalink
Support RUSTC_WRAPPER on Windows and with absolute paths
Browse files Browse the repository at this point in the history
When checking for possible `RUSTC_WRAPPER`s that we can use to cache
C/C++ output, allow for filename extensions (e.g. `sccache.exe`) and
absolute paths (e.g. `/usr/local/bin/sccache`).

Closes #473
  • Loading branch information
mqudsi committed Jan 31, 2020
1 parent da9ec7d commit 13ce46d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2147,14 +2147,20 @@ impl Build {
}

/// Returns a fallback `cc_compiler_wrapper` by introspecting `RUSTC_WRAPPER`
fn rustc_wrapper_fallback() -> Option<&'static str> {
fn rustc_wrapper_fallback() -> Option<String> {
// No explicit CC wrapper was detected, but check if RUSTC_WRAPPER
// is defined and is a build accelerator that is compatible with
// C/C++ compilers (e.g. sccache)
let rustc_wrapper = std::env::var_os("RUSTC_WRAPPER");
match rustc_wrapper.as_ref().and_then(|s| s.as_os_str().to_str()) {
Some("sccache") => Some("sccache"),
_ => return None,
let valid_wrappers = ["sccache"];

let rustc_wrapper = std::env::var_os("RUSTC_WRAPPER")?;
let wrapper_path = Path::new(&rustc_wrapper);
let wrapper_stem = wrapper_path.file_stem()?;

if valid_wrappers.contains(&wrapper_stem.to_str()?) {
Some(rustc_wrapper.to_str()?.to_owned())
} else {
None
}
}

Expand Down

0 comments on commit 13ce46d

Please sign in to comment.