Skip to content

Absolutify CXX as well as CC #969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions cargo/cargo_build_script_runner/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ fn run_buildrs() -> Result<(), String> {
}
}

if let Some(cc_path) = env::var_os("CC") {
let mut cc_path = exec_root.join(cc_path).into_os_string();
if let Some(sysroot_path) = env::var_os("SYSROOT") {
cc_path.push(" --sysroot=");
cc_path.push(&exec_root.join(sysroot_path));
for compiler_env_var in &["CC", "CXX"] {
if let Some(compiler_path) = env::var_os(compiler_env_var) {
let mut compiler_path = exec_root.join(compiler_path).into_os_string();
if let Some(sysroot_path) = env::var_os("SYSROOT") {
compiler_path.push(" --sysroot=");
compiler_path.push(&exec_root.join(sysroot_path));
}
command.env(compiler_env_var, compiler_path);
}
command.env("CC", cc_path);
}

if let Some(ar_path) = env::var_os("AR") {
Expand Down
20 changes: 20 additions & 0 deletions test/cargo_build_script/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,24 @@ fn main() {
"cargo:rustc-env=TOOL_PATH={}",
std::env::var("TOOL").unwrap()
);

// Assert that the CC and CXX env vars existed and were executable.
// We don't assert what happens when they're executed (in particular, we don't check for a
// non-zero exit code), but this asserts that it's an existing file which is executable.
//
// Unfortunately we need to shlex the path, because we add a `--sysroot=...` arg to the env var.
for env_var in &["CC", "CXX"] {
let v = std::env::var(env_var)
.unwrap_or_else(|err| panic!("Error getting {}: {}", env_var, err));
let (path, args) = if let Some(index) = v.find("--sysroot") {
let (path, args) = v.split_at(index);
(path, Some(args))
} else {
(v.as_str(), None)
};
std::process::Command::new(path)
.args(args.into_iter())
.status()
.unwrap();
}
}