@@ -24,7 +24,8 @@ extension Toolchain {
24
24
let resourceDirBase : AbsolutePath
25
25
if let resourceDir = parsedOptions. getLastArgument ( . resourceDir) {
26
26
resourceDirBase = try AbsolutePath ( validating: resourceDir. asSingle)
27
- } else if let sdk = parsedOptions. getLastArgument ( . sdk) ,
27
+ } else if !triple. isDarwin,
28
+ let sdk = parsedOptions. getLastArgument ( . sdk) ,
28
29
let sdkPath = try ? AbsolutePath ( validating: sdk. asSingle) {
29
30
resourceDirBase = sdkPath
30
31
. appending ( components: " usr " , " lib " ,
@@ -120,87 +121,130 @@ extension Toolchain {
120
121
// MARK: - Common argument routines
121
122
122
123
extension DarwinToolchain {
123
- func addArgsToLinkStdlib(
124
- to commandLine: inout [ Job . ArgTemplate ] ,
125
- parsedOptions: inout ParsedOptions ,
126
- sdkPath: String ? ,
127
- targetTriple: Triple
128
- ) throws {
124
+ func getSwiftRuntimeCompatibilityVersion( for targetTriple: Triple ) -> ( Int , Int ) ? {
125
+ // FIXME: Add arm64e to Triple.swift
126
+ if targetTriple. archName == " arm64e " {
127
+ return ( 5 , 3 )
128
+ }
129
129
130
- // Link compatibility libraries, if we're deploying back to OSes that
131
- // have an older Swift runtime.
132
- // let sharedResourceDirPath = try computeResourceDirPath(for: targetTriple,
133
- // isShared: true)
134
- // Optional<llvm::VersionTuple> runtimeCompatibilityVersion;
135
- //
136
- // if (context.Args.hasArg(options::OPT_runtime_compatibility_version)) {
137
- // auto value = context.Args.getLastArgValue(
138
- // options::OPT_runtime_compatibility_version);
139
- // if (value.equals("5.0")) {
140
- // runtimeCompatibilityVersion = llvm::VersionTuple(5, 0);
141
- // } else if (value.equals("none")) {
142
- // runtimeCompatibilityVersion = None;
143
- // } else {
144
- // // TODO: diagnose unknown runtime compatibility version?
145
- // }
146
- // } else if (job.getKind() == LinkKind::Executable) {
147
- // runtimeCompatibilityVersion
148
- // = getSwiftRuntimeCompatibilityVersionForTarget(getTriple());
149
- // }
150
- //
151
- // if (runtimeCompatibilityVersion) {
152
- // if (*runtimeCompatibilityVersion <= llvm::VersionTuple(5, 0)) {
153
- // // Swift 5.0 compatibility library
154
- // SmallString<128> BackDeployLib;
155
- // BackDeployLib.append(SharedResourceDirPath);
156
- // llvm::sys::path::append(BackDeployLib, "libswiftCompatibility50.a");
157
- //
158
- // if (llvm::sys::fs::exists(BackDeployLib)) {
159
- // Arguments.push_back("-force_load");
160
- // Arguments.push_back(context.Args.MakeArgString(BackDeployLib));
161
- // }
162
- // }
163
- // }
164
- //
165
- // if (job.getKind() == LinkKind::Executable) {
166
- // if (runtimeCompatibilityVersion)
167
- // if (*runtimeCompatibilityVersion <= llvm::VersionTuple(5, 0)) {
168
- // // Swift 5.0 dynamic replacement compatibility library.
169
- // SmallString<128> BackDeployLib;
170
- // BackDeployLib.append(SharedResourceDirPath);
171
- // llvm::sys::path::append(BackDeployLib,
172
- // "libswiftCompatibilityDynamicReplacements.a");
173
- //
174
- // if (llvm::sys::fs::exists(BackDeployLib)) {
175
- // Arguments.push_back("-force_load");
176
- // Arguments.push_back(context.Args.MakeArgString(BackDeployLib));
177
- // }
178
- // }
179
- // }
130
+ if targetTriple. isMacOSX {
131
+ let macOSVersion = targetTriple. version ( for: . macOS)
132
+ switch ( macOSVersion. major, macOSVersion. minor, macOSVersion. micro) {
133
+ case ( 10 , ... 14 , _) :
134
+ return ( 5 , 0 )
135
+ case ( 10 , ... 15 , ... 3 ) :
136
+ return ( 5 , 1 )
137
+ case ( 10 , ... 15 , _) :
138
+ return ( 5 , 2 )
139
+ default :
140
+ break
141
+ }
142
+ } else if targetTriple. isiOS { // includes tvOS
143
+ let iOSVersion = targetTriple. version ( for: . iOS( . device) )
144
+ switch ( iOSVersion. major, iOSVersion. minor, iOSVersion. micro) {
145
+ case ( ... 12 , _, _) :
146
+ return ( 5 , 0 )
147
+ case ( 13 , ... 3 , _) :
148
+ return ( 5 , 1 )
149
+ case ( 13 , _, _) :
150
+ return ( 5 , 2 )
151
+ default :
152
+ break
153
+ }
154
+ } else if targetTriple. isWatchOS {
155
+ let watchOSVersion = targetTriple. version ( for: . watchOS( . device) )
156
+ switch ( watchOSVersion. major, watchOSVersion. minor, watchOSVersion. micro) {
157
+ case ( ... 5 , _, _) :
158
+ return ( 5 , 0 )
159
+ case ( 6 , ... 1 , _) :
160
+ return ( 5 , 1 )
161
+ case ( 6 , _, _) :
162
+ return ( 5 , 2 )
163
+ default :
164
+ break
165
+ }
166
+ }
167
+ return nil
168
+ }
180
169
181
- // Add the runtime library link path, which is platform-specific and found
182
- // relative to the compiler.
183
- let runtimePaths = try runtimeLibraryPaths (
184
- for: targetTriple,
185
- parsedOptions: & parsedOptions,
186
- sdkPath: sdkPath,
187
- isShared: true
188
- )
189
- for path in runtimePaths {
190
- commandLine. appendFlag ( . L)
191
- commandLine. appendPath ( path)
170
+ func addArgsToLinkStdlib(
171
+ to commandLine: inout [ Job . ArgTemplate ] ,
172
+ parsedOptions: inout ParsedOptions ,
173
+ sdkPath: String ? ,
174
+ targetTriple: Triple ,
175
+ linkerOutputType: LinkOutputType ,
176
+ fileSystem: FileSystem
177
+ ) throws {
178
+ // Link compatibility libraries, if we're deploying back to OSes that
179
+ // have an older Swift runtime.
180
+ var runtimeCompatibilityVersion : ( Int , Int ) ? = nil
181
+ let resourceDirPath = try computeResourceDirPath ( for: targetTriple,
182
+ parsedOptions: & parsedOptions,
183
+ isShared: true )
184
+ if let version = parsedOptions. getLastArgument ( . runtimeCompatibilityVersion) ? . asSingle {
185
+ switch version {
186
+ case " 5.0 " :
187
+ runtimeCompatibilityVersion = ( 5 , 0 )
188
+ case " 5.1 " :
189
+ runtimeCompatibilityVersion = ( 5 , 1 )
190
+ case " none " :
191
+ runtimeCompatibilityVersion = nil
192
+ default :
193
+ // TODO: diagnose unknown runtime compatibility version?
194
+ break
192
195
}
196
+ } else if linkerOutputType == . executable {
197
+ runtimeCompatibilityVersion = getSwiftRuntimeCompatibilityVersion ( for: targetTriple)
198
+ }
193
199
194
- let rpaths = StdlibRpathRule (
195
- parsedOptions: & parsedOptions,
196
- targetTriple: targetTriple
197
- )
198
- for path in rpaths. paths ( runtimeLibraryPaths: runtimePaths) {
199
- commandLine. appendFlag ( " -rpath " )
200
- commandLine. appendPath ( path)
200
+ func addArgsForBackDeployLib( _ libName: String ) {
201
+ let backDeployLibPath = resourceDirPath. appending ( component: libName)
202
+ if fileSystem. exists ( backDeployLibPath) {
203
+ commandLine. append ( . flag( " -force_load " ) )
204
+ commandLine. appendPath ( backDeployLibPath)
201
205
}
202
206
}
203
207
208
+ if let compatibilityVersion = runtimeCompatibilityVersion {
209
+ if compatibilityVersion <= ( 5 , 0 ) {
210
+ // Swift 5.0 compatibility library
211
+ addArgsForBackDeployLib ( " libswiftCompatibility50.a " )
212
+ }
213
+
214
+ if compatibilityVersion <= ( 5 , 1 ) {
215
+ // Swift 5.1 compatibility library
216
+ addArgsForBackDeployLib ( " libswiftCompatibility51.a " )
217
+ }
218
+
219
+ if linkerOutputType == . executable && compatibilityVersion <= ( 5 , 0 ) {
220
+ // Swift 5.0 dynamic replacement compatibility library.
221
+ addArgsForBackDeployLib ( " libswiftCompatibilityDynamicReplacements.a " )
222
+ }
223
+ }
224
+
225
+ // Add the runtime library link path, which is platform-specific and found
226
+ // relative to the compiler.
227
+ let runtimePaths = try runtimeLibraryPaths (
228
+ for: targetTriple,
229
+ parsedOptions: & parsedOptions,
230
+ sdkPath: sdkPath,
231
+ isShared: true
232
+ )
233
+ for path in runtimePaths {
234
+ commandLine. appendFlag ( . L)
235
+ commandLine. appendPath ( path)
236
+ }
237
+
238
+ let rpaths = StdlibRpathRule (
239
+ parsedOptions: & parsedOptions,
240
+ targetTriple: targetTriple
241
+ )
242
+ for path in rpaths. paths ( runtimeLibraryPaths: runtimePaths) {
243
+ commandLine. appendFlag ( " -rpath " )
244
+ commandLine. appendPath ( path)
245
+ }
246
+ }
247
+
204
248
/// Represents the rpaths we need to add in order to find the
205
249
/// desired standard library at runtime.
206
250
fileprivate enum StdlibRpathRule {
@@ -221,7 +265,7 @@ extension DarwinToolchain {
221
265
positive: . toolchainStdlibRpath,
222
266
negative: . noToolchainStdlibRpath,
223
267
default: false
224
- ) {
268
+ ) {
225
269
// If the user has explicitly asked for a toolchain stdlib, we should
226
270
// provide one using -rpath. This used to be the default behaviour but it
227
271
// was considered annoying in at least the SwiftPM scenario (see
@@ -232,7 +276,7 @@ extension DarwinToolchain {
232
276
self = . toolchain
233
277
}
234
278
else if targetTriple. supports ( . swiftInTheOS) ||
235
- parsedOptions. hasArgument ( . noStdlibRpath) {
279
+ parsedOptions. hasArgument ( . noStdlibRpath) {
236
280
// If targeting an OS with Swift in /usr/lib/swift, the LC_ID_DYLIB
237
281
// install_name the stdlib will be an absolute path like
238
282
// /usr/lib/swift/libswiftCore.dylib, and we do not need to provide an rpath
0 commit comments