@@ -72,16 +72,6 @@ impl Arch {
7272 Arm64_sim => "apple-a12" ,
7373 }
7474 }
75-
76- fn link_env_remove ( self ) -> StaticCow < [ StaticCow < str > ] > {
77- match self {
78- Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | I686 | X86_64 | X86_64_sim
79- | Arm64_sim => {
80- cvs ! [ "MACOSX_DEPLOYMENT_TARGET" ]
81- }
82- X86_64_macabi | Arm64_macabi => cvs ! [ "IPHONEOS_DEPLOYMENT_TARGET" ] ,
83- }
84- }
8575}
8676
8777fn pre_link_args ( os : & ' static str , arch : Arch , abi : & ' static str ) -> LinkArgs {
@@ -140,7 +130,7 @@ pub fn opts(os: &'static str, arch: Arch) -> TargetOptions {
140130 abi : abi. into ( ) ,
141131 os : os. into ( ) ,
142132 cpu : arch. target_cpu ( ) . into ( ) ,
143- link_env_remove : arch . link_env_remove ( ) ,
133+ link_env_remove : link_env_remove ( arch , os ) ,
144134 vendor : "apple" . into ( ) ,
145135 linker_flavor : LinkerFlavor :: Darwin ( Cc :: Yes , Lld :: No ) ,
146136 // macOS has -dead_strip, which doesn't rely on function_sections
@@ -211,20 +201,38 @@ pub fn macos_llvm_target(arch: Arch) -> String {
211201 format ! ( "{}-apple-macosx{}.{}.0" , arch. target_name( ) , major, minor)
212202}
213203
214- pub fn macos_link_env_remove ( ) -> Vec < StaticCow < str > > {
215- let mut env_remove = Vec :: with_capacity ( 2 ) ;
216- // Remove the `SDKROOT` environment variable if it's clearly set for the wrong platform, which
217- // may occur when we're linking a custom build script while targeting iOS for example.
218- if let Ok ( sdkroot) = env:: var ( "SDKROOT" ) {
219- if sdkroot. contains ( "iPhoneOS.platform" ) || sdkroot. contains ( "iPhoneSimulator.platform" ) {
220- env_remove. push ( "SDKROOT" . into ( ) )
204+ fn link_env_remove ( arch : Arch , os : & ' static str ) -> StaticCow < [ StaticCow < str > ] > {
205+ // Apple platforms only officially support macOS as a host for any compilation.
206+ //
207+ // If building for macOS, we go ahead and remove any erronous environment state
208+ // that's only applicable to cross-OS compilation. Always leave anything for the
209+ // host OS alone though.
210+ if os == "macos" {
211+ let mut env_remove = Vec :: with_capacity ( 2 ) ;
212+ // Remove the `SDKROOT` environment variable if it's clearly set for the wrong platform, which
213+ // may occur when we're linking a custom build script while targeting iOS for example.
214+ if let Ok ( sdkroot) = env:: var ( "SDKROOT" ) {
215+ if sdkroot. contains ( "iPhoneOS.platform" ) || sdkroot. contains ( "iPhoneSimulator.platform" )
216+ {
217+ env_remove. push ( "SDKROOT" . into ( ) )
218+ }
219+ }
220+ // Additionally, `IPHONEOS_DEPLOYMENT_TARGET` must not be set when using the Xcode linker at
221+ // "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld",
222+ // although this is apparently ignored when using the linker at "/usr/bin/ld".
223+ env_remove. push ( "IPHONEOS_DEPLOYMENT_TARGET" . into ( ) ) ;
224+ env_remove. into ( )
225+ } else {
226+ // Otherwise if cross-compiling for a different OS/SDK, remove any part
227+ // of the linking environment that's wrong and reversed.
228+ match arch {
229+ Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | I686 | X86_64 | X86_64_sim
230+ | Arm64_sim => {
231+ cvs ! [ "MACOSX_DEPLOYMENT_TARGET" ]
232+ }
233+ X86_64_macabi | Arm64_macabi => cvs ! [ "IPHONEOS_DEPLOYMENT_TARGET" ] ,
221234 }
222235 }
223- // Additionally, `IPHONEOS_DEPLOYMENT_TARGET` must not be set when using the Xcode linker at
224- // "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld",
225- // although this is apparently ignored when using the linker at "/usr/bin/ld".
226- env_remove. push ( "IPHONEOS_DEPLOYMENT_TARGET" . into ( ) ) ;
227- env_remove
228236}
229237
230238fn ios_deployment_target ( ) -> ( u32 , u32 ) {
0 commit comments