Skip to content

Commit ce94093

Browse files
committed
try to detect clang/gcc
1 parent b91a035 commit ce94093

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
@@ -3272,6 +3272,35 @@ impl Tool {
32723272
}
32733273

32743274
fn with_features(path: PathBuf, clang_driver: Option<&str>, cuda: bool) -> Self {
3275+
fn detect_family(path: &Path) -> ToolFamily {
3276+
let mut cmd = Command::new(path);
3277+
cmd.arg("--version");
3278+
3279+
let stdout = match run_output(&mut cmd, &path.to_string_lossy())
3280+
.ok()
3281+
.and_then(|o| String::from_utf8(o).ok())
3282+
{
3283+
Some(s) => s,
3284+
None => {
3285+
// --version failed. fallback to gnu
3286+
println!("cargo-warning:Running failed: {:?}", cmd);
3287+
return ToolFamily::Gnu;
3288+
}
3289+
};
3290+
if stdout.contains("clang") {
3291+
ToolFamily::Clang
3292+
} else if stdout.contains("GCC") {
3293+
ToolFamily::Gnu
3294+
} else {
3295+
// --version doesn't include clang for GCC
3296+
println!(
3297+
"cargo-warning:Compiler version doesn't include clang or GCC: {:?}",
3298+
cmd
3299+
);
3300+
ToolFamily::Gnu
3301+
}
3302+
}
3303+
32753304
// Try to detect family of the tool from its name, falling back to Gnu.
32763305
let family = if let Some(fname) = path.file_name().and_then(|p| p.to_str()) {
32773306
if fname.contains("clang-cl") {
@@ -3284,10 +3313,10 @@ impl Tool {
32843313
_ => ToolFamily::Clang,
32853314
}
32863315
} else {
3287-
ToolFamily::Gnu
3316+
detect_family(&path)
32883317
}
32893318
} else {
3290-
ToolFamily::Gnu
3319+
detect_family(&path)
32913320
};
32923321

32933322
Tool {

0 commit comments

Comments
 (0)