Skip to content

Commit 0e50b63

Browse files
authored
[NFC] Rename Destination type to SwiftSDK (#6707)
With the cross-compilation proposal accepted in principle, it's time to move over to the new nomenclature altogether. Renamed `Destination` type to `SwiftSDK`. Also renamed mentions of "destination" in declarations to "Swift SDK" and cleaned up usage of `triple` where it was actually referring to the target triple. Naming is consistent across the codebase. This is an NFC. * Rename `Destination` type to `SwiftSDK` Also renamed more mentions of "destination" in declarations to "Swift SDK". * Fix build error with incomplete renaming * Add `@_disfavoredOverload` to deprecated `BuildParameters.init`
1 parent d8e22aa commit 0e50b63

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+464
-322
lines changed

Sources/Build/BuildDescription/ClangTargetBuildDescription.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public final class ClangTargetBuildDescription {
216216

217217
var args = [String]()
218218
// Only enable ARC on macOS.
219-
if buildParameters.triple.isDarwin() {
219+
if buildParameters.targetTriple.isDarwin() {
220220
args += ["-fobjc-arc"]
221221
}
222222
args += try buildParameters.targetTripleArgs(for: target)
@@ -231,7 +231,7 @@ public final class ClangTargetBuildDescription {
231231
// index store for Apple's clang or if explicitly asked to.
232232
if ProcessEnv.vars.keys.contains("SWIFTPM_ENABLE_CLANG_INDEX_STORE") {
233233
args += buildParameters.indexStoreArguments(for: target)
234-
} else if buildParameters.triple.isDarwin(),
234+
} else if buildParameters.targetTriple.isDarwin(),
235235
(try? buildParameters.toolchain._isClangCompilerVendorApple()) == true
236236
{
237237
args += buildParameters.indexStoreArguments(for: target)
@@ -244,13 +244,13 @@ public final class ClangTargetBuildDescription {
244244
// 1. on Darwin when compiling for C++, because C++ modules are disabled on Apple-built Clang releases
245245
// 2. on Windows when compiling for any language, because of issues with the Windows SDK
246246
// 3. on Android when compiling for any language, because of issues with the Android SDK
247-
enableModules = !(buildParameters.triple.isDarwin() && isCXX) && !buildParameters.triple
248-
.isWindows() && !buildParameters.triple.isAndroid()
247+
enableModules = !(buildParameters.targetTriple.isDarwin() && isCXX) && !buildParameters.targetTriple
248+
.isWindows() && !buildParameters.targetTriple.isAndroid()
249249
} else {
250250
// For version >= 5.8, we disable them when compiling for C++ regardless of platforms, see:
251251
// https://github.com/llvm/llvm-project/issues/55980 for clang frontend crash when module
252252
// enabled for C++ on c++17 standard and above.
253-
enableModules = !isCXX && !buildParameters.triple.isWindows() && !buildParameters.triple.isAndroid()
253+
enableModules = !isCXX && !buildParameters.targetTriple.isWindows() && !buildParameters.targetTriple.isAndroid()
254254
}
255255

256256
if enableModules {

Sources/Build/BuildDescription/ProductBuildDescription.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
115115
case .debug:
116116
return []
117117
case .release:
118-
if self.buildParameters.triple.isApple() {
118+
if self.buildParameters.targetTriple.isApple() {
119119
return ["-Xlinker", "-dead_strip"]
120-
} else if self.buildParameters.triple.isWindows() {
120+
} else if self.buildParameters.targetTriple.isWindows() {
121121
return ["-Xlinker", "/OPT:REF"]
122-
} else if self.buildParameters.triple.arch == .wasm32 {
122+
} else if self.buildParameters.targetTriple.arch == .wasm32 {
123123
// FIXME: wasm-ld strips data segments referenced through __start/__stop symbols
124124
// during GC, and it removes Swift metadata sections like swift5_protocols
125125
// We should add support of SHF_GNU_RETAIN-like flag for __attribute__((retain))
@@ -137,7 +137,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
137137
/// The arguments to the librarian to create a static library.
138138
public func archiveArguments() throws -> [String] {
139139
let librarian = self.buildParameters.toolchain.librarianPath.pathString
140-
let triple = self.buildParameters.triple
140+
let triple = self.buildParameters.targetTriple
141141
if triple.isWindows(), librarian.hasSuffix("link") || librarian.hasSuffix("link.exe") {
142142
return try [librarian, "/LIB", "/OUT:\(binaryPath.pathString)", "@\(self.linkFileListPath.pathString)"]
143143
}
@@ -206,17 +206,17 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
206206
args += self.deadStripArguments
207207
case .library(.dynamic):
208208
args += ["-emit-library"]
209-
if self.buildParameters.triple.isDarwin() {
209+
if self.buildParameters.targetTriple.isDarwin() {
210210
let relativePath = try "@rpath/\(buildParameters.binaryRelativePath(for: self.product).pathString)"
211211
args += ["-Xlinker", "-install_name", "-Xlinker", relativePath]
212212
}
213213
args += self.deadStripArguments
214214
case .executable, .snippet:
215215
// Link the Swift stdlib statically, if requested.
216216
if self.buildParameters.shouldLinkStaticSwiftStdlib {
217-
if self.buildParameters.triple.isDarwin() {
217+
if self.buildParameters.targetTriple.isDarwin() {
218218
self.observabilityScope.emit(.swiftBackDeployError)
219-
} else if self.buildParameters.triple.isSupportingStaticStdlib {
219+
} else if self.buildParameters.targetTriple.isSupportingStaticStdlib {
220220
args += ["-static-stdlib"]
221221
}
222222
}
@@ -245,9 +245,9 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
245245

246246
// Set rpath such that dynamic libraries are looked up
247247
// adjacent to the product.
248-
if self.buildParameters.triple.isLinux() {
248+
if self.buildParameters.targetTriple.isLinux() {
249249
args += ["-Xlinker", "-rpath=$ORIGIN"]
250-
} else if self.buildParameters.triple.isDarwin() {
250+
} else if self.buildParameters.targetTriple.isDarwin() {
251251
let rpath = self.product.type == .test ? "@loader_path/../../../" : "@loader_path"
252252
args += ["-Xlinker", "-rpath", "-Xlinker", rpath]
253253
}
@@ -267,7 +267,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
267267

268268
// When deploying to macOS prior to macOS 12, add an rpath to the
269269
// back-deployed concurrency libraries.
270-
if useStdlibRpath, self.buildParameters.triple.isDarwin(),
270+
if useStdlibRpath, self.buildParameters.targetTriple.isDarwin(),
271271
let macOSSupportedPlatform = self.package.platforms.getDerived(for: .macOS),
272272
macOSSupportedPlatform.version.major < 12
273273
{

Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ public final class SwiftTargetBuildDescription {
103103
/// The path to the swiftmodule file after compilation.
104104
var moduleOutputPath: AbsolutePath {
105105
// If we're an executable and we're not allowing test targets to link against us, we hide the module.
106-
let allowLinkingAgainstExecutables = (buildParameters.triple.isDarwin() || self.buildParameters.triple
107-
.isLinux() || self.buildParameters.triple.isWindows()) && self.toolsVersion >= .v5_5
106+
let allowLinkingAgainstExecutables = (buildParameters.targetTriple.isDarwin() || self.buildParameters.targetTriple
107+
.isLinux() || self.buildParameters.targetTriple.isWindows()) && self.toolsVersion >= .v5_5
108108
let dirPath = (target.type == .executable && !allowLinkingAgainstExecutables) ? self.tempsPath : self
109109
.buildParameters.buildPath
110110
return dirPath.appending(component: self.target.c99name + ".swiftmodule")
@@ -326,7 +326,7 @@ public final class SwiftTargetBuildDescription {
326326
guard let bundlePath else { return }
327327

328328
let mainPathSubstitution: String
329-
if self.buildParameters.triple.isWASI() {
329+
if self.buildParameters.targetTriple.isWASI() {
330330
// We prefer compile-time evaluation of the bundle path here for WASI. There's no benefit in evaluating this
331331
// at runtime, especially as `Bundle` support in WASI Foundation is partial. We expect all resource paths to
332332
// evaluate to `/\(resourceBundleName)/\(resourcePath)`, which allows us to pass this path to JS APIs like
@@ -731,7 +731,7 @@ public final class SwiftTargetBuildDescription {
731731

732732
/// Returns true if ObjC compatibility header should be emitted.
733733
private var shouldEmitObjCCompatibilityHeader: Bool {
734-
self.buildParameters.triple.isDarwin() && self.target.type == .library
734+
self.buildParameters.targetTriple.isDarwin() && self.target.type == .library
735735
}
736736

737737
func writeOutputFileMap() throws -> AbsolutePath {
@@ -932,7 +932,7 @@ public final class SwiftTargetBuildDescription {
932932

933933
private var stdlibArguments: [String] {
934934
if self.buildParameters.shouldLinkStaticSwiftStdlib,
935-
self.buildParameters.triple.isSupportingStaticStdlib
935+
self.buildParameters.targetTriple.isSupportingStaticStdlib
936936
{
937937
return ["-static-stdlib"]
938938
} else {

Sources/Build/BuildOperation.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,17 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
423423
let prebuildCommandResults: [ResolvedTarget: [PrebuildCommandResult]]
424424
// Invoke any build tool plugins in the graph to generate prebuild commands and build commands.
425425
if let pluginConfiguration {
426-
let buildOperationForPluginDependencies = try BuildOperation(buildParameters: self.buildParameters.withDestination(self.buildParameters.hostTriple), cacheBuildManifest: false, packageGraphLoader: { return graph }, additionalFileRules: self.additionalFileRules, pkgConfigDirectories: self.pkgConfigDirectories, outputStream: self.outputStream, logLevel: self.logLevel, fileSystem: self.fileSystem, observabilityScope: self.observabilityScope)
426+
let buildOperationForPluginDependencies = try BuildOperation(
427+
buildParameters: self.buildParameters.forTriple(self.buildParameters.hostTriple),
428+
cacheBuildManifest: false,
429+
packageGraphLoader: { return graph },
430+
additionalFileRules: self.additionalFileRules,
431+
pkgConfigDirectories: self.pkgConfigDirectories,
432+
outputStream: self.outputStream,
433+
logLevel: self.logLevel,
434+
fileSystem: self.fileSystem,
435+
observabilityScope: self.observabilityScope
436+
)
427437
buildToolPluginInvocationResults = try graph.invokeBuildToolPlugins(
428438
outputDir: pluginConfiguration.workDirectory.appending("outputs"),
429439
builtToolsDir: self.buildParameters.buildPath,

Sources/Build/BuildPlan.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,24 +127,24 @@ extension BuildParameters {
127127
public func targetTripleArgs(for target: ResolvedTarget) throws -> [String] {
128128
var args = ["-target"]
129129
// Compute the triple string for Darwin platform using the platform version.
130-
if triple.isDarwin() {
130+
if targetTriple.isDarwin() {
131131
guard let macOSSupportedPlatform = target.platforms.getDerived(for: .macOS) else {
132132
throw StringError("the target \(target) doesn't support building for macOS")
133133
}
134-
args += [triple.tripleString(forPlatformVersion: macOSSupportedPlatform.version.versionString)]
134+
args += [targetTriple.tripleString(forPlatformVersion: macOSSupportedPlatform.version.versionString)]
135135
} else {
136-
args += [triple.tripleString]
136+
args += [targetTriple.tripleString]
137137
}
138138
return args
139139
}
140140

141141
/// Computes the linker flags to use in order to rename a module-named main function to 'main' for the target platform, or nil if the linker doesn't support it for the platform.
142142
func linkerFlagsForRenamingMainFunction(of target: ResolvedTarget) -> [String]? {
143143
let args: [String]
144-
if self.triple.isApple() {
144+
if self.targetTriple.isApple() {
145145
args = ["-alias", "_\(target.c99name)_main", "_main"]
146146
}
147-
else if self.triple.isLinux() {
147+
else if self.targetTriple.isLinux() {
148148
args = ["--defsym", "main=\(target.c99name)_main"]
149149
}
150150
else {
@@ -458,7 +458,7 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
458458
switch dependency {
459459
case .target: break
460460
case .product(let product, _):
461-
if buildParameters.triple.isDarwin() {
461+
if buildParameters.targetTriple.isDarwin() {
462462
try BuildPlan.validateDeploymentVersionOfProductDependency(
463463
product: product,
464464
forTarget: target,
@@ -632,9 +632,9 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
632632
// Note: This will come from build settings in future.
633633
for target in dependencies.staticTargets {
634634
if case let target as ClangTarget = target.underlyingTarget, target.isCXX {
635-
if buildParameters.triple.isDarwin() {
635+
if buildParameters.targetTriple.isDarwin() {
636636
buildProduct.additionalFlags += ["-lc++"]
637-
} else if buildParameters.triple.isWindows() {
637+
} else if buildParameters.targetTriple.isWindows() {
638638
// Don't link any C++ library.
639639
} else {
640640
buildProduct.additionalFlags += ["-lstdc++"]
@@ -1001,14 +1001,14 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
10011001
/// Extracts the library information from an XCFramework.
10021002
private func parseXCFramework(for target: BinaryTarget) throws -> [LibraryInfo] {
10031003
try self.externalLibrariesCache.memoize(key: target) {
1004-
return try target.parseXCFrameworks(for: self.buildParameters.triple, fileSystem: self.fileSystem)
1004+
return try target.parseXCFrameworks(for: self.buildParameters.targetTriple, fileSystem: self.fileSystem)
10051005
}
10061006
}
10071007

10081008
/// Extracts the artifacts from an artifactsArchive
10091009
private func parseArtifactsArchive(for target: BinaryTarget) throws -> [ExecutableInfo] {
10101010
try self.externalExecutablesCache.memoize(key: target) {
1011-
let execInfos = try target.parseArtifactArchives(for: self.buildParameters.triple, fileSystem: self.fileSystem)
1011+
let execInfos = try target.parseArtifactArchives(for: self.buildParameters.targetTriple, fileSystem: self.fileSystem)
10121012
return execInfos.filter{!$0.supportedTriples.isEmpty}
10131013
}
10141014
}
@@ -1067,7 +1067,7 @@ extension Basics.Diagnostic {
10671067
extension BuildParameters {
10681068
/// Returns a named bundle's path inside the build directory.
10691069
func bundlePath(named name: String) -> AbsolutePath {
1070-
return buildPath.appending(component: name + triple.nsbundleExtension)
1070+
return buildPath.appending(component: name + targetTriple.nsbundleExtension)
10711071
}
10721072
}
10731073

Sources/Commands/PackageTools/APIDiff.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct APIDiff: SwiftCommand {
7575
var regenerateBaseline: Bool = false
7676

7777
func run(_ swiftTool: SwiftTool) throws {
78-
let apiDigesterPath = try swiftTool.getDestinationToolchain().getSwiftAPIDigester()
78+
let apiDigesterPath = try swiftTool.getTargetToolchain().getSwiftAPIDigester()
7979
let apiDigesterTool = SwiftAPIDigester(fileSystem: swiftTool.fileSystem, tool: apiDigesterPath)
8080

8181
let packageRoot = try globalOptions.locations.packageDirectory ?? swiftTool.getPackageRoot()

Sources/Commands/PackageTools/DumpCommands.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct DumpSymbolGraph: SwiftCommand {
5353
// Configure the symbol graph extractor.
5454
let symbolGraphExtractor = try SymbolGraphExtract(
5555
fileSystem: swiftTool.fileSystem,
56-
tool: swiftTool.getDestinationToolchain().getSymbolGraphExtract(),
56+
tool: swiftTool.getTargetToolchain().getSymbolGraphExtract(),
5757
observabilityScope: swiftTool.observabilityScope,
5858
skipSynthesizedMembers: skipSynthesizedMembers,
5959
minimumAccessLevel: minimumAccessLevel,

Sources/Commands/PackageTools/PluginCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ struct PluginCommand: SwiftCommand {
246246
.contains { package.path.isDescendantOfOrEqual(to: $0) } ? [] : [package.path]
247247

248248
// Use the directory containing the compiler as an additional search directory, and add the $PATH.
249-
let toolSearchDirs = [try swiftTool.getDestinationToolchain().swiftCompilerPath.parentDirectory]
249+
let toolSearchDirs = [try swiftTool.getTargetToolchain().swiftCompilerPath.parentDirectory]
250250
+ getEnvSearchPaths(pathString: ProcessEnv.path, currentWorkingDirectory: .none)
251251

252252
// Build or bring up-to-date any executable host-side tools on which this plugin depends. Add them and any binary dependencies to the tool-names-to-path map.

Sources/Commands/SwiftRunTool.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public struct SwiftRunTool: SwiftCommand {
144144
print("Launching Swift REPL with arguments: \(arguments.joined(separator: " "))")
145145
try self.run(
146146
fileSystem: swiftTool.fileSystem,
147-
executablePath: swiftTool.getDestinationToolchain().swiftInterpreterPath,
147+
executablePath: swiftTool.getTargetToolchain().swiftInterpreterPath,
148148
originalWorkingDirectory: swiftTool.originalWorkingDirectory,
149149
arguments: arguments
150150
)
@@ -168,7 +168,7 @@ public struct SwiftRunTool: SwiftCommand {
168168
}
169169

170170
let pathRelativeToWorkingDirectory = executablePath.relative(to: swiftTool.originalWorkingDirectory)
171-
let lldbPath = try swiftTool.getDestinationToolchain().getLLDB()
171+
let lldbPath = try swiftTool.getTargetToolchain().getLLDB()
172172
try exec(path: lldbPath.pathString, args: ["--", pathRelativeToWorkingDirectory.pathString] + options.arguments)
173173
} catch let error as RunError {
174174
swiftTool.observabilityScope.emit(error)
@@ -180,7 +180,7 @@ public struct SwiftRunTool: SwiftCommand {
180180
if let executable = options.executable, try isValidSwiftFilePath(fileSystem: swiftTool.fileSystem, path: executable) {
181181
swiftTool.observabilityScope.emit(.runFileDeprecation)
182182
// Redirect execution to the toolchain's swift executable.
183-
let swiftInterpreterPath = try swiftTool.getDestinationToolchain().swiftInterpreterPath
183+
let swiftInterpreterPath = try swiftTool.getTargetToolchain().swiftInterpreterPath
184184
// Prepend the script to interpret to the arguments.
185185
let arguments = [executable] + options.arguments
186186
try self.run(

0 commit comments

Comments
 (0)