@@ -1811,6 +1811,16 @@ impl Build {
1811
1811
family. add_force_frame_pointer ( cmd) ;
1812
1812
}
1813
1813
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
+
1814
1824
// Target flags
1815
1825
match cmd. family {
1816
1826
ToolFamily :: Clang => {
@@ -1954,14 +1964,6 @@ impl Build {
1954
1964
}
1955
1965
}
1956
1966
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
-
1965
1967
if target. contains ( "darwin" ) {
1966
1968
if let Some ( arch) = map_darwin_target_from_rust_to_compiler_architecture ( target)
1967
1969
{
@@ -3525,6 +3527,35 @@ impl Tool {
3525
3527
}
3526
3528
3527
3529
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
+
3528
3559
// Try to detect family of the tool from its name, falling back to Gnu.
3529
3560
let family = if let Some ( fname) = path. file_name ( ) . and_then ( |p| p. to_str ( ) ) {
3530
3561
if fname. contains ( "clang-cl" ) {
@@ -3537,10 +3568,10 @@ impl Tool {
3537
3568
_ => ToolFamily :: Clang ,
3538
3569
}
3539
3570
} else {
3540
- ToolFamily :: Gnu
3571
+ detect_family ( & path )
3541
3572
}
3542
3573
} else {
3543
- ToolFamily :: Gnu
3574
+ detect_family ( & path )
3544
3575
} ;
3545
3576
3546
3577
Tool {
0 commit comments