11use std:: { borrow:: Cow , env} ;
22
3- use crate :: spec:: { cvs, FramePointer , LldFlavor , SplitDebuginfo , TargetOptions } ;
3+ use crate :: spec:: { cvs, FramePointer , SplitDebuginfo , TargetOptions } ;
4+ use crate :: spec:: { LinkArgs , LinkerFlavor , LldFlavor } ;
5+
6+ fn pre_link_args ( os : & ' static str , arch : & ' static str , abi : & ' static str ) -> LinkArgs {
7+ let mut args = LinkArgs :: new ( ) ;
8+
9+ let platform_name = match abi {
10+ "sim" => format ! ( "{}-simulator" , os) ,
11+ "macabi" => "mac-catalyst" . to_string ( ) ,
12+ _ => os. to_string ( ) ,
13+ } ;
14+
15+ let platform_version = match os. as_ref ( ) {
16+ "ios" => ios_lld_platform_version ( ) ,
17+ "tvos" => tvos_lld_platform_version ( ) ,
18+ "watchos" => watchos_lld_platform_version ( ) ,
19+ "macos" => macos_lld_platform_version ( arch) ,
20+ _ => unreachable ! ( ) ,
21+ } ;
22+
23+ if abi != "macabi" {
24+ args. insert ( LinkerFlavor :: Gcc , vec ! [ "-arch" . into( ) , arch. into( ) ] ) ;
25+ }
26+
27+ args. insert (
28+ LinkerFlavor :: Lld ( LldFlavor :: Ld64 ) ,
29+ vec ! [
30+ "-arch" . into( ) ,
31+ arch. into( ) ,
32+ "-platform_version" . into( ) ,
33+ platform_name. into( ) ,
34+ platform_version. clone( ) . into( ) ,
35+ platform_version. into( ) ,
36+ ] ,
37+ ) ;
38+
39+ args
40+ }
441
5- pub fn opts ( os : & ' static str ) -> TargetOptions {
42+ pub fn opts ( os : & ' static str , arch : & ' static str , abi : & ' static str ) -> TargetOptions {
643 // ELF TLS is only available in macOS 10.7+. If you try to compile for 10.6
744 // either the linker will complain if it is used or the binary will end up
845 // segfaulting at runtime when run on 10.6. Rust by default supports macOS
@@ -24,6 +61,7 @@ pub fn opts(os: &'static str) -> TargetOptions {
2461 // macOS has -dead_strip, which doesn't rely on function_sections
2562 function_sections : false ,
2663 dynamic_linking : true ,
64+ pre_link_args : pre_link_args ( os, arch, abi) ,
2765 linker_is_gnu : false ,
2866 families : cvs ! [ "unix" ] ,
2967 is_like_osx : true ,
@@ -73,6 +111,11 @@ fn macos_deployment_target(arch: &str) -> (u32, u32) {
73111 . unwrap_or_else ( || macos_default_deployment_target ( arch) )
74112}
75113
114+ fn macos_lld_platform_version ( arch : & str ) -> String {
115+ let ( major, minor) = macos_deployment_target ( arch) ;
116+ format ! ( "{}.{}" , major, minor)
117+ }
118+
76119pub fn macos_llvm_target ( arch : & str ) -> String {
77120 let ( major, minor) = macos_deployment_target ( arch) ;
78121 format ! ( "{}-apple-macosx{}.{}.0" , arch, major, minor)
@@ -109,7 +152,7 @@ pub fn ios_llvm_target(arch: &str) -> String {
109152 format ! ( "{}-apple-ios{}.{}.0" , arch, major, minor)
110153}
111154
112- pub fn ios_lld_platform_version ( ) -> String {
155+ fn ios_lld_platform_version ( ) -> String {
113156 let ( major, minor) = ios_deployment_target ( ) ;
114157 format ! ( "{}.{}" , major, minor)
115158}
@@ -123,7 +166,7 @@ fn tvos_deployment_target() -> (u32, u32) {
123166 deployment_target ( "TVOS_DEPLOYMENT_TARGET" ) . unwrap_or ( ( 7 , 0 ) )
124167}
125168
126- pub fn tvos_lld_platform_version ( ) -> String {
169+ fn tvos_lld_platform_version ( ) -> String {
127170 let ( major, minor) = tvos_deployment_target ( ) ;
128171 format ! ( "{}.{}" , major, minor)
129172}
@@ -132,7 +175,7 @@ fn watchos_deployment_target() -> (u32, u32) {
132175 deployment_target ( "WATCHOS_DEPLOYMENT_TARGET" ) . unwrap_or ( ( 5 , 0 ) )
133176}
134177
135- pub fn watchos_lld_platform_version ( ) -> String {
178+ fn watchos_lld_platform_version ( ) -> String {
136179 let ( major, minor) = watchos_deployment_target ( ) ;
137180 format ! ( "{}.{}" , major, minor)
138181}
0 commit comments