@@ -2182,17 +2182,14 @@ impl Build {
21822182 }
21832183 }
21842184
2185- // Add version information to the target.
2186- let llvm_target = if target. vendor == "apple" {
2187- let deployment_target = self . apple_deployment_target ( target) ;
2188- target. versioned_llvm_target ( Some ( & deployment_target) )
2189- } else {
2190- target. versioned_llvm_target ( None )
2191- } ;
2192-
2193- // Pass `--target` with the LLVM target to properly
2194- // configure Clang even when cross-compiling.
2195- cmd. push_cc_arg ( format ! ( "--target={llvm_target}" ) . into ( ) ) ;
2185+ // Pass `--target` with the LLVM target to properly configure Clang even when
2186+ // cross-compiling.
2187+ //
2188+ // We intentionally don't put the deployment version in here on Apple targets,
2189+ // and instead pass that via `-mmacosx-version-min=` and similar flags, for
2190+ // better compatibility with older versions of Clang that has poor support for
2191+ // versioned target names (especially when it comes to configuration files).
2192+ cmd. push_cc_arg ( format ! ( "--target={}" , target. unversioned_llvm_target) . into ( ) ) ;
21962193 }
21972194 }
21982195 ToolFamily :: Msvc { clang_cl } => {
@@ -2208,8 +2205,9 @@ impl Build {
22082205 cmd. push_cc_arg ( "-m32" . into ( ) ) ;
22092206 cmd. push_cc_arg ( "-arch:IA32" . into ( ) ) ;
22102207 } else {
2211- let llvm_target = target. versioned_llvm_target ( None ) ;
2212- cmd. push_cc_arg ( format ! ( "--target={llvm_target}" ) . into ( ) ) ;
2208+ cmd. push_cc_arg (
2209+ format ! ( "--target={}" , target. unversioned_llvm_target) . into ( ) ,
2210+ ) ;
22132211 }
22142212 } else if target. full_arch == "i586" {
22152213 cmd. push_cc_arg ( "-arch:IA32" . into ( ) ) ;
@@ -2635,23 +2633,13 @@ impl Build {
26352633 fn apple_flags ( & self , cmd : & mut Tool ) -> Result < ( ) , Error > {
26362634 let target = self . get_target ( ) ?;
26372635
2638- // If the compiler is Clang, then we've already specifed the target
2639- // information (including the deployment target) with the `--target`
2640- // option, so we don't need to do anything further here.
2636+ // Pass the deployment target via `-mmacosx-version-min=`, `-mtargetos=` and similar.
26412637 //
2642- // If the compiler is GCC, then we need to specify
2643- // `-mmacosx-version-min` to set the deployment target, as well
2644- // as to say that the target OS is macOS.
2645- //
2646- // NOTE: GCC does not support `-miphoneos-version-min=` etc. (because
2647- // it does not support iOS in general), but we specify them anyhow in
2648- // case we actually have a Clang-like compiler disguised as a GNU-like
2649- // compiler, or in case GCC adds support for these in the future.
2650- if !cmd. is_like_clang ( ) {
2651- let min_version = self . apple_deployment_target ( & target) ;
2652- cmd. args
2653- . push ( target. apple_version_flag ( & min_version) . into ( ) ) ;
2654- }
2638+ // It is also necessary on GCC, as it forces a compilation error if the compiler is not
2639+ // configured for Darwin: https://gcc.gnu.org/onlinedocs/gcc/Darwin-Options.html
2640+ let min_version = self . apple_deployment_target ( & target) ;
2641+ cmd. args
2642+ . push ( target. apple_version_flag ( & min_version) . into ( ) ) ;
26552643
26562644 // AppleClang sometimes requires sysroot even on macOS
26572645 if cmd. is_xctoolchain_clang ( ) || target. os != "macos" {
0 commit comments