@@ -2808,6 +2808,14 @@ impl Build {
28082808 cmd
28092809 }
28102810
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+
28112819 fn get_base_compiler ( & self ) -> Result < Tool , Error > {
28122820 let out_dir = self . get_out_dir ( ) . ok ( ) ;
28132821 let out_dir = out_dir. as_deref ( ) ;
@@ -2835,14 +2843,19 @@ impl Build {
28352843 ( "CC" , "gcc" , "cc" , "clang" )
28362844 } ;
28372845
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) ) ;
28422847 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)
28442857 } else {
2845- traditional
2858+ fallback
28462859 } ;
28472860
28482861 let cl_exe = self . find_msvc_tools_find_tool ( & target, msvc) ;
0 commit comments