File tree Expand file tree Collapse file tree 1 file changed +31
-2
lines changed Expand file tree Collapse file tree 1 file changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -2904,6 +2904,35 @@ impl Tool {
2904
2904
}
2905
2905
2906
2906
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
+
2907
2936
// Try to detect family of the tool from its name, falling back to Gnu.
2908
2937
let family = if let Some ( fname) = path. file_name ( ) . and_then ( |p| p. to_str ( ) ) {
2909
2938
if fname. contains ( "clang-cl" ) {
@@ -2916,10 +2945,10 @@ impl Tool {
2916
2945
_ => ToolFamily :: Clang ,
2917
2946
}
2918
2947
} else {
2919
- ToolFamily :: Gnu
2948
+ detect_family ( & path )
2920
2949
}
2921
2950
} else {
2922
- ToolFamily :: Gnu
2951
+ detect_family ( & path )
2923
2952
} ;
2924
2953
2925
2954
Tool {
You can’t perform that action at this time.
0 commit comments