@@ -17,6 +17,7 @@ pub enum Arch {
1717 Arm64 ,
1818 Arm64_32 ,
1919 I386 ,
20+ I686 ,
2021 X86_64 ,
2122 X86_64_sim ,
2223 X86_64_macabi ,
@@ -33,13 +34,23 @@ impl Arch {
3334 Arm64 | Arm64_macabi | Arm64_sim => "arm64" ,
3435 Arm64_32 => "arm64_32" ,
3536 I386 => "i386" ,
37+ I686 => "i686" ,
3638 X86_64 | X86_64_sim | X86_64_macabi => "x86_64" ,
3739 }
3840 }
3941
42+ pub fn target_arch ( self ) -> Cow < ' static , str > {
43+ Cow :: Borrowed ( match self {
44+ Armv7 | Armv7k | Armv7s => "arm" ,
45+ Arm64 | Arm64_32 | Arm64_macabi | Arm64_sim => "aarch64" ,
46+ I386 | I686 => "x86" ,
47+ X86_64 | X86_64_sim | X86_64_macabi => "x86_64" ,
48+ } )
49+ }
50+
4051 fn target_abi ( self ) -> & ' static str {
4152 match self {
42- Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | X86_64 => "" ,
53+ Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | I686 | X86_64 => "" ,
4354 X86_64_macabi | Arm64_macabi => "macabi" ,
4455 // x86_64-apple-ios is a simulator target, even though it isn't
4556 // declared that way in the target like the other ones...
@@ -54,7 +65,7 @@ impl Arch {
5465 Armv7s => "cortex-a9" ,
5566 Arm64 => "apple-a7" ,
5667 Arm64_32 => "apple-s4" ,
57- I386 => "yonah" ,
68+ I386 | I686 => "yonah" ,
5869 X86_64 | X86_64_sim => "core2" ,
5970 X86_64_macabi => "core2" ,
6071 Arm64_macabi => "apple-a12" ,
@@ -64,15 +75,16 @@ impl Arch {
6475
6576 fn link_env_remove ( self ) -> StaticCow < [ StaticCow < str > ] > {
6677 match self {
67- Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | X86_64 | X86_64_sim | Arm64_sim => {
78+ Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | I686 | X86_64 | X86_64_sim
79+ | Arm64_sim => {
6880 cvs ! [ "MACOSX_DEPLOYMENT_TARGET" ]
6981 }
7082 X86_64_macabi | Arm64_macabi => cvs ! [ "IPHONEOS_DEPLOYMENT_TARGET" ] ,
7183 }
7284 }
7385}
7486
75- fn pre_link_args ( os : & ' static str , arch : & ' static str , abi : & ' static str ) -> LinkArgs {
87+ fn pre_link_args ( os : & ' static str , arch : Arch , abi : & ' static str ) -> LinkArgs {
7688 let platform_name: StaticCow < str > = match abi {
7789 "sim" => format ! ( "{}-simulator" , os) . into ( ) ,
7890 "macabi" => "mac-catalyst" . into ( ) ,
@@ -88,6 +100,8 @@ fn pre_link_args(os: &'static str, arch: &'static str, abi: &'static str) -> Lin
88100 }
89101 . into ( ) ;
90102
103+ let arch = arch. target_name ( ) ;
104+
91105 let mut args = TargetOptions :: link_args (
92106 LinkerFlavor :: Darwin ( Cc :: No , Lld :: No ) ,
93107 & [ "-arch" , arch, "-platform_version" ] ,
@@ -118,7 +132,7 @@ pub fn opts(os: &'static str, arch: Arch) -> TargetOptions {
118132 // TLS is flagged as enabled if it looks to be supported. The architecture
119133 // only matters for default deployment target which is 11.0 for ARM64 and
120134 // 10.7 for everything else.
121- let has_thread_local = os == "macos" && macos_deployment_target ( "x86_64" ) >= ( 10 , 7 ) ;
135+ let has_thread_local = os == "macos" && macos_deployment_target ( Arch :: X86_64 ) >= ( 10 , 7 ) ;
122136
123137 let abi = arch. target_abi ( ) ;
124138
@@ -132,7 +146,7 @@ pub fn opts(os: &'static str, arch: Arch) -> TargetOptions {
132146 // macOS has -dead_strip, which doesn't rely on function_sections
133147 function_sections : false ,
134148 dynamic_linking : true ,
135- pre_link_args : pre_link_args ( os, arch. target_name ( ) , abi) ,
149+ pre_link_args : pre_link_args ( os, arch, abi) ,
136150 families : cvs ! [ "unix" ] ,
137151 is_like_osx : true ,
138152 default_dwarf_version : 2 ,
@@ -177,23 +191,24 @@ fn deployment_target(var_name: &str) -> Option<(u32, u32)> {
177191 . and_then ( |( a, b) | a. parse :: < u32 > ( ) . and_then ( |a| b. parse :: < u32 > ( ) . map ( |b| ( a, b) ) ) . ok ( ) )
178192}
179193
180- fn macos_default_deployment_target ( arch : & str ) -> ( u32 , u32 ) {
181- if arch == "arm64" { ( 11 , 0 ) } else { ( 10 , 7 ) }
194+ fn macos_default_deployment_target ( arch : Arch ) -> ( u32 , u32 ) {
195+ // Note: Arm64_sim is not included since macOS has no simulator.
196+ if matches ! ( arch, Arm64 | Arm64_macabi ) { ( 11 , 0 ) } else { ( 10 , 7 ) }
182197}
183198
184- fn macos_deployment_target ( arch : & str ) -> ( u32 , u32 ) {
199+ fn macos_deployment_target ( arch : Arch ) -> ( u32 , u32 ) {
185200 deployment_target ( "MACOSX_DEPLOYMENT_TARGET" )
186201 . unwrap_or_else ( || macos_default_deployment_target ( arch) )
187202}
188203
189- fn macos_lld_platform_version ( arch : & str ) -> String {
204+ fn macos_lld_platform_version ( arch : Arch ) -> String {
190205 let ( major, minor) = macos_deployment_target ( arch) ;
191206 format ! ( "{}.{}" , major, minor)
192207}
193208
194- pub fn macos_llvm_target ( arch : & str ) -> String {
209+ pub fn macos_llvm_target ( arch : Arch ) -> String {
195210 let ( major, minor) = macos_deployment_target ( arch) ;
196- format ! ( "{}-apple-macosx{}.{}.0" , arch, major, minor)
211+ format ! ( "{}-apple-macosx{}.{}.0" , arch. target_name ( ) , major, minor)
197212}
198213
199214pub fn macos_link_env_remove ( ) -> Vec < StaticCow < str > > {
0 commit comments