@@ -1811,6 +1811,16 @@ impl Build {
18111811 family. add_force_frame_pointer ( cmd) ;
18121812 }
18131813
1814+ if !cmd. is_like_msvc ( ) {
1815+ if target. contains ( "i686" ) || target. contains ( "i586" ) {
1816+ cmd. args . push ( "-m32" . into ( ) ) ;
1817+ } else if target == "x86_64-unknown-linux-gnux32" {
1818+ cmd. args . push ( "-mx32" . into ( ) ) ;
1819+ } else if target. contains ( "x86_64" ) || target. contains ( "powerpc64" ) {
1820+ cmd. args . push ( "-m64" . into ( ) ) ;
1821+ }
1822+ }
1823+
18141824 // Target flags
18151825 match cmd. family {
18161826 ToolFamily :: Clang => {
@@ -1954,14 +1964,6 @@ impl Build {
19541964 }
19551965 }
19561966 ToolFamily :: Gnu => {
1957- if target. contains ( "i686" ) || target. contains ( "i586" ) {
1958- cmd. args . push ( "-m32" . into ( ) ) ;
1959- } else if target == "x86_64-unknown-linux-gnux32" {
1960- cmd. args . push ( "-mx32" . into ( ) ) ;
1961- } else if target. contains ( "x86_64" ) || target. contains ( "powerpc64" ) {
1962- cmd. args . push ( "-m64" . into ( ) ) ;
1963- }
1964-
19651967 if target. contains ( "darwin" ) {
19661968 if let Some ( arch) = map_darwin_target_from_rust_to_compiler_architecture ( target)
19671969 {
@@ -3525,6 +3527,35 @@ impl Tool {
35253527 }
35263528
35273529 fn with_features ( path : PathBuf , clang_driver : Option < & str > , cuda : bool ) -> Self {
3530+ fn detect_family ( path : & Path ) -> ToolFamily {
3531+ let mut cmd = Command :: new ( path) ;
3532+ cmd. arg ( "--version" ) ;
3533+
3534+ let stdout = match run_output ( & mut cmd, & path. to_string_lossy ( ) )
3535+ . ok ( )
3536+ . and_then ( |o| String :: from_utf8 ( o) . ok ( ) )
3537+ {
3538+ Some ( s) => s,
3539+ None => {
3540+ // --version failed. fallback to gnu
3541+ println ! ( "cargo-warning:Failed to run: {:?}" , cmd) ;
3542+ return ToolFamily :: Gnu ;
3543+ }
3544+ } ;
3545+ if stdout. contains ( "clang" ) {
3546+ ToolFamily :: Clang
3547+ } else if stdout. contains ( "GCC" ) {
3548+ ToolFamily :: Gnu
3549+ } else {
3550+ // --version doesn't include clang for GCC
3551+ println ! (
3552+ "cargo-warning:Compiler version doesn't include clang or GCC: {:?}" ,
3553+ cmd
3554+ ) ;
3555+ ToolFamily :: Gnu
3556+ }
3557+ }
3558+
35283559 // Try to detect family of the tool from its name, falling back to Gnu.
35293560 let family = if let Some ( fname) = path. file_name ( ) . and_then ( |p| p. to_str ( ) ) {
35303561 if fname. contains ( "clang-cl" ) {
@@ -3537,10 +3568,10 @@ impl Tool {
35373568 _ => ToolFamily :: Clang ,
35383569 }
35393570 } else {
3540- ToolFamily :: Gnu
3571+ detect_family ( & path )
35413572 }
35423573 } else {
3543- ToolFamily :: Gnu
3574+ detect_family ( & path )
35443575 } ;
35453576
35463577 Tool {
0 commit comments