Skip to content

Commit 2ac4b8b

Browse files
committed
Add tests for executability of CC and CXX
1 parent 5b38c8f commit 2ac4b8b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/cargo_build_script/build.rs

+20
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,24 @@ fn main() {
44
"cargo:rustc-env=TOOL_PATH={}",
55
std::env::var("TOOL").unwrap()
66
);
7+
8+
// Assert that the CC and CXX env vars existed and were executable.
9+
// We don't assert what happens when they're executed (in particular, we don't check for a
10+
// non-zero exit code), but this asserts that it's an existing file which is executable.
11+
//
12+
// Unfortunately we need to shlex the path, because we add a `--sysroot=...` arg to the env var.
13+
for env_var in &["CC", "CXX"] {
14+
let v = std::env::var(env_var)
15+
.unwrap_or_else(|err| panic!("Error getting {}: {}", env_var, err));
16+
let (path, args) = if let Some(index) = v.find("--sysroot") {
17+
let (path, args) = v.split_at(index);
18+
(path, Some(args))
19+
} else {
20+
(v.as_str(), None)
21+
};
22+
std::process::Command::new(path)
23+
.args(args.into_iter())
24+
.status()
25+
.unwrap();
26+
}
727
}

0 commit comments

Comments
 (0)