@@ -248,6 +248,7 @@ pub use tool::Tool;
248248use tool:: ToolFamily ;
249249
250250mod target_info;
251+ mod tempfile;
251252
252253/// A builder for compilation of a native library.
253254///
@@ -314,6 +315,8 @@ enum ErrorKind {
314315 ToolNotFound ,
315316 /// One of the function arguments failed validation.
316317 InvalidArgument ,
318+ /// No known macro is defined for the compiler when discovering tool family
319+ ToolFamilyMacroNotFound ,
317320 /// Invalid target
318321 InvalidTarget ,
319322 #[ cfg( feature = "parallel" ) ]
@@ -621,15 +624,15 @@ impl Build {
621624 if compiler. family . verbose_stderr ( ) {
622625 compiler. remove_arg ( "-v" . into ( ) ) ;
623626 }
624- if compiler. family == ToolFamily :: Clang {
627+ if compiler. is_like_clang ( ) {
625628 // Avoid reporting that the arg is unsupported just because the
626629 // compiler complains that it wasn't used.
627630 compiler. push_cc_arg ( "-Wno-unused-command-line-argument" . into ( ) ) ;
628631 }
629632
630633 let mut cmd = compiler. to_command ( ) ;
631634 let is_arm = target. contains ( "aarch64" ) || target. contains ( "arm" ) ;
632- let clang = compiler. family == ToolFamily :: Clang ;
635+ let clang = compiler. is_like_clang ( ) ;
633636 let gnu = compiler. family == ToolFamily :: Gnu ;
634637 command_add_output_file (
635638 & mut cmd,
@@ -1576,7 +1579,7 @@ impl Build {
15761579 let target = self . get_target ( ) ?;
15771580 let msvc = target. contains ( "msvc" ) ;
15781581 let compiler = self . try_get_compiler ( ) ?;
1579- let clang = compiler. family == ToolFamily :: Clang ;
1582+ let clang = compiler. is_like_clang ( ) ;
15801583 let gnu = compiler. family == ToolFamily :: Gnu ;
15811584
15821585 let is_assembler_msvc = msvc && asm_ext == Some ( AsmFileExt :: DotAsm ) ;
@@ -1732,7 +1735,7 @@ impl Build {
17321735 if let Some ( ref std) = self . std {
17331736 let separator = match cmd. family {
17341737 ToolFamily :: Msvc { .. } => ':' ,
1735- ToolFamily :: Gnu | ToolFamily :: Clang => '=' ,
1738+ ToolFamily :: Gnu | ToolFamily :: Clang { .. } => '=' ,
17361739 } ;
17371740 cmd. push_cc_arg ( format ! ( "-std{}{}" , separator, std) . into ( ) ) ;
17381741 }
@@ -1825,23 +1828,23 @@ impl Build {
18251828 _ => { }
18261829 }
18271830 }
1828- ToolFamily :: Gnu | ToolFamily :: Clang => {
1831+ ToolFamily :: Gnu | ToolFamily :: Clang { .. } => {
18291832 // arm-linux-androideabi-gcc 4.8 shipped with Android NDK does
18301833 // not support '-Oz'
1831- if opt_level == "z" && cmd. family != ToolFamily :: Clang {
1834+ if opt_level == "z" && ! cmd. is_like_clang ( ) {
18321835 cmd. push_opt_unless_duplicate ( "-Os" . into ( ) ) ;
18331836 } else {
18341837 cmd. push_opt_unless_duplicate ( format ! ( "-O{}" , opt_level) . into ( ) ) ;
18351838 }
18361839
1837- if cmd. family == ToolFamily :: Clang && target. contains ( "windows" ) {
1840+ if cmd. is_like_clang ( ) && target. contains ( "windows" ) {
18381841 // Disambiguate mingw and msvc on Windows. Problem is that
18391842 // depending on the origin clang can default to a mismatchig
18401843 // run-time.
18411844 cmd. push_cc_arg ( format ! ( "--target={}" , target) . into ( ) ) ;
18421845 }
18431846
1844- if cmd. family == ToolFamily :: Clang && target. contains ( "android" ) {
1847+ if cmd. is_like_clang ( ) && target. contains ( "android" ) {
18451848 // For compatibility with code that doesn't use pre-defined `__ANDROID__` macro.
18461849 // If compiler used via ndk-build or cmake (officially supported build methods)
18471850 // this macros is defined.
@@ -1899,7 +1902,7 @@ impl Build {
18991902
19001903 // Target flags
19011904 match cmd. family {
1902- ToolFamily :: Clang => {
1905+ ToolFamily :: Clang { .. } => {
19031906 if !cmd. has_internal_target_arg
19041907 && !( target. contains ( "android" )
19051908 && android_clang_compiler_uses_target_arg_internally ( & cmd. path ) )
@@ -2290,7 +2293,7 @@ impl Build {
22902293 if self . cpp {
22912294 match ( self . cpp_set_stdlib . as_ref ( ) , cmd. family ) {
22922295 ( None , _) => { }
2293- ( Some ( stdlib) , ToolFamily :: Gnu ) | ( Some ( stdlib) , ToolFamily :: Clang ) => {
2296+ ( Some ( stdlib) , ToolFamily :: Gnu ) | ( Some ( stdlib) , ToolFamily :: Clang { .. } ) => {
22942297 cmd. push_cc_arg ( format ! ( "-stdlib=lib{}" , stdlib) . into ( ) ) ;
22952298 }
22962299 _ => {
@@ -2666,11 +2669,15 @@ impl Build {
26662669 }
26672670
26682671 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+
26692675 if let Some ( c) = & self . compiler {
26702676 return Ok ( Tool :: new (
26712677 ( * * c) . to_owned ( ) ,
26722678 & self . cached_compiler_family ,
26732679 & self . cargo_output ,
2680+ out_dir,
26742681 ) ) ;
26752682 }
26762683 let host = self . get_host ( ) ?;
@@ -2712,6 +2719,7 @@ impl Build {
27122719 driver_mode,
27132720 & self . cached_compiler_family ,
27142721 & self . cargo_output ,
2722+ out_dir,
27152723 ) ;
27162724 if let Some ( cc_wrapper) = wrapper {
27172725 t. cc_wrapper_path = Some ( PathBuf :: from ( cc_wrapper) ) ;
@@ -2730,6 +2738,7 @@ impl Build {
27302738 PathBuf :: from ( "cmd" ) ,
27312739 & self . cached_compiler_family ,
27322740 & self . cargo_output ,
2741+ out_dir,
27332742 ) ;
27342743 t. args . push ( "/c" . into ( ) ) ;
27352744 t. args . push ( format ! ( "{}.bat" , tool) . into ( ) ) ;
@@ -2739,6 +2748,7 @@ impl Build {
27392748 PathBuf :: from ( tool) ,
27402749 & self . cached_compiler_family ,
27412750 & self . cargo_output ,
2751+ out_dir,
27422752 ) )
27432753 }
27442754 } else {
@@ -2798,6 +2808,7 @@ impl Build {
27982808 PathBuf :: from ( compiler) ,
27992809 & self . cached_compiler_family ,
28002810 & self . cargo_output ,
2811+ out_dir,
28012812 ) ;
28022813 if let Some ( cc_wrapper) = Self :: rustc_wrapper_fallback ( ) {
28032814 t. cc_wrapper_path = Some ( PathBuf :: from ( cc_wrapper) ) ;
@@ -2821,6 +2832,7 @@ impl Build {
28212832 self . cuda ,
28222833 & self . cached_compiler_family ,
28232834 & self . cargo_output ,
2835+ out_dir,
28242836 ) ;
28252837 nvcc_tool
28262838 . args
@@ -3144,7 +3156,7 @@ impl Build {
31443156 // And even extend it to gcc targets by searching for "ar" instead
31453157 // of "llvm-ar"...
31463158 let compiler = self . get_base_compiler ( ) . ok ( ) ?;
3147- if compiler. family == ToolFamily :: Clang {
3159+ if compiler. is_like_clang ( ) {
31483160 name = format ! ( "llvm-{}" , tool) ;
31493161 search_programs ( & mut self . cmd ( & compiler. path ) , & name, & self . cargo_output )
31503162 . map ( |name| self . cmd ( name) )
0 commit comments