1
1
use std:: { borrow:: Cow , env} ;
2
2
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
+ }
4
41
5
- pub fn opts ( os : & ' static str ) -> TargetOptions {
42
+ pub fn opts ( os : & ' static str , arch : & ' static str , abi : & ' static str ) -> TargetOptions {
6
43
// ELF TLS is only available in macOS 10.7+. If you try to compile for 10.6
7
44
// either the linker will complain if it is used or the binary will end up
8
45
// segfaulting at runtime when run on 10.6. Rust by default supports macOS
@@ -24,6 +61,7 @@ pub fn opts(os: &'static str) -> TargetOptions {
24
61
// macOS has -dead_strip, which doesn't rely on function_sections
25
62
function_sections : false ,
26
63
dynamic_linking : true ,
64
+ pre_link_args : pre_link_args ( os, arch, abi) ,
27
65
linker_is_gnu : false ,
28
66
families : cvs ! [ "unix" ] ,
29
67
is_like_osx : true ,
@@ -73,6 +111,11 @@ fn macos_deployment_target(arch: &str) -> (u32, u32) {
73
111
. unwrap_or_else ( || macos_default_deployment_target ( arch) )
74
112
}
75
113
114
+ fn macos_lld_platform_version ( arch : & str ) -> String {
115
+ let ( major, minor) = macos_deployment_target ( arch) ;
116
+ format ! ( "{}.{}" , major, minor)
117
+ }
118
+
76
119
pub fn macos_llvm_target ( arch : & str ) -> String {
77
120
let ( major, minor) = macos_deployment_target ( arch) ;
78
121
format ! ( "{}-apple-macosx{}.{}.0" , arch, major, minor)
@@ -109,7 +152,7 @@ pub fn ios_llvm_target(arch: &str) -> String {
109
152
format ! ( "{}-apple-ios{}.{}.0" , arch, major, minor)
110
153
}
111
154
112
- pub fn ios_lld_platform_version ( ) -> String {
155
+ fn ios_lld_platform_version ( ) -> String {
113
156
let ( major, minor) = ios_deployment_target ( ) ;
114
157
format ! ( "{}.{}" , major, minor)
115
158
}
@@ -123,7 +166,7 @@ fn tvos_deployment_target() -> (u32, u32) {
123
166
deployment_target ( "TVOS_DEPLOYMENT_TARGET" ) . unwrap_or ( ( 7 , 0 ) )
124
167
}
125
168
126
- pub fn tvos_lld_platform_version ( ) -> String {
169
+ fn tvos_lld_platform_version ( ) -> String {
127
170
let ( major, minor) = tvos_deployment_target ( ) ;
128
171
format ! ( "{}.{}" , major, minor)
129
172
}
@@ -132,7 +175,7 @@ fn watchos_deployment_target() -> (u32, u32) {
132
175
deployment_target ( "WATCHOS_DEPLOYMENT_TARGET" ) . unwrap_or ( ( 5 , 0 ) )
133
176
}
134
177
135
- pub fn watchos_lld_platform_version ( ) -> String {
178
+ fn watchos_lld_platform_version ( ) -> String {
136
179
let ( major, minor) = watchos_deployment_target ( ) ;
137
180
format ! ( "{}.{}" , major, minor)
138
181
}
0 commit comments