Skip to content

[NFC] Rename Destination type to SwiftSDK #6707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public final class ClangTargetBuildDescription {

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

if enableModules {
Expand Down
20 changes: 10 additions & 10 deletions Sources/Build/BuildDescription/ProductBuildDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
case .debug:
return []
case .release:
if self.buildParameters.triple.isApple() {
if self.buildParameters.targetTriple.isApple() {
return ["-Xlinker", "-dead_strip"]
} else if self.buildParameters.triple.isWindows() {
} else if self.buildParameters.targetTriple.isWindows() {
return ["-Xlinker", "/OPT:REF"]
} else if self.buildParameters.triple.arch == .wasm32 {
} else if self.buildParameters.targetTriple.arch == .wasm32 {
// FIXME: wasm-ld strips data segments referenced through __start/__stop symbols
// during GC, and it removes Swift metadata sections like swift5_protocols
// We should add support of SHF_GNU_RETAIN-like flag for __attribute__((retain))
Expand All @@ -137,7 +137,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
/// The arguments to the librarian to create a static library.
public func archiveArguments() throws -> [String] {
let librarian = self.buildParameters.toolchain.librarianPath.pathString
let triple = self.buildParameters.triple
let triple = self.buildParameters.targetTriple
if triple.isWindows(), librarian.hasSuffix("link") || librarian.hasSuffix("link.exe") {
return try [librarian, "/LIB", "/OUT:\(binaryPath.pathString)", "@\(self.linkFileListPath.pathString)"]
}
Expand Down Expand Up @@ -206,17 +206,17 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
args += self.deadStripArguments
case .library(.dynamic):
args += ["-emit-library"]
if self.buildParameters.triple.isDarwin() {
if self.buildParameters.targetTriple.isDarwin() {
let relativePath = try "@rpath/\(buildParameters.binaryRelativePath(for: self.product).pathString)"
args += ["-Xlinker", "-install_name", "-Xlinker", relativePath]
}
args += self.deadStripArguments
case .executable, .snippet:
// Link the Swift stdlib statically, if requested.
if self.buildParameters.shouldLinkStaticSwiftStdlib {
if self.buildParameters.triple.isDarwin() {
if self.buildParameters.targetTriple.isDarwin() {
self.observabilityScope.emit(.swiftBackDeployError)
} else if self.buildParameters.triple.isSupportingStaticStdlib {
} else if self.buildParameters.targetTriple.isSupportingStaticStdlib {
args += ["-static-stdlib"]
}
}
Expand Down Expand Up @@ -245,9 +245,9 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription

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

// When deploying to macOS prior to macOS 12, add an rpath to the
// back-deployed concurrency libraries.
if useStdlibRpath, self.buildParameters.triple.isDarwin(),
if useStdlibRpath, self.buildParameters.targetTriple.isDarwin(),
let macOSSupportedPlatform = self.package.platforms.getDerived(for: .macOS),
macOSSupportedPlatform.version.major < 12
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public final class SwiftTargetBuildDescription {
/// The path to the swiftmodule file after compilation.
var moduleOutputPath: AbsolutePath {
// If we're an executable and we're not allowing test targets to link against us, we hide the module.
let allowLinkingAgainstExecutables = (buildParameters.triple.isDarwin() || self.buildParameters.triple
.isLinux() || self.buildParameters.triple.isWindows()) && self.toolsVersion >= .v5_5
let allowLinkingAgainstExecutables = (buildParameters.targetTriple.isDarwin() || self.buildParameters.targetTriple
.isLinux() || self.buildParameters.targetTriple.isWindows()) && self.toolsVersion >= .v5_5
let dirPath = (target.type == .executable && !allowLinkingAgainstExecutables) ? self.tempsPath : self
.buildParameters.buildPath
return dirPath.appending(component: self.target.c99name + ".swiftmodule")
Expand Down Expand Up @@ -326,7 +326,7 @@ public final class SwiftTargetBuildDescription {
guard let bundlePath else { return }

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

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

func writeOutputFileMap() throws -> AbsolutePath {
Expand Down Expand Up @@ -932,7 +932,7 @@ public final class SwiftTargetBuildDescription {

private var stdlibArguments: [String] {
if self.buildParameters.shouldLinkStaticSwiftStdlib,
self.buildParameters.triple.isSupportingStaticStdlib
self.buildParameters.targetTriple.isSupportingStaticStdlib
{
return ["-static-stdlib"]
} else {
Expand Down
12 changes: 11 additions & 1 deletion Sources/Build/BuildOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,17 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
let prebuildCommandResults: [ResolvedTarget: [PrebuildCommandResult]]
// Invoke any build tool plugins in the graph to generate prebuild commands and build commands.
if let pluginConfiguration {
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)
let buildOperationForPluginDependencies = try BuildOperation(
buildParameters: self.buildParameters.forTriple(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
)
buildToolPluginInvocationResults = try graph.invokeBuildToolPlugins(
outputDir: pluginConfiguration.workDirectory.appending("outputs"),
builtToolsDir: self.buildParameters.buildPath,
Expand Down
22 changes: 11 additions & 11 deletions Sources/Build/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,24 @@ extension BuildParameters {
public func targetTripleArgs(for target: ResolvedTarget) throws -> [String] {
var args = ["-target"]
// Compute the triple string for Darwin platform using the platform version.
if triple.isDarwin() {
if targetTriple.isDarwin() {
guard let macOSSupportedPlatform = target.platforms.getDerived(for: .macOS) else {
throw StringError("the target \(target) doesn't support building for macOS")
}
args += [triple.tripleString(forPlatformVersion: macOSSupportedPlatform.version.versionString)]
args += [targetTriple.tripleString(forPlatformVersion: macOSSupportedPlatform.version.versionString)]
} else {
args += [triple.tripleString]
args += [targetTriple.tripleString]
}
return args
}

/// 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.
func linkerFlagsForRenamingMainFunction(of target: ResolvedTarget) -> [String]? {
let args: [String]
if self.triple.isApple() {
if self.targetTriple.isApple() {
args = ["-alias", "_\(target.c99name)_main", "_main"]
}
else if self.triple.isLinux() {
else if self.targetTriple.isLinux() {
args = ["--defsym", "main=\(target.c99name)_main"]
}
else {
Expand Down Expand Up @@ -458,7 +458,7 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
switch dependency {
case .target: break
case .product(let product, _):
if buildParameters.triple.isDarwin() {
if buildParameters.targetTriple.isDarwin() {
try BuildPlan.validateDeploymentVersionOfProductDependency(
product: product,
forTarget: target,
Expand Down Expand Up @@ -632,9 +632,9 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
// Note: This will come from build settings in future.
for target in dependencies.staticTargets {
if case let target as ClangTarget = target.underlyingTarget, target.isCXX {
if buildParameters.triple.isDarwin() {
if buildParameters.targetTriple.isDarwin() {
buildProduct.additionalFlags += ["-lc++"]
} else if buildParameters.triple.isWindows() {
} else if buildParameters.targetTriple.isWindows() {
// Don't link any C++ library.
} else {
buildProduct.additionalFlags += ["-lstdc++"]
Expand Down Expand Up @@ -984,14 +984,14 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
/// Extracts the library information from an XCFramework.
private func parseXCFramework(for target: BinaryTarget) throws -> [LibraryInfo] {
try self.externalLibrariesCache.memoize(key: target) {
return try target.parseXCFrameworks(for: self.buildParameters.triple, fileSystem: self.fileSystem)
return try target.parseXCFrameworks(for: self.buildParameters.targetTriple, fileSystem: self.fileSystem)
}
}

/// Extracts the artifacts from an artifactsArchive
private func parseArtifactsArchive(for target: BinaryTarget) throws -> [ExecutableInfo] {
try self.externalExecutablesCache.memoize(key: target) {
let execInfos = try target.parseArtifactArchives(for: self.buildParameters.triple, fileSystem: self.fileSystem)
let execInfos = try target.parseArtifactArchives(for: self.buildParameters.targetTriple, fileSystem: self.fileSystem)
return execInfos.filter{!$0.supportedTriples.isEmpty}
}
}
Expand Down Expand Up @@ -1050,7 +1050,7 @@ extension Basics.Diagnostic {
extension BuildParameters {
/// Returns a named bundle's path inside the build directory.
func bundlePath(named name: String) -> AbsolutePath {
return buildPath.appending(component: name + triple.nsbundleExtension)
return buildPath.appending(component: name + targetTriple.nsbundleExtension)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Commands/PackageTools/APIDiff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct APIDiff: SwiftCommand {
var regenerateBaseline: Bool = false

func run(_ swiftTool: SwiftTool) throws {
let apiDigesterPath = try swiftTool.getDestinationToolchain().getSwiftAPIDigester()
let apiDigesterPath = try swiftTool.getTargetToolchain().getSwiftAPIDigester()
let apiDigesterTool = SwiftAPIDigester(fileSystem: swiftTool.fileSystem, tool: apiDigesterPath)

let packageRoot = try globalOptions.locations.packageDirectory ?? swiftTool.getPackageRoot()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Commands/PackageTools/DumpCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct DumpSymbolGraph: SwiftCommand {
// Configure the symbol graph extractor.
let symbolGraphExtractor = try SymbolGraphExtract(
fileSystem: swiftTool.fileSystem,
tool: swiftTool.getDestinationToolchain().getSymbolGraphExtract(),
tool: swiftTool.getTargetToolchain().getSymbolGraphExtract(),
observabilityScope: swiftTool.observabilityScope,
skipSynthesizedMembers: skipSynthesizedMembers,
minimumAccessLevel: minimumAccessLevel,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Commands/PackageTools/PluginCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ struct PluginCommand: SwiftCommand {
.contains { package.path.isDescendantOfOrEqual(to: $0) } ? [] : [package.path]

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

// 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.
Expand Down
6 changes: 3 additions & 3 deletions Sources/Commands/SwiftRunTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public struct SwiftRunTool: SwiftCommand {
print("Launching Swift REPL with arguments: \(arguments.joined(separator: " "))")
try self.run(
fileSystem: swiftTool.fileSystem,
executablePath: swiftTool.getDestinationToolchain().swiftInterpreterPath,
executablePath: swiftTool.getTargetToolchain().swiftInterpreterPath,
originalWorkingDirectory: swiftTool.originalWorkingDirectory,
arguments: arguments
)
Expand All @@ -168,7 +168,7 @@ public struct SwiftRunTool: SwiftCommand {
}

let pathRelativeToWorkingDirectory = executablePath.relative(to: swiftTool.originalWorkingDirectory)
let lldbPath = try swiftTool.getDestinationToolchain().getLLDB()
let lldbPath = try swiftTool.getTargetToolchain().getLLDB()
try exec(path: lldbPath.pathString, args: ["--", pathRelativeToWorkingDirectory.pathString] + options.arguments)
} catch let error as RunError {
swiftTool.observabilityScope.emit(error)
Expand All @@ -180,7 +180,7 @@ public struct SwiftRunTool: SwiftCommand {
if let executable = options.executable, try isValidSwiftFilePath(fileSystem: swiftTool.fileSystem, path: executable) {
swiftTool.observabilityScope.emit(.runFileDeprecation)
// Redirect execution to the toolchain's swift executable.
let swiftInterpreterPath = try swiftTool.getDestinationToolchain().swiftInterpreterPath
let swiftInterpreterPath = try swiftTool.getTargetToolchain().swiftInterpreterPath
// Prepend the script to interpret to the arguments.
let arguments = [executable] + options.arguments
try self.run(
Expand Down
Loading