Skip to content

Commit e8e7b24

Browse files
committed
try to detect clang/gcc
1 parent ba7003e commit e8e7b24

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/lib.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2904,6 +2904,35 @@ impl Tool {
29042904
}
29052905

29062906
fn with_features(path: PathBuf, clang_driver: Option<&str>, cuda: bool) -> Self {
2907+
fn detect_family(path: &Path) -> ToolFamily {
2908+
let mut cmd = Command::new(path);
2909+
cmd.arg("--version");
2910+
let stdout = match cmd
2911+
.output()
2912+
.ok()
2913+
.and_then(|o| String::from_utf8(o.stdout).ok())
2914+
{
2915+
Some(s) => s,
2916+
None => {
2917+
// --version failed. fallback to gnu
2918+
println!("cargo-warning:Running failed: {:?}", cmd);
2919+
return ToolFamily::Gnu;
2920+
}
2921+
};
2922+
if stdout.contains("clang") {
2923+
ToolFamily::Clang
2924+
} else if stdout.contains("GCC") {
2925+
ToolFamily::Gnu
2926+
} else {
2927+
// --version doesn't include clang for GCC
2928+
println!(
2929+
"cargo-warning:Compiler version doesn't include clang or GCC: {:?}",
2930+
cmd
2931+
);
2932+
ToolFamily::Gnu
2933+
}
2934+
}
2935+
29072936
// Try to detect family of the tool from its name, falling back to Gnu.
29082937
let family = if let Some(fname) = path.file_name().and_then(|p| p.to_str()) {
29092938
if fname.contains("clang-cl") {
@@ -2916,10 +2945,10 @@ impl Tool {
29162945
_ => ToolFamily::Clang,
29172946
}
29182947
} else {
2919-
ToolFamily::Gnu
2948+
detect_family(&path)
29202949
}
29212950
} else {
2922-
ToolFamily::Gnu
2951+
detect_family(&path)
29232952
};
29242953

29252954
Tool {

0 commit comments

Comments
 (0)