@@ -2808,6 +2808,14 @@ impl Build {
2808
2808
cmd
2809
2809
}
2810
2810
2811
+ fn prefer_clang ( & self ) -> bool {
2812
+ if let Some ( env) = self . getenv ( "CARGO_ENCODED_RUSTFLAGS" ) {
2813
+ env. to_string_lossy ( ) . contains ( "linker-plugin-lto" )
2814
+ } else {
2815
+ false
2816
+ }
2817
+ }
2818
+
2811
2819
fn get_base_compiler ( & self ) -> Result < Tool , Error > {
2812
2820
let out_dir = self . get_out_dir ( ) . ok ( ) ;
2813
2821
let out_dir = out_dir. as_deref ( ) ;
@@ -2835,14 +2843,19 @@ impl Build {
2835
2843
( "CC" , "gcc" , "cc" , "clang" )
2836
2844
} ;
2837
2845
2838
- // On historical Solaris systems, "cc" may have been Sun Studio, which
2839
- // is not flag-compatible with "gcc". This history casts a long shadow,
2840
- // and many modern illumos distributions today ship GCC as "gcc" without
2841
- // also making it available as "cc".
2846
+ let fallback = Cow :: Borrowed ( Path :: new ( traditional) ) ;
2842
2847
let default = if cfg ! ( target_os = "solaris" ) || cfg ! ( target_os = "illumos" ) {
2843
- gnu
2848
+ // On historical Solaris systems, "cc" may have been Sun Studio, which
2849
+ // is not flag-compatible with "gcc". This history casts a long shadow,
2850
+ // and many modern illumos distributions today ship GCC as "gcc" without
2851
+ // also making it available as "cc".
2852
+ Cow :: Borrowed ( Path :: new ( gnu) )
2853
+ } else if self . prefer_clang ( ) {
2854
+ self . which ( Path :: new ( clang) , None )
2855
+ . map ( Cow :: Owned )
2856
+ . unwrap_or ( fallback)
2844
2857
} else {
2845
- traditional
2858
+ fallback
2846
2859
} ;
2847
2860
2848
2861
let cl_exe = self . find_msvc_tools_find_tool ( & target, msvc) ;
0 commit comments