Skip to content

Commit fe92c3b

Browse files
committed
try to detect clang/gcc
1 parent 8c4954b commit fe92c3b

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
@@ -3440,6 +3440,35 @@ impl Tool {
34403440
}
34413441

34423442
fn with_features(path: PathBuf, clang_driver: Option<&str>, cuda: bool) -> Self {
3443+
fn detect_family(path: &Path) -> ToolFamily {
3444+
let mut cmd = Command::new(path);
3445+
cmd.arg("--version");
3446+
3447+
let stdout = match run_output(&mut cmd, &path.to_string_lossy())
3448+
.ok()
3449+
.and_then(|o| String::from_utf8(o).ok())
3450+
{
3451+
Some(s) => s,
3452+
None => {
3453+
// --version failed. fallback to gnu
3454+
println!("cargo-warning:Running failed: {:?}", cmd);
3455+
return ToolFamily::Gnu;
3456+
}
3457+
};
3458+
if stdout.contains("clang") {
3459+
ToolFamily::Clang
3460+
} else if stdout.contains("GCC") {
3461+
ToolFamily::Gnu
3462+
} else {
3463+
// --version doesn't include clang for GCC
3464+
println!(
3465+
"cargo-warning:Compiler version doesn't include clang or GCC: {:?}",
3466+
cmd
3467+
);
3468+
ToolFamily::Gnu
3469+
}
3470+
}
3471+
34433472
// Try to detect family of the tool from its name, falling back to Gnu.
34443473
let family = if let Some(fname) = path.file_name().and_then(|p| p.to_str()) {
34453474
if fname.contains("clang-cl") {
@@ -3452,10 +3481,10 @@ impl Tool {
34523481
_ => ToolFamily::Clang,
34533482
}
34543483
} else {
3455-
ToolFamily::Gnu
3484+
detect_family(&path)
34563485
}
34573486
} else {
3458-
ToolFamily::Gnu
3487+
detect_family(&path)
34593488
};
34603489

34613490
Tool {

0 commit comments

Comments
 (0)