@@ -68,6 +68,11 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
68
68
self . tempsPath. appending ( " Objects.LinkFileList " )
69
69
}
70
70
71
+ /// Triple for which this product is compiled.
72
+ var buildTriple : Triple {
73
+ self . buildParameters. buildTriple ( for: self . product)
74
+ }
75
+
71
76
/// File system reference.
72
77
private let fileSystem : FileSystem
73
78
@@ -110,15 +115,16 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
110
115
return [ ]
111
116
}
112
117
118
+ let buildTriple = self . buildTriple
113
119
switch self . buildParameters. configuration {
114
120
case . debug:
115
121
return [ ]
116
122
case . release:
117
- if self . buildParameters . targetTriple . isApple ( ) {
123
+ if buildTriple . isApple ( ) {
118
124
return [ " -Xlinker " , " -dead_strip " ]
119
- } else if self . buildParameters . targetTriple . isWindows ( ) {
125
+ } else if buildTriple . isWindows ( ) {
120
126
return [ " -Xlinker " , " /OPT:REF " ]
121
- } else if self . buildParameters . targetTriple . arch == . wasm32 {
127
+ } else if buildTriple . arch == . wasm32 {
122
128
// FIXME: wasm-ld strips data segments referenced through __start/__stop symbols
123
129
// during GC, and it removes Swift metadata sections like swift5_protocols
124
130
// We should add support of SHF_GNU_RETAIN-like flag for __attribute__((retain))
@@ -136,7 +142,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
136
142
/// The arguments to the librarian to create a static library.
137
143
public func archiveArguments( ) throws -> [ String ] {
138
144
let librarian = self . buildParameters. toolchain. librarianPath. pathString
139
- let triple = self . buildParameters . targetTriple
145
+ let triple = self . buildTriple
140
146
if triple. isWindows ( ) , librarian. hasSuffix ( " link " ) || librarian. hasSuffix ( " link.exe " ) {
141
147
return try [ librarian, " /LIB " , " /OUT: \( binaryPath. pathString) " , " @ \( self . linkFileListPath. pathString) " ]
142
148
}
@@ -187,6 +193,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
187
193
}
188
194
189
195
var isLinkingStaticStdlib = false
196
+ let buildTriple = self . buildTriple
190
197
switch derivedProductType {
191
198
case . macro:
192
199
throw InternalError ( " macro not supported " ) // should never be reached
@@ -206,7 +213,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
206
213
args += self . deadStripArguments
207
214
case . library( . dynamic) :
208
215
args += [ " -emit-library " ]
209
- if self . buildParameters . targetTriple . isDarwin ( ) {
216
+ if buildTriple . isDarwin ( ) {
210
217
let relativePath = try " @rpath/ \( buildParameters. binaryRelativePath ( for: self . product) . pathString) "
211
218
args += [ " -Xlinker " , " -install_name " , " -Xlinker " , relativePath]
212
219
}
@@ -215,9 +222,9 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
215
222
// Link the Swift stdlib statically, if requested.
216
223
// TODO: unify this logic with SwiftTargetBuildDescription.stdlibArguments
217
224
if self . buildParameters. linkingParameters. shouldLinkStaticSwiftStdlib {
218
- if self . buildParameters . targetTriple . isDarwin ( ) {
225
+ if buildTriple . isDarwin ( ) {
219
226
self . observabilityScope. emit ( . swiftBackDeployError)
220
- } else if self . buildParameters . targetTriple . isSupportingStaticStdlib {
227
+ } else if buildTriple . isSupportingStaticStdlib {
221
228
args += [ " -static-stdlib " ]
222
229
isLinkingStaticStdlib = true
223
230
}
@@ -260,9 +267,9 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
260
267
// Set rpath such that dynamic libraries are looked up
261
268
// adjacent to the product, unless overridden.
262
269
if !self . buildParameters. linkingParameters. shouldDisableLocalRpath {
263
- if self . buildParameters . targetTriple . isLinux ( ) {
270
+ if buildTriple . isLinux ( ) {
264
271
args += [ " -Xlinker " , " -rpath=$ORIGIN " ]
265
- } else if self . buildParameters . targetTriple . isDarwin ( ) {
272
+ } else if buildTriple . isDarwin ( ) {
266
273
let rpath = self . product. type == . test ? " @loader_path/../../../ " : " @loader_path "
267
274
args += [ " -Xlinker " , " -rpath " , " -Xlinker " , rpath]
268
275
}
@@ -283,7 +290,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
283
290
284
291
// When deploying to macOS prior to macOS 12, add an rpath to the
285
292
// back-deployed concurrency libraries.
286
- if useStdlibRpath, self . buildParameters . targetTriple . isMacOSX {
293
+ if useStdlibRpath, buildTriple . isMacOSX {
287
294
let macOSSupportedPlatform = self . package . platforms. getDerived ( for: . macOS, usingXCTest: product. isLinkingXCTest)
288
295
if macOSSupportedPlatform. version. major < 12 {
289
296
let backDeployedStdlib = try buildParameters. toolchain. macosSwiftStdlib
@@ -308,7 +315,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
308
315
// setting is the package-level right now. We might need to figure out a better
309
316
// answer for libraries if/when we support specifying deployment target at the
310
317
// target-level.
311
- args += try self . buildParameters. targetTripleArgs ( for: self . product. targets [ 0 ] )
318
+ args += try self . buildParameters. buildTripleArgs ( for: self . product. targets [ 0 ] )
312
319
313
320
// Add arguments from declared build settings.
314
321
args += self . buildSettingsFlags
@@ -351,7 +358,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
351
358
flags += libraries. map { " -l " + $0 }
352
359
353
360
// Linked frameworks.
354
- if self . buildParameters . targetTriple . supportsFrameworks {
361
+ if self . buildTriple . supportsFrameworks {
355
362
let frameworks = OrderedSet ( self . staticTargets. reduce ( [ ] ) {
356
363
$0 + self . buildParameters. createScope ( for: $1) . evaluate ( . LINK_FRAMEWORKS)
357
364
} )
0 commit comments