@@ -248,6 +248,7 @@ pub use tool::Tool;
248
248
use tool:: ToolFamily ;
249
249
250
250
mod target_info;
251
+ mod tempfile;
251
252
252
253
/// A builder for compilation of a native library.
253
254
///
@@ -314,6 +315,8 @@ enum ErrorKind {
314
315
ToolNotFound ,
315
316
/// One of the function arguments failed validation.
316
317
InvalidArgument ,
318
+ /// No known macro is defined for the compiler when discovering tool family
319
+ ToolFamilyMacroNotFound ,
317
320
/// Invalid target
318
321
InvalidTarget ,
319
322
#[ cfg( feature = "parallel" ) ]
@@ -621,15 +624,15 @@ impl Build {
621
624
if compiler. family . verbose_stderr ( ) {
622
625
compiler. remove_arg ( "-v" . into ( ) ) ;
623
626
}
624
- if compiler. family == ToolFamily :: Clang {
627
+ if compiler. is_like_clang ( ) {
625
628
// Avoid reporting that the arg is unsupported just because the
626
629
// compiler complains that it wasn't used.
627
630
compiler. push_cc_arg ( "-Wno-unused-command-line-argument" . into ( ) ) ;
628
631
}
629
632
630
633
let mut cmd = compiler. to_command ( ) ;
631
634
let is_arm = target. contains ( "aarch64" ) || target. contains ( "arm" ) ;
632
- let clang = compiler. family == ToolFamily :: Clang ;
635
+ let clang = compiler. is_like_clang ( ) ;
633
636
let gnu = compiler. family == ToolFamily :: Gnu ;
634
637
command_add_output_file (
635
638
& mut cmd,
@@ -1576,7 +1579,7 @@ impl Build {
1576
1579
let target = self . get_target ( ) ?;
1577
1580
let msvc = target. contains ( "msvc" ) ;
1578
1581
let compiler = self . try_get_compiler ( ) ?;
1579
- let clang = compiler. family == ToolFamily :: Clang ;
1582
+ let clang = compiler. is_like_clang ( ) ;
1580
1583
let gnu = compiler. family == ToolFamily :: Gnu ;
1581
1584
1582
1585
let is_assembler_msvc = msvc && asm_ext == Some ( AsmFileExt :: DotAsm ) ;
@@ -1732,7 +1735,7 @@ impl Build {
1732
1735
if let Some ( ref std) = self . std {
1733
1736
let separator = match cmd. family {
1734
1737
ToolFamily :: Msvc { .. } => ':' ,
1735
- ToolFamily :: Gnu | ToolFamily :: Clang => '=' ,
1738
+ ToolFamily :: Gnu | ToolFamily :: Clang { .. } => '=' ,
1736
1739
} ;
1737
1740
cmd. push_cc_arg ( format ! ( "-std{}{}" , separator, std) . into ( ) ) ;
1738
1741
}
@@ -1825,23 +1828,23 @@ impl Build {
1825
1828
_ => { }
1826
1829
}
1827
1830
}
1828
- ToolFamily :: Gnu | ToolFamily :: Clang => {
1831
+ ToolFamily :: Gnu | ToolFamily :: Clang { .. } => {
1829
1832
// arm-linux-androideabi-gcc 4.8 shipped with Android NDK does
1830
1833
// not support '-Oz'
1831
- if opt_level == "z" && cmd. family != ToolFamily :: Clang {
1834
+ if opt_level == "z" && ! cmd. is_like_clang ( ) {
1832
1835
cmd. push_opt_unless_duplicate ( "-Os" . into ( ) ) ;
1833
1836
} else {
1834
1837
cmd. push_opt_unless_duplicate ( format ! ( "-O{}" , opt_level) . into ( ) ) ;
1835
1838
}
1836
1839
1837
- if cmd. family == ToolFamily :: Clang && target. contains ( "windows" ) {
1840
+ if cmd. is_like_clang ( ) && target. contains ( "windows" ) {
1838
1841
// Disambiguate mingw and msvc on Windows. Problem is that
1839
1842
// depending on the origin clang can default to a mismatchig
1840
1843
// run-time.
1841
1844
cmd. push_cc_arg ( format ! ( "--target={}" , target) . into ( ) ) ;
1842
1845
}
1843
1846
1844
- if cmd. family == ToolFamily :: Clang && target. contains ( "android" ) {
1847
+ if cmd. is_like_clang ( ) && target. contains ( "android" ) {
1845
1848
// For compatibility with code that doesn't use pre-defined `__ANDROID__` macro.
1846
1849
// If compiler used via ndk-build or cmake (officially supported build methods)
1847
1850
// this macros is defined.
@@ -1899,7 +1902,7 @@ impl Build {
1899
1902
1900
1903
// Target flags
1901
1904
match cmd. family {
1902
- ToolFamily :: Clang => {
1905
+ ToolFamily :: Clang { .. } => {
1903
1906
if !cmd. has_internal_target_arg
1904
1907
&& !( target. contains ( "android" )
1905
1908
&& android_clang_compiler_uses_target_arg_internally ( & cmd. path ) )
@@ -2290,7 +2293,7 @@ impl Build {
2290
2293
if self . cpp {
2291
2294
match ( self . cpp_set_stdlib . as_ref ( ) , cmd. family ) {
2292
2295
( None , _) => { }
2293
- ( Some ( stdlib) , ToolFamily :: Gnu ) | ( Some ( stdlib) , ToolFamily :: Clang ) => {
2296
+ ( Some ( stdlib) , ToolFamily :: Gnu ) | ( Some ( stdlib) , ToolFamily :: Clang { .. } ) => {
2294
2297
cmd. push_cc_arg ( format ! ( "-stdlib=lib{}" , stdlib) . into ( ) ) ;
2295
2298
}
2296
2299
_ => {
@@ -2666,11 +2669,15 @@ impl Build {
2666
2669
}
2667
2670
2668
2671
fn get_base_compiler ( & self ) -> Result < Tool , Error > {
2672
+ let out_dir = self . get_out_dir ( ) . ok ( ) ;
2673
+ let out_dir = out_dir. as_deref ( ) ;
2674
+
2669
2675
if let Some ( c) = & self . compiler {
2670
2676
return Ok ( Tool :: new (
2671
2677
( * * c) . to_owned ( ) ,
2672
2678
& self . cached_compiler_family ,
2673
2679
& self . cargo_output ,
2680
+ out_dir,
2674
2681
) ) ;
2675
2682
}
2676
2683
let host = self . get_host ( ) ?;
@@ -2712,6 +2719,7 @@ impl Build {
2712
2719
driver_mode,
2713
2720
& self . cached_compiler_family ,
2714
2721
& self . cargo_output ,
2722
+ out_dir,
2715
2723
) ;
2716
2724
if let Some ( cc_wrapper) = wrapper {
2717
2725
t. cc_wrapper_path = Some ( PathBuf :: from ( cc_wrapper) ) ;
@@ -2730,6 +2738,7 @@ impl Build {
2730
2738
PathBuf :: from ( "cmd" ) ,
2731
2739
& self . cached_compiler_family ,
2732
2740
& self . cargo_output ,
2741
+ out_dir,
2733
2742
) ;
2734
2743
t. args . push ( "/c" . into ( ) ) ;
2735
2744
t. args . push ( format ! ( "{}.bat" , tool) . into ( ) ) ;
@@ -2739,6 +2748,7 @@ impl Build {
2739
2748
PathBuf :: from ( tool) ,
2740
2749
& self . cached_compiler_family ,
2741
2750
& self . cargo_output ,
2751
+ out_dir,
2742
2752
) )
2743
2753
}
2744
2754
} else {
@@ -2798,6 +2808,7 @@ impl Build {
2798
2808
PathBuf :: from ( compiler) ,
2799
2809
& self . cached_compiler_family ,
2800
2810
& self . cargo_output ,
2811
+ out_dir,
2801
2812
) ;
2802
2813
if let Some ( cc_wrapper) = Self :: rustc_wrapper_fallback ( ) {
2803
2814
t. cc_wrapper_path = Some ( PathBuf :: from ( cc_wrapper) ) ;
@@ -2821,6 +2832,7 @@ impl Build {
2821
2832
self . cuda ,
2822
2833
& self . cached_compiler_family ,
2823
2834
& self . cargo_output ,
2835
+ out_dir,
2824
2836
) ;
2825
2837
nvcc_tool
2826
2838
. args
@@ -3144,7 +3156,7 @@ impl Build {
3144
3156
// And even extend it to gcc targets by searching for "ar" instead
3145
3157
// of "llvm-ar"...
3146
3158
let compiler = self . get_base_compiler ( ) . ok ( ) ?;
3147
- if compiler. family == ToolFamily :: Clang {
3159
+ if compiler. is_like_clang ( ) {
3148
3160
name = format ! ( "llvm-{}" , tool) ;
3149
3161
search_programs ( & mut self . cmd ( & compiler. path ) , & name, & self . cargo_output )
3150
3162
. map ( |name| self . cmd ( name) )
0 commit comments