From c9f661dd6d3e86c04f164148cd5110b501213771 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Fri, 7 Jul 2023 20:17:09 +0100 Subject: [PATCH 1/3] Rename `Destination` type to `SwiftSDK` Also renamed more mentions of "destination" in declarations to "Swift SDK". --- .../ClangTargetBuildDescription.swift | 10 +- .../ProductBuildDescription.swift | 20 +-- .../SwiftTargetBuildDescription.swift | 10 +- Sources/Build/BuildOperation.swift | 12 +- Sources/Build/BuildPlan.swift | 22 ++-- Sources/Commands/PackageTools/APIDiff.swift | 2 +- .../Commands/PackageTools/DumpCommands.swift | 2 +- .../Commands/PackageTools/PluginCommand.swift | 2 +- Sources/Commands/SwiftRunTool.swift | 6 +- Sources/Commands/SwiftTestTool.swift | 12 +- .../Commands/Utilities/PluginDelegate.swift | 4 +- .../Commands/Utilities/TestingSupport.swift | 6 +- Sources/CoreCommands/SwiftTool.swift | 62 ++++----- Sources/PackageLoading/ManifestLoader.swift | 4 +- Sources/PackageModel/CMakeLists.txt | 2 +- .../{Destination.swift => SwiftSDK.swift} | 89 ++++++++----- Sources/PackageModel/SwiftSDKBundle.swift | 16 +-- .../SwiftSDKConfigurationStore.swift | 32 ++--- Sources/PackageModel/UserToolchain.swift | 80 +++++++----- Sources/SPMBuildCore/BuildParameters.swift | 121 +++++++++++++++--- Sources/SPMTestSupport/Toolchain.swift | 6 +- .../ConfigurationSubcommand.swift | 2 +- .../Configuration/ResetConfiguration.swift | 4 +- .../Configuration/SetConfiguration.swift | 4 +- .../Configuration/ShowConfiguration.swift | 4 +- Sources/SwiftSDKTool/SwiftSDKSubcommand.swift | 2 +- .../Workspace/DefaultPluginScriptRunner.swift | 6 +- .../Workspace/Workspace+BinaryArtifacts.swift | 4 +- Sources/Workspace/Workspace.swift | 2 +- Sources/XCBuildSupport/XcodeBuildSystem.swift | 2 +- Sources/swift-bootstrap/main.swift | 14 +- Tests/BuildTests/BuildPlanTests.swift | 54 ++++---- Tests/BuildTests/MockBuildTestHelper.swift | 8 +- Tests/CommandsTests/BuildToolTests.swift | 4 +- Tests/CommandsTests/PackageToolTests.swift | 12 +- .../BuildPerfTests.swift | 4 +- .../FunctionalTests/CFamilyTargetTests.swift | 12 +- .../DependencyResolutionTests.swift | 8 +- .../FunctionalTests/MiscellaneousTests.swift | 14 +- .../ModuleAliasingFixtureTests.swift | 4 +- Tests/FunctionalTests/ModuleMapTests.swift | 6 +- Tests/FunctionalTests/ToolsVersionTests.swift | 2 +- .../PD_5_0_LoadingTests.swift | 2 +- .../PackageModelTests/DestinationTests.swift | 34 ++--- .../PackageModelTests/PackageModelTests.swift | 4 +- .../PluginInvocationTests.swift | 19 ++- Tests/WorkspaceTests/InitTests.swift | 6 +- Tests/WorkspaceTests/WorkspaceTests.swift | 26 ++-- 48 files changed, 462 insertions(+), 321 deletions(-) rename Sources/PackageModel/{Destination.swift => SwiftSDK.swift} (92%) diff --git a/Sources/Build/BuildDescription/ClangTargetBuildDescription.swift b/Sources/Build/BuildDescription/ClangTargetBuildDescription.swift index 58c72624542..c169e48d26c 100644 --- a/Sources/Build/BuildDescription/ClangTargetBuildDescription.swift +++ b/Sources/Build/BuildDescription/ClangTargetBuildDescription.swift @@ -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) @@ -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) @@ -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 { diff --git a/Sources/Build/BuildDescription/ProductBuildDescription.swift b/Sources/Build/BuildDescription/ProductBuildDescription.swift index 09ef3c598f8..67303bc1ec4 100644 --- a/Sources/Build/BuildDescription/ProductBuildDescription.swift +++ b/Sources/Build/BuildDescription/ProductBuildDescription.swift @@ -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)) @@ -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)"] } @@ -206,7 +206,7 @@ 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] } @@ -214,9 +214,9 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription 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"] } } @@ -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] } @@ -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 { diff --git a/Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift b/Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift index 97edc012ff0..1b482d1ddca 100644 --- a/Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift +++ b/Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift @@ -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") @@ -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 @@ -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 { @@ -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 { diff --git a/Sources/Build/BuildOperation.swift b/Sources/Build/BuildOperation.swift index 12bfe79607f..de88959880d 100644 --- a/Sources/Build/BuildOperation.swift +++ b/Sources/Build/BuildOperation.swift @@ -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, diff --git a/Sources/Build/BuildPlan.swift b/Sources/Build/BuildPlan.swift index cc0de00506b..c6b130866e8 100644 --- a/Sources/Build/BuildPlan.swift +++ b/Sources/Build/BuildPlan.swift @@ -127,13 +127,13 @@ 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 } @@ -141,10 +141,10 @@ extension BuildParameters { /// 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 { @@ -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, @@ -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++"] @@ -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} } } @@ -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) } } diff --git a/Sources/Commands/PackageTools/APIDiff.swift b/Sources/Commands/PackageTools/APIDiff.swift index 4ce1d92606d..3f60f0204cd 100644 --- a/Sources/Commands/PackageTools/APIDiff.swift +++ b/Sources/Commands/PackageTools/APIDiff.swift @@ -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() diff --git a/Sources/Commands/PackageTools/DumpCommands.swift b/Sources/Commands/PackageTools/DumpCommands.swift index b76c0b4c62a..7d9ac0cbcd3 100644 --- a/Sources/Commands/PackageTools/DumpCommands.swift +++ b/Sources/Commands/PackageTools/DumpCommands.swift @@ -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, diff --git a/Sources/Commands/PackageTools/PluginCommand.swift b/Sources/Commands/PackageTools/PluginCommand.swift index 5dd33c5e339..e0c184f3989 100644 --- a/Sources/Commands/PackageTools/PluginCommand.swift +++ b/Sources/Commands/PackageTools/PluginCommand.swift @@ -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. diff --git a/Sources/Commands/SwiftRunTool.swift b/Sources/Commands/SwiftRunTool.swift index 642d56b6f9a..190d576872f 100644 --- a/Sources/Commands/SwiftRunTool.swift +++ b/Sources/Commands/SwiftRunTool.swift @@ -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 ) @@ -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) @@ -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( diff --git a/Sources/Commands/SwiftTestTool.swift b/Sources/Commands/SwiftTestTool.swift index ab024e8e7f9..dc5f7ce5471 100644 --- a/Sources/Commands/SwiftTestTool.swift +++ b/Sources/Commands/SwiftTestTool.swift @@ -168,8 +168,8 @@ public struct SwiftTestTool: SwiftCommand { try self.validateArguments(observabilityScope: swiftTool.observabilityScope) // validate XCTest available on darwin based systems - let toolchain = try swiftTool.getDestinationToolchain() - if toolchain.triple.isDarwin() && toolchain.xctestPath == nil { + let toolchain = try swiftTool.getTargetToolchain() + if toolchain.targetTriple.isDarwin() && toolchain.xctestPath == nil { throw TestError.xctestNotAvailable } } catch { @@ -185,7 +185,7 @@ public struct SwiftTestTool: SwiftCommand { let command = try List.parse() try command.run(swiftTool) } else if !self.options.shouldRunInParallel { - let toolchain = try swiftTool.getDestinationToolchain() + let toolchain = try swiftTool.getTargetToolchain() let testProducts = try buildTestsIfNeeded(swiftTool: swiftTool) let buildParameters = try swiftTool.buildParametersForTest(options: self.options) @@ -261,7 +261,7 @@ public struct SwiftTestTool: SwiftCommand { } } else { - let toolchain = try swiftTool.getDestinationToolchain() + let toolchain = try swiftTool.getTargetToolchain() let testProducts = try buildTestsIfNeeded(swiftTool: swiftTool) let testSuites = try TestingSupport.getTestSuites( in: testProducts, @@ -349,7 +349,7 @@ public struct SwiftTestTool: SwiftCommand { /// Merges all profraw profiles in codecoverage directory into default.profdata file. private func mergeCodeCovRawDataFiles(swiftTool: SwiftTool) throws { // Get the llvm-prof tool. - let llvmProf = try swiftTool.getDestinationToolchain().getLLVMProf() + let llvmProf = try swiftTool.getTargetToolchain().getLLVMProf() // Get the profraw files. let buildParameters = try swiftTool.buildParametersForTest(options: self.options) @@ -371,7 +371,7 @@ public struct SwiftTestTool: SwiftCommand { /// Exports profdata as a JSON file. private func exportCodeCovAsJSON(to path: AbsolutePath, testBinary: AbsolutePath, swiftTool: SwiftTool) throws { // Export using the llvm-cov tool. - let llvmCov = try swiftTool.getDestinationToolchain().getLLVMCov() + let llvmCov = try swiftTool.getTargetToolchain().getLLVMCov() let buildParameters = try swiftTool.buildParametersForTest(options: self.options) let args = [ llvmCov.pathString, diff --git a/Sources/Commands/Utilities/PluginDelegate.swift b/Sources/Commands/Utilities/PluginDelegate.swift index 35422835db3..67008d3ae49 100644 --- a/Sources/Commands/Utilities/PluginDelegate.swift +++ b/Sources/Commands/Utilities/PluginDelegate.swift @@ -169,7 +169,7 @@ final class PluginDelegate: PluginInvocationDelegate { ) throws -> PluginInvocationTestResult { // Build the tests. Ideally we should only build those that match the subset, but we don't have a way to know // which ones they are until we've built them and can examine the binaries. - let toolchain = try swiftTool.getDestinationToolchain() + let toolchain = try swiftTool.getTargetToolchain() var buildParameters = try swiftTool.buildParameters() buildParameters.enableTestability = true buildParameters.enableCodeCoverage = parameters.enableCodeCoverage @@ -340,7 +340,7 @@ final class PluginDelegate: PluginInvocationDelegate { // Configure the symbol graph extractor. var symbolGraphExtractor = try SymbolGraphExtract( fileSystem: swiftTool.fileSystem, - tool: swiftTool.getDestinationToolchain().getSymbolGraphExtract(), + tool: swiftTool.getTargetToolchain().getSymbolGraphExtract(), observabilityScope: swiftTool.observabilityScope ) symbolGraphExtractor.skipSynthesizedMembers = !options.includeSynthesized diff --git a/Sources/Commands/Utilities/TestingSupport.swift b/Sources/Commands/Utilities/TestingSupport.swift index 372bf6774e4..6846a31ef60 100644 --- a/Sources/Commands/Utilities/TestingSupport.swift +++ b/Sources/Commands/Utilities/TestingSupport.swift @@ -92,7 +92,7 @@ enum TestingSupport { let data: String = try withTemporaryFile { tempFile in let args = [try Self.xctestHelperPath(swiftTool: swiftTool).pathString, path.pathString, tempFile.path.pathString] var env = try Self.constructTestEnvironment( - toolchain: try swiftTool.getDestinationToolchain(), + toolchain: try swiftTool.getTargetToolchain(), buildParameters: swiftTool.buildParametersForTest( enableCodeCoverage: enableCodeCoverage ), @@ -100,7 +100,7 @@ enum TestingSupport { ) // Add the sdk platform path if we have it. If this is not present, we might always end up failing. - let sdkPlatformFrameworksPath = try Destination.sdkPlatformFrameworkPaths() + let sdkPlatformFrameworksPath = try SwiftSDK.sdkPlatformFrameworkPaths() // appending since we prefer the user setting (if set) to the one we inject env.appendPath("DYLD_FRAMEWORK_PATH", value: sdkPlatformFrameworksPath.fwk.pathString) env.appendPath("DYLD_LIBRARY_PATH", value: sdkPlatformFrameworksPath.lib.pathString) @@ -111,7 +111,7 @@ enum TestingSupport { } #else let env = try Self.constructTestEnvironment( - toolchain: try swiftTool.getDestinationToolchain(), + toolchain: try swiftTool.getTargetToolchain(), buildParameters: swiftTool.buildParametersForTest( enableCodeCoverage: enableCodeCoverage ), diff --git a/Sources/CoreCommands/SwiftTool.swift b/Sources/CoreCommands/SwiftTool.swift index 7165524d3fb..bb64891b211 100644 --- a/Sources/CoreCommands/SwiftTool.swift +++ b/Sources/CoreCommands/SwiftTool.swift @@ -207,7 +207,7 @@ public final class SwiftTool { /// Path to the shared configuration directory public let sharedConfigurationDirectory: AbsolutePath? - /// Path to the cross-compilation destinations directory. + /// Path to the cross-compilation Swift SDKs directory. public let sharedSwiftSDKsDirectory: AbsolutePath? /// Cancellator to handle cancellation of outstanding work when handling SIGINT @@ -592,8 +592,8 @@ public final class SwiftTool { } /// Returns the user toolchain to compile the actual product. - public func getDestinationToolchain() throws -> UserToolchain { - try _destinationToolchain.get() + public func getTargetToolchain() throws -> UserToolchain { + try _targetToolchain.get() } public func getHostToolchain() throws -> UserToolchain { @@ -670,28 +670,28 @@ public final class SwiftTool { private lazy var _buildParameters: Result = { return Result(catching: { - let destinationToolchain = try self.getDestinationToolchain() - let destinationTriple = destinationToolchain.triple + let targetToolchain = try self.getTargetToolchain() + let targetTriple = targetToolchain.targetTriple // Use "apple" as the subdirectory because in theory Xcode build system // can be used to build for any Apple platform and it has it's own // conventions for build subpaths based on platforms. let dataPath = self.scratchDirectory.appending( - component: destinationTriple.platformBuildPathComponent(buildSystem: options.build.buildSystem) + component: targetTriple.platformBuildPathComponent(buildSystem: options.build.buildSystem) ) return try BuildParameters( dataPath: dataPath, configuration: options.build.configuration, - toolchain: destinationToolchain, - destinationTriple: destinationTriple, + toolchain: targetToolchain, + targetTriple: targetTriple, flags: options.build.buildFlags, pkgConfigDirectories: options.locations.pkgConfigDirectories, architectures: options.build.architectures, workers: options.build.jobs ?? UInt32(ProcessInfo.processInfo.activeProcessorCount), shouldLinkStaticSwiftStdlib: options.linker.shouldLinkStaticSwiftStdlib, canRenameEntrypointFunctionName: driverSupport.checkSupportedFrontendFlags( - flags: ["entry-point-function-name"], toolchain: destinationToolchain, fileSystem: self.fileSystem + flags: ["entry-point-function-name"], toolchain: targetToolchain, fileSystem: self.fileSystem ), sanitizers: options.build.enabledSanitizers, enableCodeCoverage: false, // set by test commands when appropriate @@ -712,38 +712,38 @@ public final class SwiftTool { }) }() - /// Lazily compute the destination toolchain. - private lazy var _destinationToolchain: Result = { - var destination: Destination - let hostDestination: Destination + /// Lazily compute the target toolchain. + private lazy var _targetToolchain: Result = { + var swiftSDK: SwiftSDK + let hostSwiftSDK: SwiftSDK do { let hostToolchain = try _hostToolchain.get() - hostDestination = hostToolchain.destination + hostSwiftSDK = hostToolchain.swiftSDK let hostTriple = try Triple.getHostTriple(usingSwiftCompiler: hostToolchain.swiftCompilerPath) // Create custom toolchain if present. if let customDestination = options.locations.customCompileDestination { - let destinations = try Destination.decode( + let swiftSDKs = try SwiftSDK.decode( fromFile: customDestination, fileSystem: fileSystem, observabilityScope: observabilityScope ) - if destinations.count == 1 { - destination = destinations[0] - } else if destinations.count > 1, + if swiftSDKs.count == 1 { + swiftSDK = swiftSDKs[0] + } else if swiftSDKs.count > 1, let triple = options.build.customCompileTriple, - let matchingDestination = destinations.first(where: { $0.targetTriple == triple }) + let matchingSDK = swiftSDKs.first(where: { $0.targetTriple == triple }) { - destination = matchingDestination + swiftSDK = matchingSDK } else { return .failure(SwiftSDKError.noSwiftSDKDecoded(customDestination)) } } else if let triple = options.build.customCompileTriple, - let targetDestination = Destination.defaultDestination(for: triple, host: hostDestination) + let targetSwiftSDK = SwiftSDK.defaultSwiftSDK(for: triple, hostSDK: hostSwiftSDK) { - destination = targetDestination + swiftSDK = targetSwiftSDK } else if let swiftSDKSelector = options.build.swiftSDKSelector { - destination = try SwiftSDKBundle.selectBundle( + swiftSDK = try SwiftSDKBundle.selectBundle( fromBundlesAt: sharedSwiftSDKsDirectory, fileSystem: fileSystem, matching: swiftSDKSelector, @@ -752,35 +752,35 @@ public final class SwiftTool { ) } else { // Otherwise use the host toolchain. - destination = hostDestination + swiftSDK = hostSwiftSDK } } catch { return .failure(error) } // Apply any manual overrides. if let triple = options.build.customCompileTriple { - destination.targetTriple = triple + swiftSDK.targetTriple = triple } if let binDir = options.build.customCompileToolchain { - destination.add(toolsetRootPath: binDir.appending(components: "usr", "bin")) + swiftSDK.add(toolsetRootPath: binDir.appending(components: "usr", "bin")) } if let sdk = options.build.customCompileSDK { - destination.pathsConfiguration.sdkRootPath = sdk + swiftSDK.pathsConfiguration.sdkRootPath = sdk } - destination.architectures = options.build.architectures + swiftSDK.architectures = options.build.architectures // Check if we ended up with the host toolchain. - if hostDestination == destination { + if hostSwiftSDK == swiftSDK { return self._hostToolchain } - return Result(catching: { try UserToolchain(destination: destination) }) + return Result(catching: { try UserToolchain(swiftSDK: swiftSDK) }) }() /// Lazily compute the host toolchain used to compile the package description. private lazy var _hostToolchain: Result = { return Result(catching: { - try UserToolchain(destination: Destination.hostDestination( + try UserToolchain(swiftSDK: SwiftSDK.hostSwiftSDK( originalWorkingDirectory: self.originalWorkingDirectory)) }) }() diff --git a/Sources/PackageLoading/ManifestLoader.swift b/Sources/PackageLoading/ManifestLoader.swift index bb51f2f5076..8dd05380844 100644 --- a/Sources/PackageLoading/ManifestLoader.swift +++ b/Sources/PackageLoading/ManifestLoader.swift @@ -643,9 +643,9 @@ public final class ManifestLoader: ManifestLoaderProtocol { // Use the same minimum deployment target as the PackageDescription library (with a fallback to the default host triple). #if os(macOS) if let version = self.toolchain.swiftPMLibrariesLocation.manifestLibraryMinimumDeploymentTarget?.versionString { - cmd += ["-target", "\(self.toolchain.triple.tripleString(forPlatformVersion: version))"] + cmd += ["-target", "\(self.toolchain.targetTriple.tripleString(forPlatformVersion: version))"] } else { - cmd += ["-target", self.toolchain.triple.tripleString] + cmd += ["-target", self.toolchain.targetTriple.tripleString] } #endif diff --git a/Sources/PackageModel/CMakeLists.txt b/Sources/PackageModel/CMakeLists.txt index 166fd2a78db..7874c4a3794 100644 --- a/Sources/PackageModel/CMakeLists.txt +++ b/Sources/PackageModel/CMakeLists.txt @@ -12,7 +12,6 @@ add_library(PackageModel BuildEnvironment.swift BuildFlags.swift BuildSettings.swift - Destination.swift Diagnostics.swift IdentityResolver.swift Manifest/Manifest.swift @@ -42,6 +41,7 @@ add_library(PackageModel Sources.swift SupportedLanguageExtension.swift SwiftLanguageVersion.swift + SwiftSDK.swift SwiftSDKConfigurationStore.swift SwiftSDKBundle.swift Target.swift diff --git a/Sources/PackageModel/Destination.swift b/Sources/PackageModel/SwiftSDK.swift similarity index 92% rename from Sources/PackageModel/Destination.swift rename to Sources/PackageModel/SwiftSDK.swift index 777375e1d77..657b4e18d55 100644 --- a/Sources/PackageModel/Destination.swift +++ b/Sources/PackageModel/SwiftSDK.swift @@ -29,13 +29,13 @@ public enum SwiftSDKError: Swift.Error { /// The schema version is invalid. case invalidSchemaVersion - /// Name of the destination bundle is not valid. + /// Name of the Swift SDK bundle is not valid. case invalidBundleName(String) /// No valid Swift SDKs were decoded from a metadata file. case noSwiftSDKDecoded(AbsolutePath) - /// Path used for storing destination configuration data is not a directory. + /// Path used for storing Swift SDK configuration data is not a directory. case pathIsNotDirectory(AbsolutePath) /// Swift SDK metadata couldn't be serialized with the latest serialization schema, potentially because it @@ -113,8 +113,12 @@ extension SwiftSDKError: CustomStringConvertible { } } -/// The compilation destination, has information about everything that's required for a certain destination. -public struct Destination: Equatable { +@available(*, deprecated, renamed: "SwiftSDK") +public typealias Destination = SwiftSDK + +/// Swift SDK model type which has information about everything that's required to build a SwiftPM package for a certain +/// platform. +public struct SwiftSDK: Equatable { /// The clang/LLVM triple describing the target OS and architecture. /// /// The triple has the general format ---, where: @@ -127,15 +131,15 @@ public struct Destination: Equatable { /// for more information see //https://clang.llvm.org/docs/CrossCompilation.html public var targetTriple: Triple? - /// The clang/LLVM triple describing the host platform that supports this destination. + /// The clang/LLVM triple describing the host platform that supports this Swift SDK. public let hostTriple: Triple? - // FIXME: this needs to be implemented with either multiple destinations or making ``targetTriple`` an array. + // FIXME: this needs to be implemented with either multiple Swift SDKs or making ``SwiftSDK/targetTriple`` an array. /// The architectures to build for. We build for host architecture if this is empty. public var architectures: [String]? = nil - /// Root directory path of the SDK used to compile for the destination. - @available(*, deprecated, message: "use `sdkRootDir` instead") + /// Root directory path of the SDK used to compile for the target triple. + @available(*, deprecated, message: "use `pathsConfiguration.sdkRootPath` instead") public var sdk: AbsolutePath? { get { sdkRootDir @@ -145,7 +149,7 @@ public struct Destination: Equatable { } } - /// Root directory path of the SDK used to compile for the destination. + /// Root directory path of the SDK used to compile for the target triple. @available(*, deprecated, message: "use `pathsConfiguration.sdkRootPath` instead") public var sdkRootDir: AbsolutePath? { get { @@ -198,8 +202,8 @@ public struct Destination: Equatable { ) } - /// Set of tools and their properties used for building code for this destination. While a serialized destination - /// may specify multiple toolset files, these files are consolidated into a single ``Toolset`` value during + /// Set of tools and their properties used for building code for the target triple. While a serialized Swift SDK + /// metadata may specify multiple toolset files, these files are consolidated into a single ``Toolset`` value during /// deserialization. public private(set) var toolset: Toolset @@ -220,7 +224,7 @@ public struct Destination: Equatable { self.toolsetPaths = toolsetPaths } - /// Root directory path of the SDK used to compile for the destination. + /// Root directory path of the SDK used to compile for the target triple. public var sdkRootPath: AbsolutePath? /// Path containing Swift resources for dynamic linking. @@ -430,11 +434,22 @@ public struct Destination: Equatable { } /// The destination describing the host OS. + + @available(*, deprecated, renamed: "hostSwiftSDK") public static func hostDestination( _ binDir: AbsolutePath? = nil, originalWorkingDirectory: AbsolutePath? = nil, environment: [String: String] = ProcessEnv.vars - ) throws -> Destination { + ) throws -> SwiftSDK { + try self.hostSwiftSDK(binDir, originalWorkingDirectory: originalWorkingDirectory, environment: environment) + } + + /// The Swift SDK for the host OS. + public static func hostSwiftSDK( + _ binDir: AbsolutePath? = nil, + originalWorkingDirectory: AbsolutePath? = nil, + environment: [String: String] = ProcessEnv.vars + ) throws -> SwiftSDK { let originalWorkingDirectory = originalWorkingDirectory ?? localFileSystem.currentWorkingDirectory // Select the correct binDir. if ProcessEnv.vars["SWIFTPM_CUSTOM_BINDIR"] != nil { @@ -442,7 +457,7 @@ public struct Destination: Equatable { } let customBinDir = (ProcessEnv.vars["SWIFTPM_CUSTOM_BIN_DIR"] ?? ProcessEnv.vars["SWIFTPM_CUSTOM_BINDIR"]) .flatMap { try? AbsolutePath(validating: $0) } - let binDir = try customBinDir ?? binDir ?? Destination.hostBinDir( + let binDir = try customBinDir ?? binDir ?? SwiftSDK.hostBinDir( fileSystem: localFileSystem, originalWorkingDirectory: originalWorkingDirectory ) @@ -471,7 +486,7 @@ public struct Destination: Equatable { var extraCCFlags: [String] = [] var extraSwiftCFlags: [String] = [] #if os(macOS) - let sdkPaths = try Destination.sdkPlatformFrameworkPaths(environment: environment) + let sdkPaths = try SwiftSDK.sdkPlatformFrameworkPaths(environment: environment) extraCCFlags += ["-F", sdkPaths.fwk.pathString] extraSwiftCFlags += ["-F", sdkPaths.fwk.pathString] extraSwiftCFlags += ["-I", sdkPaths.lib.pathString] @@ -482,7 +497,7 @@ public struct Destination: Equatable { extraCCFlags += ["-fPIC"] #endif - return Destination( + return SwiftSDK( toolset: .init( knownTools: [ .cCompiler: .init(extraCLIOptions: extraCCFlags), @@ -530,12 +545,13 @@ public struct Destination: Equatable { private static var _sdkPlatformFrameworkPath: (fwk: AbsolutePath, lib: AbsolutePath)? = nil /// Returns a default destination of a given target environment - public static func defaultDestination(for triple: Triple, host: Destination) -> Destination? { + @available(*, deprecated, renamed: "defaultSwiftSDK") + public static func defaultDestination(for triple: Triple, host: SwiftSDK) -> SwiftSDK? { if triple.isWASI() { let wasiSysroot = host.toolset.rootPaths.first? .parentDirectory // usr .appending(components: "share", "wasi-sysroot") - return Destination( + return SwiftSDK( targetTriple: triple, toolset: host.toolset, pathsConfiguration: .init(sdkRootPath: wasiSysroot) @@ -544,6 +560,21 @@ public struct Destination: Equatable { return nil } + /// Returns a default Swift SDK of a given target environment. + public static func defaultSwiftSDK(for targetTriple: Triple, hostSDK: SwiftSDK) -> SwiftSDK? { + if targetTriple.isWASI() { + let wasiSysroot = hostSDK.toolset.rootPaths.first? + .parentDirectory // usr + .appending(components: "share", "wasi-sysroot") + return SwiftSDK( + targetTriple: targetTriple, + toolset: hostSDK.toolset, + pathsConfiguration: .init(sdkRootPath: wasiSysroot) + ) + } + return nil + } + /// Propagates toolchain and SDK paths known to the destination to `swiftc` CLI options. public mutating func applyPathCLIOptions() { var properties = self.toolset.knownTools[.swiftCompiler] ?? .init(extraCLIOptions: []) @@ -563,13 +594,13 @@ public struct Destination: Equatable { } } -extension Destination { - /// Load a ``Destination`` description from a JSON representation from disk. +extension SwiftSDK { + /// Load a ``SwiftSDK`` description from a JSON representation from disk. public static func decode( fromFile path: AbsolutePath, fileSystem: FileSystem, observabilityScope: ObservabilityScope - ) throws -> [Destination] { + ) throws -> [SwiftSDK] { let decoder = JSONDecoder.makeWithDefaults() do { let version = try decoder.decode(path: path, fileSystem: fileSystem, as: SemanticVersionInfo.self) @@ -582,18 +613,18 @@ extension Destination { ) } catch DecodingError.keyNotFound { let version = try decoder.decode(path: path, fileSystem: fileSystem, as: VersionInfo.self) - return try [Destination(legacy: version, fromFile: path, fileSystem: fileSystem, decoder: decoder)] + return try [SwiftSDK(legacy: version, fromFile: path, fileSystem: fileSystem, decoder: decoder)] } } - /// Load a ``Destination`` description from a semantically versioned JSON representation from disk. + /// Load a ``SwiftSDK`` description from a semantically versioned JSON representation from disk. private static func decode( semanticVersion: SemanticVersionInfo, fromFile path: AbsolutePath, fileSystem: FileSystem, decoder: JSONDecoder, observabilityScope: ObservabilityScope - ) throws -> [Destination] { + ) throws -> [SwiftSDK] { switch semanticVersion.schemaVersion { case Version(3, 0, 0): let destinations = try decoder.decode(path: path, fileSystem: fileSystem, as: SerializedDestinationV3.self) @@ -613,7 +644,7 @@ extension Destination { ) } - return try Destination( + return try SwiftSDK( runTimeTriple: triple, properties: properties, toolset: toolset, @@ -639,7 +670,7 @@ extension Destination { ) } - return try Destination( + return try SwiftSDK( targetTriple: triple, properties: properties, toolset: toolset, @@ -670,13 +701,13 @@ extension Destination { ) } - /// Initialize new destination from values deserialized using v3 schema. + /// Initialize new Swift SDK from values deserialized using v3 schema. /// - Parameters: /// - runTimeTriple: triple of the machine running code built with this destination. /// - properties: properties of the destination for the given triple. /// - toolset: combined toolset used by this destination. /// - destinationDirectory: directory used for converting relative paths in `properties` to absolute paths. - init( + private init( runTimeTriple: Triple, properties: SerializedDestinationV3.TripleProperties, toolset: Toolset = .init(), @@ -689,7 +720,7 @@ extension Destination { ) } - /// Load a ``Destination`` description from a legacy JSON representation from disk. + /// Load a ``SwiftSDK`` description from a legacy JSON representation from disk. private init( legacy version: VersionInfo, fromFile path: AbsolutePath, diff --git a/Sources/PackageModel/SwiftSDKBundle.swift b/Sources/PackageModel/SwiftSDKBundle.swift index 7a85b324fee..1aa3c237240 100644 --- a/Sources/PackageModel/SwiftSDKBundle.swift +++ b/Sources/PackageModel/SwiftSDKBundle.swift @@ -20,7 +20,7 @@ import struct TSCBasic.RegEx public struct SwiftSDKBundle { public struct Variant: Equatable { let metadata: ArtifactsArchiveMetadata.Variant - let swiftSDKs: [Destination] + let swiftSDKs: [SwiftSDK] } // Path to the bundle root directory. @@ -81,7 +81,7 @@ public struct SwiftSDKBundle { matching selector: String, hostTriple: Triple, observabilityScope: ObservabilityScope - ) throws -> Destination { + ) throws -> SwiftSDK { guard let destinationsDirectory else { throw StringError( """ @@ -363,12 +363,12 @@ extension ArtifactsArchiveMetadata { } do { - let destinations = try Destination.decode( + let swiftSDKs = try SwiftSDK.decode( fromFile: variantConfigurationPath, fileSystem: fileSystem, observabilityScope: observabilityScope ) - variants.append(.init(metadata: variantMetadata, swiftSDKs: destinations)) + variants.append(.init(metadata: variantMetadata, swiftSDKs: swiftSDKs)) } catch { observabilityScope.emit( warning: "Couldn't parse Swift SDK artifact metadata at \(variantConfigurationPath)", @@ -391,7 +391,7 @@ extension [SwiftSDKBundle] { /// - hostTriple: triple of the machine on which the destination is building. /// - targetTriple: triple of the machine for which the destination is building. /// - Returns: `Destination` value with a given artifact ID, `nil` if none found. - public func selectDestination(id: String, hostTriple: Triple, targetTriple: Triple) -> Destination? { + public func selectSwiftSDK(id: String, hostTriple: Triple, targetTriple: Triple) -> SwiftSDK? { for bundle in self { for (artifactID, variants) in bundle.artifacts { guard artifactID == id else { @@ -421,9 +421,9 @@ extension [SwiftSDKBundle] { matching selector: String, hostTriple: Triple, observabilityScope: ObservabilityScope - ) -> Destination? { - var matchedByID: (path: AbsolutePath, variant: SwiftSDKBundle.Variant, destination: Destination)? - var matchedByTriple: (path: AbsolutePath, variant: SwiftSDKBundle.Variant, destination: Destination)? + ) -> SwiftSDK? { + var matchedByID: (path: AbsolutePath, variant: SwiftSDKBundle.Variant, destination: SwiftSDK)? + var matchedByTriple: (path: AbsolutePath, variant: SwiftSDKBundle.Variant, destination: SwiftSDK)? for bundle in self { for (artifactID, variants) in bundle.artifacts { diff --git a/Sources/PackageModel/SwiftSDKConfigurationStore.swift b/Sources/PackageModel/SwiftSDKConfigurationStore.swift index aee7cdae155..f9642645fe4 100644 --- a/Sources/PackageModel/SwiftSDKConfigurationStore.swift +++ b/Sources/PackageModel/SwiftSDKConfigurationStore.swift @@ -24,10 +24,10 @@ public final class SwiftSDKConfigurationStore { /// `~/.swiftpm/swift-sdks` or a directory to which `~/.swiftpm/swift-sdks` symlinks to. private let swiftSDKsDirectoryPath: AbsolutePath - /// Path to the directory in which destination configuration files are stored. + /// Path to the directory in which Swift SDK configuration files are stored. private let configurationDirectoryPath: AbsolutePath - /// File system that stores destination configuration and contains + /// File system that stores Swift SDK configuration and contains /// ``SwiftSDKConfigurationStore//configurationDirectoryPath``. private let fileSystem: FileSystem @@ -75,9 +75,9 @@ public final class SwiftSDKConfigurationStore { public func updateConfiguration( sdkID: String, - destination: Destination + swiftSDK: SwiftSDK ) throws { - let (targetTriple, properties) = try destination.serialized + let (targetTriple, properties) = try swiftSDK.serialized let configurationPath = configurationDirectoryPath.appending( component: "\(sdkID)_\(targetTriple).json" @@ -88,22 +88,22 @@ public final class SwiftSDKConfigurationStore { public func readConfiguration( sdkID: String, - targetTriple triple: Triple - ) throws -> Destination? { + targetTriple: Triple + ) throws -> SwiftSDK? { let configurationPath = configurationDirectoryPath.appending( - component: "\(sdkID)_\(triple.tripleString).json" + component: "\(sdkID)_\(targetTriple.tripleString).json" ) - let destinationBundles = try SwiftSDKBundle.getAllValidBundles( + let swiftSDKs = try SwiftSDKBundle.getAllValidBundles( swiftSDKsDirectory: swiftSDKsDirectoryPath, fileSystem: fileSystem, observabilityScope: observabilityScope ) - guard var destination = destinationBundles.selectDestination( + guard var swiftSDK = swiftSDKs.selectSwiftSDK( id: sdkID, hostTriple: hostTriple, - targetTriple: triple + targetTriple: targetTriple ) else { return nil } @@ -115,20 +115,20 @@ public final class SwiftSDKConfigurationStore { as: SwiftSDKMetadataV4.TripleProperties.self ) - destination.pathsConfiguration.merge( - with: try Destination( - targetTriple: triple, + swiftSDK.pathsConfiguration.merge( + with: try SwiftSDK( + targetTriple: targetTriple, properties: properties ).pathsConfiguration ) } - return destination + return swiftSDK } - /// Resets configuration for identified destination triple. + /// Resets configuration for identified target triple. /// - Parameters: - /// - destinationID: ID of the destination to operate on. + /// - sdkID: ID of the Swift SDK to operate on. /// - tripleString: run-time triple for which the properties should be reset. /// - Returns: `true` if custom configuration was successfully removed, `false` if no custom configuration existed. public func resetConfiguration( diff --git a/Sources/PackageModel/UserToolchain.swift b/Sources/PackageModel/UserToolchain.swift index 4ca422cc133..1f83666728b 100644 --- a/Sources/PackageModel/UserToolchain.swift +++ b/Sources/PackageModel/UserToolchain.swift @@ -49,12 +49,19 @@ public final class UserToolchain: Toolchain { } /// The compilation destination object. - public let destination: Destination + @available(*, deprecated, renamed: "swiftSDK") + public var destination: SwiftSDK { swiftSDK } + + /// The Swift SDK used by this toolchain. + public let swiftSDK: SwiftSDK /// The target triple that should be used for compilation. - public let triple: Triple + @available(*, deprecated, renamed: "targetTriple") + public var triple: Triple { targetTriple } + + public let targetTriple: Triple - /// The list of archs to build for. + /// The list of CPU architectures to build for. public let architectures: [String]? /// Search paths from the PATH environment variable. @@ -252,7 +259,7 @@ public final class UserToolchain: Toolchain { // Then, check the toolchain. do { - if let toolPath = try? UserToolchain.getTool("clang", binDirectories: self.destination.toolset.rootPaths) { + if let toolPath = try? UserToolchain.getTool("clang", binDirectories: self.swiftSDK.toolset.rootPaths) { self._clangCompiler = toolPath return toolPath } @@ -318,12 +325,12 @@ public final class UserToolchain: Toolchain { internal static func deriveSwiftCFlags( triple: Triple, - destination: Destination, + swiftSDK: SwiftSDK, environment: EnvironmentVariables ) throws -> [String] { - let swiftCompilerFlags = destination.toolset.knownTools[.swiftCompiler]?.extraCLIOptions ?? [] + let swiftCompilerFlags = swiftSDK.toolset.knownTools[.swiftCompiler]?.extraCLIOptions ?? [] - guard let sdkDir = destination.pathsConfiguration.sdkRootPath else { + guard let sdkDir = swiftSDK.pathsConfiguration.sdkRootPath else { if triple.isWindows() { // Windows uses a variable named SDKROOT to determine the root of // the SDK. This is not the same value as the SDKROOT parameter @@ -430,13 +437,28 @@ public final class UserToolchain: Toolchain { case custom(searchPaths: [AbsolutePath], useXcrun: Bool = true) } + @available(*, deprecated, message: "use init(swiftSDK:environment:searchStrategy:customLibrariesLocation) instead") + public convenience init( + destination: SwiftSDK, + environment: EnvironmentVariables = .process(), + searchStrategy: SearchStrategy = .default, + customLibrariesLocation: ToolchainConfiguration.SwiftPMLibrariesLocation? = nil + ) throws { + try self.init( + swiftSDK: destination, + environment: environment, + searchStrategy: searchStrategy, + customLibrariesLocation: customLibrariesLocation + ) + } + public init( - destination: Destination, + swiftSDK: SwiftSDK, environment: EnvironmentVariables = .process(), searchStrategy: SearchStrategy = .default, customLibrariesLocation: ToolchainConfiguration.SwiftPMLibrariesLocation? = nil ) throws { - self.destination = destination + self.swiftSDK = swiftSDK self.environment = environment switch searchStrategy { @@ -453,13 +475,13 @@ public final class UserToolchain: Toolchain { } let swiftCompilers = try UserToolchain.determineSwiftCompilers( - binDirectories: destination.toolset.rootPaths, + binDirectories: swiftSDK.toolset.rootPaths, useXcrun: useXcrun, environment: environment, searchPaths: envSearchPaths ) self.swiftCompilerPath = swiftCompilers.compile - self.architectures = destination.architectures + self.architectures = swiftSDK.architectures #if canImport(Darwin) let toolchainPlistPath = self.swiftCompilerPath.parentDirectory.parentDirectory.parentDirectory @@ -478,7 +500,7 @@ public final class UserToolchain: Toolchain { #endif // Use the triple from destination or compute the host triple using swiftc. - var triple = try destination.targetTriple ?? Triple.getHostTriple(usingSwiftCompiler: swiftCompilers.compile) + var triple = try swiftSDK.targetTriple ?? Triple.getHostTriple(usingSwiftCompiler: swiftCompilers.compile) // Change the triple to the specified arch if there's exactly one of them. // The Triple property is only looked at by the native build system currently. @@ -487,31 +509,31 @@ public final class UserToolchain: Toolchain { triple = try Triple(architectures[0] + components) } - self.triple = triple + self.targetTriple = triple self.extraFlags = BuildFlags( - cCompilerFlags: destination.toolset.knownTools[.cCompiler]?.extraCLIOptions ?? [], - cxxCompilerFlags: destination.toolset.knownTools[.cxxCompiler]?.extraCLIOptions ?? [], + cCompilerFlags: swiftSDK.toolset.knownTools[.cCompiler]?.extraCLIOptions ?? [], + cxxCompilerFlags: swiftSDK.toolset.knownTools[.cxxCompiler]?.extraCLIOptions ?? [], swiftCompilerFlags: try Self.deriveSwiftCFlags( triple: triple, - destination: destination, + swiftSDK: swiftSDK, environment: environment), - linkerFlags: destination.toolset.knownTools[.linker]?.extraCLIOptions ?? [], - xcbuildFlags: destination.toolset.knownTools[.xcbuild]?.extraCLIOptions ?? []) + linkerFlags: swiftSDK.toolset.knownTools[.linker]?.extraCLIOptions ?? [], + xcbuildFlags: swiftSDK.toolset.knownTools[.xcbuild]?.extraCLIOptions ?? []) - self.includeSearchPaths = destination.pathsConfiguration.includeSearchPaths ?? [] - self.librarySearchPaths = destination.pathsConfiguration.includeSearchPaths ?? [] + self.includeSearchPaths = swiftSDK.pathsConfiguration.includeSearchPaths ?? [] + self.librarySearchPaths = swiftSDK.pathsConfiguration.includeSearchPaths ?? [] self.librarianPath = try destination.toolset.knownTools[.librarian]?.path ?? UserToolchain.determineLibrarian( triple: triple, - binDirectories: destination.toolset.rootPaths, + binDirectories: swiftSDK.toolset.rootPaths, useXcrun: useXcrun, environment: environment, searchPaths: envSearchPaths, extraSwiftFlags: self.extraFlags.swiftCompilerFlags ) - if let sdkDir = destination.pathsConfiguration.sdkRootPath { + if let sdkDir = swiftSDK.pathsConfiguration.sdkRootPath { let sysrootFlags = [triple.isDarwin() ? "-isysroot" : "--sysroot", sdkDir.pathString] self.extraFlags.cCompilerFlags.insert(contentsOf: sysrootFlags, at: 0) } @@ -556,7 +578,7 @@ public final class UserToolchain: Toolchain { let swiftPMLibrariesLocation = try customLibrariesLocation ?? Self.deriveSwiftPMLibrariesLocation( swiftCompilerPath: swiftCompilerPath, - destination: destination, + swiftSDK: swiftSDK, environment: environment ) @@ -568,7 +590,7 @@ public final class UserToolchain: Toolchain { } else { swiftPluginServerPath = try Self.derivePluginServerPath(triple: triple) xctestPath = try Self.deriveXCTestPath( - destination: self.destination, + swiftSDK: self.swiftSDK, triple: triple, environment: environment ) @@ -580,7 +602,7 @@ public final class UserToolchain: Toolchain { swiftCompilerFlags: self.extraFlags.swiftCompilerFlags, swiftCompilerEnvironment: environment, swiftPMLibrariesLocation: swiftPMLibrariesLocation, - sdkRootPath: self.destination.pathsConfiguration.sdkRootPath, + sdkRootPath: self.swiftSDK.pathsConfiguration.sdkRootPath, xctestPath: xctestPath, swiftPluginServerPath: swiftPluginServerPath ) @@ -588,7 +610,7 @@ public final class UserToolchain: Toolchain { private static func deriveSwiftPMLibrariesLocation( swiftCompilerPath: AbsolutePath, - destination: Destination, + swiftSDK: SwiftSDK, environment: EnvironmentVariables ) throws -> ToolchainConfiguration.SwiftPMLibrariesLocation? { // Look for an override in the env. @@ -621,7 +643,7 @@ public final class UserToolchain: Toolchain { // an alternative cloud be to force explicit locations to always be set explicitly when running in Xcode/SwiftPM // debug and assert if not set but we detect that we are in this mode - for applicationPath in destination.toolset.rootPaths { + for applicationPath in swiftSDK.toolset.rootPaths { // this is the normal case when using the toolchain let librariesPath = applicationPath.parentDirectory.appending(components: "lib", "swift", "pm") if localFileSystem.exists(librariesPath) { @@ -667,7 +689,7 @@ public final class UserToolchain: Toolchain { // TODO: We should have some general utility to find tools. private static func deriveXCTestPath( - destination: Destination, + swiftSDK: SwiftSDK, triple: Triple, environment: EnvironmentVariables ) throws -> AbsolutePath? { @@ -682,7 +704,7 @@ public final class UserToolchain: Toolchain { } else if triple.isWindows() { let sdkRoot: AbsolutePath - if let sdkDir = destination.pathsConfiguration.sdkRootPath { + if let sdkDir = swiftSDK.pathsConfiguration.sdkRootPath { sdkRoot = sdkDir } else if let SDKROOT = environment["SDKROOT"], let sdkDir = try? AbsolutePath(validating: SDKROOT) { sdkRoot = sdkDir diff --git a/Sources/SPMBuildCore/BuildParameters.swift b/Sources/SPMBuildCore/BuildParameters.swift index 039d9715200..92259b9a97a 100644 --- a/Sources/SPMBuildCore/BuildParameters.swift +++ b/Sources/SPMBuildCore/BuildParameters.swift @@ -163,8 +163,15 @@ public struct BuildParameters: Encodable { /// Host triple. public var hostTriple: Triple - /// Destination triple. - public var triple: Triple + /// Target triple. + @available(*, deprecated, renamed: "targetTriple") + public var triple: Triple { + get { targetTriple } + set { targetTriple = newValue } + } + + /// Target triple. + public var targetTriple: Triple /// Extra build flags. public var flags: BuildFlags @@ -226,15 +233,15 @@ public struct BuildParameters: Encodable { /// The current platform we're building for. var currentPlatform: PackageModel.Platform { - if self.triple.isDarwin() { + if self.targetTriple.isDarwin() { return .macOS - } else if self.triple.isAndroid() { + } else if self.targetTriple.isAndroid() { return .android - } else if self.triple.isWASI() { + } else if self.targetTriple.isWASI() { return .wasi - } else if self.triple.isWindows() { + } else if self.targetTriple.isWindows() { return .windows - } else if self.triple.isOpenBSD() { + } else if self.targetTriple.isOpenBSD() { return .openbsd } else { return .linux @@ -261,6 +268,7 @@ public struct BuildParameters: Encodable { public var debugInfoFormat: DebugInfoFormat + @available(*, deprecated, message: "use `init` overload with `targetTriple` parameter name instead") public init( dataPath: AbsolutePath, configuration: BuildConfiguration, @@ -293,26 +301,92 @@ public struct BuildParameters: Encodable { linkTimeOptimizationMode: LinkTimeOptimizationMode? = nil, debugInfoFormat: DebugInfoFormat = .dwarf ) throws { - let triple = try destinationTriple ?? .getHostTriple(usingSwiftCompiler: toolchain.swiftCompilerPath) + try self.init( + dataPath: dataPath, + configuration: configuration, + toolchain: toolchain, + hostTriple: hostTriple, + targetTriple: destinationTriple, + flags: flags, + pkgConfigDirectories: pkgConfigDirectories, + architectures: architectures, + workers: workers, + shouldLinkStaticSwiftStdlib: shouldLinkStaticSwiftStdlib, + shouldEnableManifestCaching: shouldEnableManifestCaching, + canRenameEntrypointFunctionName: canRenameEntrypointFunctionName, + shouldCreateDylibForDynamicProducts: shouldCreateDylibForDynamicProducts, + sanitizers: sanitizers, + enableCodeCoverage: enableCodeCoverage, + indexStoreMode: indexStoreMode, + enableParseableModuleInterfaces: enableParseableModuleInterfaces, + emitSwiftModuleSeparately: emitSwiftModuleSeparately, + useIntegratedSwiftDriver: useIntegratedSwiftDriver, + useExplicitModuleBuild: useExplicitModuleBuild, + isXcodeBuildSystemEnabled: isXcodeBuildSystemEnabled, + enableTestability: enableTestability, + forceTestDiscovery: forceTestDiscovery, + testEntryPointPath: testEntryPointPath, + explicitTargetDependencyImportCheckingMode: explicitTargetDependencyImportCheckingMode, + linkerDeadStrip: linkerDeadStrip, + colorizedOutput: colorizedOutput, + verboseOutput: verboseOutput, + linkTimeOptimizationMode: linkTimeOptimizationMode, + debugInfoFormat: debugInfoFormat + ) + } + + public init( + dataPath: AbsolutePath, + configuration: BuildConfiguration, + toolchain: Toolchain, + hostTriple: Triple? = nil, + targetTriple: Triple? = nil, + flags: BuildFlags, + pkgConfigDirectories: [AbsolutePath] = [], + architectures: [String]? = nil, + workers: UInt32 = UInt32(ProcessInfo.processInfo.activeProcessorCount), + shouldLinkStaticSwiftStdlib: Bool = false, + shouldEnableManifestCaching: Bool = false, + canRenameEntrypointFunctionName: Bool = false, + shouldCreateDylibForDynamicProducts: Bool = true, + sanitizers: EnabledSanitizers = EnabledSanitizers(), + enableCodeCoverage: Bool = false, + indexStoreMode: IndexStoreMode = .auto, + enableParseableModuleInterfaces: Bool = false, + emitSwiftModuleSeparately: Bool = false, + useIntegratedSwiftDriver: Bool = false, + useExplicitModuleBuild: Bool = false, + isXcodeBuildSystemEnabled: Bool = false, + enableTestability: Bool? = nil, + forceTestDiscovery: Bool = false, + testEntryPointPath: AbsolutePath? = nil, + explicitTargetDependencyImportCheckingMode: TargetDependencyImportCheckingMode = .none, + linkerDeadStrip: Bool = true, + colorizedOutput: Bool = false, + verboseOutput: Bool = false, + linkTimeOptimizationMode: LinkTimeOptimizationMode? = nil, + debugInfoFormat: DebugInfoFormat = .dwarf + ) throws { + let targetTriple = try targetTriple ?? .getHostTriple(usingSwiftCompiler: toolchain.swiftCompilerPath) self.dataPath = dataPath self.configuration = configuration self._toolchain = _Toolchain(toolchain: toolchain) self.hostTriple = try hostTriple ?? .getHostTriple(usingSwiftCompiler: toolchain.swiftCompilerPath) - self.triple = triple + self.targetTriple = targetTriple switch debugInfoFormat { case .dwarf: var flags = flags // DWARF requires lld as link.exe expects CodeView debug info. - self.flags = flags.merging(triple.isWindows() ? BuildFlags( + self.flags = flags.merging(targetTriple.isWindows() ? BuildFlags( cCompilerFlags: ["-gdwarf"], cxxCompilerFlags: ["-gdwarf"], swiftCompilerFlags: ["-g", "-use-ld=lld"], linkerFlags: ["-debug:dwarf"] ) : BuildFlags(cCompilerFlags: ["-g"], cxxCompilerFlags: ["-g"], swiftCompilerFlags: ["-g"])) case .codeview: - if !triple.isWindows() { - throw StringError("CodeView debug information is currently not supported on \(triple.osName)") + if !targetTriple.isWindows() { + throw StringError("CodeView debug information is currently not supported on \(targetTriple.osName)") } var flags = flags self.flags = flags.merging(BuildFlags( @@ -345,7 +419,7 @@ public struct BuildParameters: Encodable { // when building and testing in release mode, one can use the '--disable-testable-imports' flag // to disable testability in `swift test`, but that requires that the tests do not use the testable imports feature self.enableTestability = enableTestability ?? (.debug == configuration) - self.testProductStyle = triple.isDarwin() ? .loadableBundle : .entryPointExecutable( + self.testProductStyle = targetTriple.isDarwin() ? .loadableBundle : .entryPointExecutable( explicitlyEnabledDiscovery: forceTestDiscovery, explicitlySpecifiedPath: testEntryPointPath ) @@ -357,7 +431,12 @@ public struct BuildParameters: Encodable { self.debugInfoFormat = debugInfoFormat } + @available(*, deprecated, renamed: "forTriple()") public func withDestination(_ destinationTriple: Triple) throws -> BuildParameters { + try self.forTriple(destinationTriple) + } + + public func forTriple(_ targetTriple: Triple) throws -> BuildParameters { let forceTestDiscovery: Bool let testEntryPointPath: AbsolutePath? switch self.testProductStyle { @@ -372,9 +451,9 @@ public struct BuildParameters: Encodable { return try .init( dataPath: self.dataPath.parentDirectory.appending(components: ["plugins", "tools"]), configuration: self.configuration, - toolchain: try UserToolchain(destination: Destination.hostDestination()), + toolchain: try UserToolchain(swiftSDK: SwiftSDK.hostSwiftSDK()), hostTriple: self.hostTriple, - destinationTriple: destinationTriple, + targetTriple: targetTriple, flags: BuildFlags(), pkgConfigDirectories: self.pkgConfigDirectories, architectures: nil, @@ -445,7 +524,7 @@ public struct BuildParameters: Encodable { return nil } - if triple.isApple() { + if targetTriple.isApple() { return .swiftAST } return .modulewrap @@ -458,29 +537,29 @@ public struct BuildParameters: Encodable { /// Returns the path to the dynamic library of a product for the current build parameters. func potentialDynamicLibraryPath(for product: ResolvedProduct) throws -> RelativePath { - try RelativePath(validating: "\(triple.dynamicLibraryPrefix)\(product.name)\(triple.dynamicLibraryExtension)") + try RelativePath(validating: "\(targetTriple.dynamicLibraryPrefix)\(product.name)\(targetTriple.dynamicLibraryExtension)") } /// Returns the path to the binary of a product for the current build parameters, relative to the build directory. public func binaryRelativePath(for product: ResolvedProduct) throws -> RelativePath { - let potentialExecutablePath = try RelativePath(validating: "\(product.name)\(triple.executableExtension)") + let potentialExecutablePath = try RelativePath(validating: "\(product.name)\(targetTriple.executableExtension)") switch product.type { case .executable, .snippet: return potentialExecutablePath case .library(.static): - return try RelativePath(validating: "lib\(product.name)\(triple.staticLibraryExtension)") + return try RelativePath(validating: "lib\(product.name)\(targetTriple.staticLibraryExtension)") case .library(.dynamic): return try potentialDynamicLibraryPath(for: product) case .library(.automatic), .plugin: fatalError() case .test: - guard !triple.isWASI() else { + guard !targetTriple.isWASI() else { return try RelativePath(validating: "\(product.name).wasm") } let base = "\(product.name).xctest" - if triple.isDarwin() { + if targetTriple.isDarwin() { return try RelativePath(validating: "\(base)/Contents/MacOS/\(product.name)") } else { return try RelativePath(validating: base) diff --git a/Sources/SPMTestSupport/Toolchain.swift b/Sources/SPMTestSupport/Toolchain.swift index 3861f5c5c36..ebadbd417e1 100644 --- a/Sources/SPMTestSupport/Toolchain.swift +++ b/Sources/SPMTestSupport/Toolchain.swift @@ -37,11 +37,11 @@ private func resolveBinDir() throws -> AbsolutePath { #endif } -extension Destination { +extension SwiftSDK { public static var `default`: Self { get throws { let binDir = try resolveBinDir() - return try! Destination.hostDestination(binDir) + return try! SwiftSDK.hostSwiftSDK(binDir) } } } @@ -49,7 +49,7 @@ extension Destination { extension UserToolchain { public static var `default`: Self { get throws { - return try .init(destination: Destination.default) + return try .init(swiftSDK: SwiftSDK.default) } } } diff --git a/Sources/SwiftSDKTool/Configuration/ConfigurationSubcommand.swift b/Sources/SwiftSDKTool/Configuration/ConfigurationSubcommand.swift index 7edf1557262..d4984b5c21d 100644 --- a/Sources/SwiftSDKTool/Configuration/ConfigurationSubcommand.swift +++ b/Sources/SwiftSDKTool/Configuration/ConfigurationSubcommand.swift @@ -34,7 +34,7 @@ protocol ConfigurationSubcommand: SwiftSDKSubcommand { func run( hostTriple: Triple, targetTriple: Triple, - _ destination: Destination, + _ destination: SwiftSDK, _ configurationStore: SwiftSDKConfigurationStore, _ swiftSDKsDirectory: AbsolutePath, _ observabilityScope: ObservabilityScope diff --git a/Sources/SwiftSDKTool/Configuration/ResetConfiguration.swift b/Sources/SwiftSDKTool/Configuration/ResetConfiguration.swift index 1331afc72e2..1db853ff0b6 100644 --- a/Sources/SwiftSDKTool/Configuration/ResetConfiguration.swift +++ b/Sources/SwiftSDKTool/Configuration/ResetConfiguration.swift @@ -59,7 +59,7 @@ struct ResetConfiguration: ConfigurationSubcommand { func run( hostTriple: Triple, targetTriple: Triple, - _ destination: Destination, + _ destination: SwiftSDK, _ configurationStore: SwiftSDKConfigurationStore, _ destinationsDirectory: AbsolutePath, _ observabilityScope: ObservabilityScope @@ -120,7 +120,7 @@ struct ResetConfiguration: ConfigurationSubcommand { } else { var destination = destination destination.pathsConfiguration = configuration - try configurationStore.updateConfiguration(sdkID: sdkID, destination: destination) + try configurationStore.updateConfiguration(sdkID: sdkID, swiftSDK: destination) observabilityScope.emit( info: """ diff --git a/Sources/SwiftSDKTool/Configuration/SetConfiguration.swift b/Sources/SwiftSDKTool/Configuration/SetConfiguration.swift index 5663e6705d6..c7a95c4c473 100644 --- a/Sources/SwiftSDKTool/Configuration/SetConfiguration.swift +++ b/Sources/SwiftSDKTool/Configuration/SetConfiguration.swift @@ -75,7 +75,7 @@ struct SetConfiguration: ConfigurationSubcommand { func run( hostTriple: Triple, targetTriple: Triple, - _ destination: Destination, + _ destination: SwiftSDK, _ configurationStore: SwiftSDKConfigurationStore, _ destinationsDirectory: AbsolutePath, _ observabilityScope: ObservabilityScope @@ -132,7 +132,7 @@ struct SetConfiguration: ConfigurationSubcommand { var destination = destination destination.pathsConfiguration = configuration - try configurationStore.updateConfiguration(sdkID: sdkID, destination: destination) + try configurationStore.updateConfiguration(sdkID: sdkID, swiftSDK: destination) observabilityScope.emit( info: """ diff --git a/Sources/SwiftSDKTool/Configuration/ShowConfiguration.swift b/Sources/SwiftSDKTool/Configuration/ShowConfiguration.swift index d1ef8bbccf6..c9cda18d7b9 100644 --- a/Sources/SwiftSDKTool/Configuration/ShowConfiguration.swift +++ b/Sources/SwiftSDKTool/Configuration/ShowConfiguration.swift @@ -40,7 +40,7 @@ struct ShowConfiguration: ConfigurationSubcommand { func run( hostTriple: Triple, targetTriple: Triple, - _ destination: Destination, + _ destination: SwiftSDK, _ configurationStore: SwiftSDKConfigurationStore, _ destinationsDirectory: AbsolutePath, _ observabilityScope: ObservabilityScope @@ -49,7 +49,7 @@ struct ShowConfiguration: ConfigurationSubcommand { } } -extension Destination.PathsConfiguration: CustomStringConvertible { +extension SwiftSDK.PathsConfiguration: CustomStringConvertible { public var description: String { """ sdkRootPath: \(sdkRootPath.configurationString) diff --git a/Sources/SwiftSDKTool/SwiftSDKSubcommand.swift b/Sources/SwiftSDKTool/SwiftSDKSubcommand.swift index 8b4b45d1bf3..26b2b111505 100644 --- a/Sources/SwiftSDKTool/SwiftSDKSubcommand.swift +++ b/Sources/SwiftSDKTool/SwiftSDKSubcommand.swift @@ -65,7 +65,7 @@ extension SwiftSDKSubcommand { let observabilityScope = observabilitySystem.topScope let destinationsDirectory = try self.getOrCreateDestinationsDirectory() - let hostToolchain = try UserToolchain(destination: Destination.hostDestination()) + let hostToolchain = try UserToolchain(swiftSDK: SwiftSDK.hostSwiftSDK()) let triple = try Triple.getHostTriple(usingSwiftCompiler: hostToolchain.swiftCompilerPath) var commandError: Error? = nil diff --git a/Sources/Workspace/DefaultPluginScriptRunner.swift b/Sources/Workspace/DefaultPluginScriptRunner.swift index bf6da4b2103..5a6c2acdf97 100644 --- a/Sources/Workspace/DefaultPluginScriptRunner.swift +++ b/Sources/Workspace/DefaultPluginScriptRunner.swift @@ -107,7 +107,7 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable { } public var hostTriple: Triple { - return self.toolchain.triple + return self.toolchain.targetTriple } /// Starts compiling a plugin script asynchronously and when done, calls the completion handler on the callback queue with the results (including the path of the compiled plugin executable and with any emitted diagnostics, etc). Existing compilation results that are still valid are reused, if possible. This function itself returns immediately after starting the compile. Note that the completion handler only receives a `.failure` result if the compiler couldn't be invoked at all; a non-zero exit code from the compiler still returns `.success` with a full compilation result that notes the error in the diagnostics (in other words, a `.failure` result only means "failure to invoke the compiler"). @@ -177,9 +177,9 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable { // Use the same minimum deployment target as the PackagePlugin library (with a fallback to the default host triple). #if os(macOS) if let version = self.toolchain.swiftPMLibrariesLocation.pluginLibraryMinimumDeploymentTarget?.versionString { - commandLine += ["-target", "\(self.toolchain.triple.tripleString(forPlatformVersion: version))"] + commandLine += ["-target", "\(self.toolchain.targetTriple.tripleString(forPlatformVersion: version))"] } else { - commandLine += ["-target", self.toolchain.triple.tripleString] + commandLine += ["-target", self.toolchain.targetTriple.tripleString] } #endif diff --git a/Sources/Workspace/Workspace+BinaryArtifacts.swift b/Sources/Workspace/Workspace+BinaryArtifacts.swift index 13c5be1198f..e3bd82d2d32 100644 --- a/Sources/Workspace/Workspace+BinaryArtifacts.swift +++ b/Sources/Workspace/Workspace+BinaryArtifacts.swift @@ -174,11 +174,11 @@ extension Workspace { guard let supportedArchive = metadata.archives .first(where: { $0.fileName.lowercased().hasSuffix(".zip") && $0.supportedTriples - .contains(self.hostToolchain.triple) + .contains(self.hostToolchain.targetTriple) }) else { throw StringError( - "No supported archive was found for '\(self.hostToolchain.triple.tripleString)'" + "No supported archive was found for '\(self.hostToolchain.targetTriple.tripleString)'" ) } // add relevant archive diff --git a/Sources/Workspace/Workspace.swift b/Sources/Workspace/Workspace.swift index 46f58307467..93a8d4c58f9 100644 --- a/Sources/Workspace/Workspace.swift +++ b/Sources/Workspace/Workspace.swift @@ -629,7 +629,7 @@ public class Workspace { let location = try location.validatingSharedLocations(fileSystem: fileSystem, warningHandler: initializationWarningHandler) let currentToolsVersion = customToolsVersion ?? ToolsVersion.current - let hostToolchain = try customHostToolchain ?? UserToolchain(destination: .hostDestination()) + let hostToolchain = try customHostToolchain ?? UserToolchain(swiftSDK: .hostSwiftSDK()) var manifestLoader = customManifestLoader ?? ManifestLoader( toolchain: hostToolchain, cacheDir: location.sharedManifestsCacheDirectory, diff --git a/Sources/XCBuildSupport/XcodeBuildSystem.swift b/Sources/XCBuildSupport/XcodeBuildSystem.swift index 0d9564f0a2e..1bc6e9f21a7 100644 --- a/Sources/XCBuildSupport/XcodeBuildSystem.swift +++ b/Sources/XCBuildSupport/XcodeBuildSystem.swift @@ -184,7 +184,7 @@ public final class XcodeBuildSystem: SPMBuildCore.BuildSystem { platform: "macosx", sdk: "macosx", sdkVariant: nil, - targetArchitecture: buildParameters.triple.archName, + targetArchitecture: buildParameters.targetTriple.archName, supportedArchitectures: [], disableOnlyActiveArch: true ) diff --git a/Sources/swift-bootstrap/main.swift b/Sources/swift-bootstrap/main.swift index a7cdb1e3da3..6f922b0869c 100644 --- a/Sources/swift-bootstrap/main.swift +++ b/Sources/swift-bootstrap/main.swift @@ -187,7 +187,7 @@ struct SwiftBootstrapBuildTool: ParsableCommand { struct Builder { let identityResolver: IdentityResolver let hostToolchain: UserToolchain - let destinationToolchain: UserToolchain + let targetToolchain: UserToolchain let fileSystem: FileSystem let observabilityScope: ObservabilityScope let logLevel: Basics.Diagnostic.Severity @@ -203,8 +203,8 @@ struct SwiftBootstrapBuildTool: ParsableCommand { } self.identityResolver = DefaultIdentityResolver() - self.hostToolchain = try UserToolchain(destination: Destination.hostDestination(originalWorkingDirectory: cwd)) - self.destinationToolchain = hostToolchain // TODO: support destinations? + self.hostToolchain = try UserToolchain(swiftSDK: SwiftSDK.hostSwiftSDK(originalWorkingDirectory: cwd)) + self.targetToolchain = hostToolchain // TODO: support cross-compilation? self.fileSystem = fileSystem self.observabilityScope = observabilityScope self.logLevel = logLevel @@ -250,15 +250,15 @@ struct SwiftBootstrapBuildTool: ParsableCommand { buildFlags.swiftCompilerFlags += Self.additionalSwiftBuildFlags let dataPath = scratchDirectory.appending( - component: self.destinationToolchain.triple.platformBuildPathComponent(buildSystem: buildSystem) + component: self.targetToolchain.targetTriple.platformBuildPathComponent(buildSystem: buildSystem) ) let buildParameters = try BuildParameters( dataPath: dataPath, configuration: configuration, - toolchain: self.destinationToolchain, - hostTriple: self.hostToolchain.triple, - destinationTriple: self.destinationToolchain.triple, + toolchain: self.targetToolchain, + hostTriple: self.hostToolchain.targetTriple, + targetTriple: self.targetToolchain.targetTriple, flags: buildFlags, architectures: architectures, useIntegratedSwiftDriver: useIntegratedSwiftDriver, diff --git a/Tests/BuildTests/BuildPlanTests.swift b/Tests/BuildTests/BuildPlanTests.swift index ef3f36c56f4..d4b9cc76bf6 100644 --- a/Tests/BuildTests/BuildPlanTests.swift +++ b/Tests/BuildTests/BuildPlanTests.swift @@ -758,7 +758,7 @@ final class BuildPlanTests: XCTestCase { buildPath: buildDirPath, config: .release, toolchain: UserToolchain.default, - destinationTriple: UserToolchain.default.triple, + targetTriple: UserToolchain.default.targetTriple, useExplicitModuleBuild: true ), graph: graph, @@ -2217,7 +2217,7 @@ final class BuildPlanTests: XCTestCase { // Verify that `-lstdc++` is passed instead of `-lc++` when cross-compiling to Linux. result = try BuildPlanResult(plan: BuildPlan( - buildParameters: mockBuildParameters(destinationTriple: .arm64Linux), + buildParameters: mockBuildParameters(targetTriple: .arm64Linux), graph: graph, fileSystem: fs, observabilityScope: observability.topScope @@ -2491,7 +2491,7 @@ final class BuildPlanTests: XCTestCase { result.checkProductsCount(2) result.checkTargetsCount(2) - let triple = result.plan.buildParameters.triple + let triple = result.plan.buildParameters.targetTriple let buildPath = result.plan.buildParameters.dataPath.appending(components: "debug") let exe = try result.target(for: "exe").clangTarget() @@ -2960,7 +2960,7 @@ final class BuildPlanTests: XCTestCase { XCTAssertNoDiagnostics(observability.diagnostics) let result = try BuildPlanResult(plan: BuildPlan( - buildParameters: mockBuildParameters(destinationTriple: .windows), + buildParameters: mockBuildParameters(targetTriple: .windows), graph: graph, fileSystem: fs, observabilityScope: observability.topScope @@ -3038,7 +3038,7 @@ final class BuildPlanTests: XCTestCase { ) XCTAssertNoDiagnostics(observability.diagnostics) - var parameters = mockBuildParameters(destinationTriple: .wasi) + var parameters = mockBuildParameters(targetTriple: .wasi) parameters.shouldLinkStaticSwiftStdlib = true let result = try BuildPlanResult(plan: BuildPlan( buildParameters: parameters, @@ -3135,7 +3135,7 @@ final class BuildPlanTests: XCTestCase { func createResult(for triple: Basics.Triple) throws -> BuildPlanResult { try BuildPlanResult(plan: BuildPlan( - buildParameters: mockBuildParameters(canRenameEntrypointFunctionName: true, destinationTriple: triple), + buildParameters: mockBuildParameters(canRenameEntrypointFunctionName: true, targetTriple: triple), graph: graph, fileSystem: fs, observabilityScope: observability.topScope @@ -3315,7 +3315,7 @@ final class BuildPlanTests: XCTestCase { XCTAssertThrows(Diagnostics.fatalError) { _ = try BuildPlan( - buildParameters: mockBuildParameters(destinationTriple: .x86_64MacOS), + buildParameters: mockBuildParameters(targetTriple: .x86_64MacOS), graph: graph, fileSystem: fileSystem, observabilityScope: observability.topScope @@ -3427,7 +3427,7 @@ final class BuildPlanTests: XCTestCase { func createResult(for dest: Basics.Triple) throws -> BuildPlanResult { return try BuildPlanResult(plan: BuildPlan( - buildParameters: mockBuildParameters(destinationTriple: dest), + buildParameters: mockBuildParameters(targetTriple: dest), graph: graph, fileSystem: fs, observabilityScope: observability.topScope @@ -3532,17 +3532,17 @@ final class BuildPlanTests: XCTestCase { ) XCTAssertNoDiagnostics(observability.diagnostics) - let userDestination = Destination( + let userSwiftSDK = SwiftSDK( toolset: .init( knownTools: [ .cCompiler: .init(extraCLIOptions: ["-I/fake/sdk/sysroot", "-clang-flag-from-json"]), .swiftCompiler: .init(extraCLIOptions: ["-swift-flag-from-json"]) ], - rootPaths: try UserToolchain.default.destination.toolset.rootPaths + rootPaths: try UserToolchain.default.swiftSDK.toolset.rootPaths ), pathsConfiguration: .init(sdkRootPath: "/fake/sdk") ) - let mockToolchain = try UserToolchain(destination: userDestination) + let mockToolchain = try UserToolchain(swiftSDK: userSwiftSDK) let extraBuildParameters = mockBuildParameters(toolchain: mockToolchain, flags: BuildFlags(cCompilerFlags: ["-clang-command-line-flag"], swiftCompilerFlags: ["-swift-command-line-flag"])) let result = try BuildPlanResult(plan: BuildPlan( @@ -3563,7 +3563,7 @@ final class BuildPlanTests: XCTestCase { #else args += ["--sysroot"] #endif - args += ["\(userDestination.pathsConfiguration.sdkRootPath!)", "-I/fake/sdk/sysroot", "-clang-flag-from-json", .anySequence, "-clang-command-line-flag"] + args += ["\(userSwiftSDK.pathsConfiguration.sdkRootPath!)", "-I/fake/sdk/sysroot", "-clang-flag-from-json", .anySequence, "-clang-command-line-flag"] XCTAssertMatch(try lib.basicArguments(isCXX: false), args) let exe = try result.target(for: "exe").swiftTarget().compileArguments() @@ -3609,15 +3609,15 @@ final class BuildPlanTests: XCTestCase { .librarian: .init(path: "/fake/toolchain/usr/bin/librarian"), .linker: .init(extraCLIOptions: [jsonFlag(tool: .linker)]), ], - rootPaths: try UserToolchain.default.destination.toolset.rootPaths) + rootPaths: try UserToolchain.default.swiftSDK.toolset.rootPaths) let targetTriple = try Triple("armv7em-unknown-none-macho") - let destination = try Destination( + let swiftSDK = try SwiftSDK( targetTriple: targetTriple, properties: .init( sdkRootPath: "/fake/sdk", swiftStaticResourcesPath: "/usr/lib/swift_static/none"), toolset: toolset) - let toolchain = try UserToolchain(destination: destination) + let toolchain = try UserToolchain(swiftSDK: swiftSDK) let buildParameters = mockBuildParameters( toolchain: toolchain, flags: BuildFlags( @@ -3625,7 +3625,7 @@ final class BuildPlanTests: XCTestCase { cxxCompilerFlags: [cliFlag(tool: .cxxCompiler)], swiftCompilerFlags: [cliFlag(tool: .swiftCompiler)], linkerFlags: [cliFlag(tool: .linker)]), - destinationTriple: targetTriple) + targetTriple: targetTriple) let result = try BuildPlanResult(plan: BuildPlan( buildParameters: buildParameters, graph: graph, @@ -3749,16 +3749,16 @@ final class BuildPlanTests: XCTestCase { ) XCTAssertNoDiagnostics(observability.diagnostics) - let targetTriple = try UserToolchain.default.triple + let targetTriple = try UserToolchain.default.targetTriple let sdkIncludeSearchPath = "/usr/lib/swift_static/none/include" let sdkLibrarySearchPath = "/usr/lib/swift_static/none/lib" - let destination = try Destination( + let swiftSDK = try SwiftSDK( targetTriple: targetTriple, properties: .init( sdkRootPath: "/fake/sdk", includeSearchPaths: [sdkIncludeSearchPath], librarySearchPaths: [sdkLibrarySearchPath])) - let toolchain = try UserToolchain(destination: destination) + let toolchain = try UserToolchain(swiftSDK: swiftSDK) let buildParameters = mockBuildParameters(toolchain: toolchain) let result = try BuildPlanResult(plan: BuildPlan( buildParameters: buildParameters, @@ -4028,7 +4028,7 @@ final class BuildPlanTests: XCTestCase { fileSystem: fs, observabilityScope: observability.topScope ) - let dynamicLibraryExtension = plan.buildParameters.triple.dynamicLibraryExtension + let dynamicLibraryExtension = plan.buildParameters.targetTriple.dynamicLibraryExtension #if os(Windows) let dynamicLibraryPrefix = "" #else @@ -4090,7 +4090,7 @@ final class BuildPlanTests: XCTestCase { XCTAssertNoDiagnostics(observability.diagnostics) let result = try BuildPlanResult(plan: BuildPlan( - buildParameters: mockBuildParameters(destinationTriple: .x86_64Linux), + buildParameters: mockBuildParameters(targetTriple: .x86_64Linux), graph: graph, fileSystem: fs, observabilityScope: observability.topScope @@ -4166,7 +4166,7 @@ final class BuildPlanTests: XCTestCase { let contents: String = try fs.readFileContents(yaml) - if result.plan.buildParameters.triple.isWindows() { + if result.plan.buildParameters.targetTriple.isWindows() { XCTAssertMatch(contents, .contains(""" "C.rary-debug.a": tool: shell @@ -4175,7 +4175,7 @@ final class BuildPlanTests: XCTestCase { description: "Archiving \(buildPath.appending(components: "library.a").escapedPathString())" args: ["\(result.plan.buildParameters.toolchain.librarianPath.escapedPathString())","/LIB","/OUT:\(buildPath.appending(components: "library.a").escapedPathString())","@\(buildPath.appending(components: "rary.product", "Objects.LinkFileList").escapedPathString())"] """)) - } else if result.plan.buildParameters.triple.isDarwin() { + } else if result.plan.buildParameters.targetTriple.isDarwin() { XCTAssertMatch(contents, .contains(""" "C.rary-debug.a": tool: shell @@ -4300,7 +4300,7 @@ final class BuildPlanTests: XCTestCase { XCTAssertNoDiagnostics(observability.diagnostics) let plan = try BuildPlan( - buildParameters: mockBuildParameters(destinationTriple: .wasi), + buildParameters: mockBuildParameters(targetTriple: .wasi), graph: graph, fileSystem: fs, observabilityScope: observability.topScope @@ -4428,7 +4428,7 @@ final class BuildPlanTests: XCTestCase { let supportingTriples: [Basics.Triple] = [.x86_64Linux, .arm64Linux, .wasi] for triple in supportingTriples { let result = try BuildPlanResult(plan: BuildPlan( - buildParameters: mockBuildParameters(shouldLinkStaticSwiftStdlib: true, destinationTriple: triple), + buildParameters: mockBuildParameters(shouldLinkStaticSwiftStdlib: true, targetTriple: triple), graph: graph, fileSystem: fs, observabilityScope: observability.topScope @@ -4552,7 +4552,7 @@ final class BuildPlanTests: XCTestCase { XCTAssertNoDiagnostics(observability.diagnostics) let result = try BuildPlanResult(plan: BuildPlan( - buildParameters: mockBuildParameters(destinationTriple: destinationTriple), + buildParameters: mockBuildParameters(targetTriple: destinationTriple), graph: graph, fileSystem: fs, observabilityScope: observability.topScope @@ -4661,7 +4661,7 @@ final class BuildPlanTests: XCTestCase { XCTAssertNoDiagnostics(observability.diagnostics) let result = try BuildPlanResult(plan: BuildPlan( - buildParameters: mockBuildParameters(destinationTriple: destinationTriple), + buildParameters: mockBuildParameters(targetTriple: destinationTriple), graph: graph, fileSystem: fs, observabilityScope: observability.topScope diff --git a/Tests/BuildTests/MockBuildTestHelper.swift b/Tests/BuildTests/MockBuildTestHelper.swift index 21a0cd583e2..e61f7da4dfc 100644 --- a/Tests/BuildTests/MockBuildTestHelper.swift +++ b/Tests/BuildTests/MockBuildTestHelper.swift @@ -57,7 +57,7 @@ extension Basics.Triple { static let wasi = try! Self("wasm32-unknown-wasi") } -let hostTriple = try! UserToolchain.default.triple +let hostTriple = try! UserToolchain.default.targetTriple #if os(macOS) let defaultTargetTriple: String = hostTriple.tripleString(forPlatformVersion: "10.13") #else @@ -71,7 +71,7 @@ func mockBuildParameters( flags: PackageModel.BuildFlags = PackageModel.BuildFlags(), shouldLinkStaticSwiftStdlib: Bool = false, canRenameEntrypointFunctionName: Bool = false, - destinationTriple: Basics.Triple = hostTriple, + targetTriple: Basics.Triple = hostTriple, indexStoreMode: BuildParameters.IndexStoreMode = .off, useExplicitModuleBuild: Bool = false, linkerDeadStrip: Bool = true, @@ -82,7 +82,7 @@ func mockBuildParameters( configuration: config, toolchain: toolchain, hostTriple: hostTriple, - destinationTriple: destinationTriple, + targetTriple: targetTriple, flags: flags, pkgConfigDirectories: [], workers: 3, @@ -110,7 +110,7 @@ func mockBuildParameters(environment: BuildEnvironment) -> BuildParameters { fatalError("unsupported platform in tests") } - return mockBuildParameters(config: environment.configuration ?? .debug, destinationTriple: triple) + return mockBuildParameters(config: environment.configuration ?? .debug, targetTriple: triple) } enum BuildError: Swift.Error { diff --git a/Tests/CommandsTests/BuildToolTests.swift b/Tests/CommandsTests/BuildToolTests.swift index 7f9f79fe4ff..afd0a479a4d 100644 --- a/Tests/CommandsTests/BuildToolTests.swift +++ b/Tests/CommandsTests/BuildToolTests.swift @@ -121,7 +121,7 @@ final class BuildToolTests: CommandsTestCase { func testBinPathAndSymlink() throws { try fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { fixturePath in let fullPath = try resolveSymlinks(fixturePath) - let targetPath = fullPath.appending(components: ".build", try UserToolchain.default.triple.platformBuildPathComponent()) + let targetPath = fullPath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent()) let xcbuildTargetPath = fullPath.appending(components: ".build", "apple") XCTAssertEqual(try execute(["--show-bin-path"], packagePath: fullPath).stdout, "\(targetPath.appending("debug").pathString)\n") @@ -328,7 +328,7 @@ final class BuildToolTests: CommandsTestCase { let defaultOutput = try execute(["-c", "debug", "-v"], packagePath: fixturePath).stdout // Look for certain things in the output from XCBuild. - XCTAssertMatch(defaultOutput, .contains("-target \(try UserToolchain.default.triple.tripleString(forPlatformVersion: ""))")) + XCTAssertMatch(defaultOutput, .contains("-target \(try UserToolchain.default.targetTriple.tripleString(forPlatformVersion: ""))")) } } diff --git a/Tests/CommandsTests/PackageToolTests.swift b/Tests/CommandsTests/PackageToolTests.swift index 050d11e1bff..8390d6ea70e 100644 --- a/Tests/CommandsTests/PackageToolTests.swift +++ b/Tests/CommandsTests/PackageToolTests.swift @@ -475,7 +475,7 @@ final class PackageToolTests: CommandsTestCase { // Returns symbol graph with or without pretty printing. private func symbolGraph(atPath path: AbsolutePath, withPrettyPrinting: Bool, file: StaticString = #file, line: UInt = #line) throws -> Data? { let tool = try SwiftTool.createSwiftToolForTest(options: GlobalOptions.parse(["--package-path", path.pathString])) - let symbolGraphExtractorPath = try tool.getDestinationToolchain().getSymbolGraphExtract() + let symbolGraphExtractorPath = try tool.getTargetToolchain().getSymbolGraphExtract() let arguments = withPrettyPrinting ? ["dump-symbol-graph", "--pretty-print"] : ["dump-symbol-graph"] @@ -768,7 +768,7 @@ final class PackageToolTests: CommandsTestCase { _ = try SwiftPM.Package.execute(["edit", "baz", "--branch", "bugfix"], packagePath: fooPath) // Path to the executable. - let exec = [fooPath.appending(components: ".build", try UserToolchain.default.triple.platformBuildPathComponent(), "debug", "foo").pathString] + let exec = [fooPath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug", "foo").pathString] // We should see it now in packages directory. let editsPath = fooPath.appending(components: "Packages", "bar") @@ -842,7 +842,7 @@ final class PackageToolTests: CommandsTestCase { // Build it. XCTAssertBuilds(packageRoot) let buildPath = packageRoot.appending(".build") - let binFile = buildPath.appending(components: try UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Bar") + let binFile = buildPath.appending(components: try UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug", "Bar") XCTAssertFileExists(binFile) XCTAssert(localFileSystem.isDirectory(buildPath)) @@ -861,7 +861,7 @@ final class PackageToolTests: CommandsTestCase { // Build it. XCTAssertBuilds(packageRoot) let buildPath = packageRoot.appending(".build") - let binFile = buildPath.appending(components: try UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Bar") + let binFile = buildPath.appending(components: try UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug", "Bar") XCTAssertFileExists(binFile) XCTAssert(localFileSystem.isDirectory(buildPath)) // Clean, and check for removal of the build directory but not Packages. @@ -931,7 +931,7 @@ final class PackageToolTests: CommandsTestCase { func build() throws -> String { return try SwiftPM.Build.execute(packagePath: fooPath).stdout } - let exec = [fooPath.appending(components: ".build", try UserToolchain.default.triple.platformBuildPathComponent(), "debug", "foo").pathString] + let exec = [fooPath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug", "foo").pathString] // Build and check. _ = try build() @@ -1687,7 +1687,7 @@ final class PackageToolTests: CommandsTestCase { """ ) - let hostTriple = try UserToolchain(destination: .hostDestination()).triple + let hostTriple = try UserToolchain(swiftSDK: .hostSwiftSDK()).targetTriple let hostTripleString = hostTriple.isDarwin() ? hostTriple.tripleString(forPlatformVersion: "") : hostTriple.tripleString try localFileSystem.writeFileContents(packageDir.appending(components: "Binaries", "LocalBinaryTool.artifactbundle", "info.json"), string: """ diff --git a/Tests/FunctionalPerformanceTests/BuildPerfTests.swift b/Tests/FunctionalPerformanceTests/BuildPerfTests.swift index e0b4aaf3398..66e17b81357 100644 --- a/Tests/FunctionalPerformanceTests/BuildPerfTests.swift +++ b/Tests/FunctionalPerformanceTests/BuildPerfTests.swift @@ -62,7 +62,7 @@ class BuildPerfTests: XCTestCasePerf { func runFullBuildTest(for name: String, app appString: String? = nil, product productString: String) throws { try fixture(name: name) { fixturePath in let app = fixturePath.appending(components: (appString ?? "")) - let triple = try UserToolchain.default.triple + let triple = try UserToolchain.default.targetTriple let product = app.appending(components: ".build", triple.platformBuildPathComponent(), "debug", productString) try self.execute(packagePath: app) measure { @@ -76,7 +76,7 @@ class BuildPerfTests: XCTestCasePerf { func runNullBuildTest(for name: String, app appString: String? = nil, product productString: String) throws { try fixture(name: name) { fixturePath in let app = fixturePath.appending(components: (appString ?? "")) - let triple = try UserToolchain.default.triple + let triple = try UserToolchain.default.targetTriple let product = app.appending(components: ".build", triple.platformBuildPathComponent(), "debug", productString) try self.execute(packagePath: app) measure { diff --git a/Tests/FunctionalTests/CFamilyTargetTests.swift b/Tests/FunctionalTests/CFamilyTargetTests.swift index d443a4f89d3..9f0a11be217 100644 --- a/Tests/FunctionalTests/CFamilyTargetTests.swift +++ b/Tests/FunctionalTests/CFamilyTargetTests.swift @@ -41,7 +41,7 @@ class CFamilyTargetTestCase: XCTestCase { func testCLibraryWithSpaces() throws { try fixture(name: "CFamilyTargets/CLibraryWithSpaces") { fixturePath in XCTAssertBuilds(fixturePath) - let debugPath = fixturePath.appending(components: ".build", try UserToolchain.default.triple.platformBuildPathComponent(), "debug") + let debugPath = fixturePath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Bar.c.o") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o") } @@ -51,7 +51,7 @@ class CFamilyTargetTestCase: XCTestCase { try fixture(name: "DependencyResolution/External/CUsingCDep") { fixturePath in let packageRoot = fixturePath.appending("Bar") XCTAssertBuilds(packageRoot) - let debugPath = fixturePath.appending(components: "Bar", ".build", try UserToolchain.default.triple.platformBuildPathComponent(), "debug") + let debugPath = fixturePath.appending(components: "Bar", ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Sea.c.o") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o") let path = try SwiftPM.packagePath(for: "Foo", packageRoot: packageRoot) @@ -62,7 +62,7 @@ class CFamilyTargetTestCase: XCTestCase { func testModuleMapGenerationCases() throws { try fixture(name: "CFamilyTargets/ModuleMapGenerationCases") { fixturePath in XCTAssertBuilds(fixturePath) - let debugPath = fixturePath.appending(components: ".build", try UserToolchain.default.triple.platformBuildPathComponent(), "debug") + let debugPath = fixturePath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Jaz.c.o") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "main.swift.o") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "FlatInclude.c.o") @@ -85,7 +85,7 @@ class CFamilyTargetTestCase: XCTestCase { // Try building a fixture which needs extra flags to be able to build. try fixture(name: "CFamilyTargets/CDynamicLookup") { fixturePath in XCTAssertBuilds(fixturePath, Xld: ["-undefined", "dynamic_lookup"]) - let debugPath = fixturePath.appending(components: ".build", try UserToolchain.default.triple.platformBuildPathComponent(), "debug") + let debugPath = fixturePath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o") } } @@ -97,7 +97,7 @@ class CFamilyTargetTestCase: XCTestCase { try fixture(name: "CFamilyTargets/ObjCmacOSPackage") { fixturePath in // Build the package. XCTAssertBuilds(fixturePath) - XCTAssertDirectoryContainsFile(dir: fixturePath.appending(components: ".build", try UserToolchain.default.triple.platformBuildPathComponent(), "debug"), filename: "HelloWorldExample.m.o") + XCTAssertDirectoryContainsFile(dir: fixturePath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug"), filename: "HelloWorldExample.m.o") // Run swift-test on package. XCTAssertSwiftTest(fixturePath) } @@ -106,7 +106,7 @@ class CFamilyTargetTestCase: XCTestCase { func testCanBuildRelativeHeaderSearchPaths() throws { try fixture(name: "CFamilyTargets/CLibraryParentSearchPath") { fixturePath in XCTAssertBuilds(fixturePath) - XCTAssertDirectoryContainsFile(dir: fixturePath.appending(components: ".build", try UserToolchain.default.triple.platformBuildPathComponent(), "debug"), filename: "HeaderInclude.swiftmodule") + XCTAssertDirectoryContainsFile(dir: fixturePath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug"), filename: "HeaderInclude.swiftmodule") } } } diff --git a/Tests/FunctionalTests/DependencyResolutionTests.swift b/Tests/FunctionalTests/DependencyResolutionTests.swift index 0a312de947e..ef80bea8807 100644 --- a/Tests/FunctionalTests/DependencyResolutionTests.swift +++ b/Tests/FunctionalTests/DependencyResolutionTests.swift @@ -23,7 +23,7 @@ class DependencyResolutionTests: XCTestCase { try fixture(name: "DependencyResolution/Internal/Simple") { fixturePath in XCTAssertBuilds(fixturePath) - let output = try Process.checkNonZeroExit(args: fixturePath.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Foo").pathString) + let output = try Process.checkNonZeroExit(args: fixturePath.appending(components: ".build", UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug", "Foo").pathString) XCTAssertEqual(output, "Foo\nBar\n") } } @@ -38,7 +38,7 @@ class DependencyResolutionTests: XCTestCase { try fixture(name: "DependencyResolution/Internal/Complex") { fixturePath in XCTAssertBuilds(fixturePath) - let output = try Process.checkNonZeroExit(args: fixturePath.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Foo").pathString) + let output = try Process.checkNonZeroExit(args: fixturePath.appending(components: ".build", UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug", "Foo").pathString) XCTAssertEqual(output, "meiow Baz\n") } } @@ -54,7 +54,7 @@ class DependencyResolutionTests: XCTestCase { let packageRoot = fixturePath.appending("Bar") XCTAssertBuilds(packageRoot) - XCTAssertFileExists(fixturePath.appending(components: "Bar", ".build", try UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Bar")) + XCTAssertFileExists(fixturePath.appending(components: "Bar", ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug", "Bar")) let path = try SwiftPM.packagePath(for: "Foo", packageRoot: packageRoot) XCTAssert(try GitRepository(path: path).getTags().contains("1.2.3")) } @@ -63,7 +63,7 @@ class DependencyResolutionTests: XCTestCase { func testExternalComplex() throws { try fixture(name: "DependencyResolution/External/Complex") { fixturePath in XCTAssertBuilds(fixturePath.appending("app")) - let output = try Process.checkNonZeroExit(args: fixturePath.appending(components: "app", ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Dealer").pathString) + let output = try Process.checkNonZeroExit(args: fixturePath.appending(components: "app", ".build", UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug", "Dealer").pathString) XCTAssertEqual(output, "♣︎K\n♣︎Q\n♣︎J\n♣︎10\n♣︎9\n♣︎8\n♣︎7\n♣︎6\n♣︎5\n♣︎4\n") } } diff --git a/Tests/FunctionalTests/MiscellaneousTests.swift b/Tests/FunctionalTests/MiscellaneousTests.swift index 42d683ed883..53e29947299 100644 --- a/Tests/FunctionalTests/MiscellaneousTests.swift +++ b/Tests/FunctionalTests/MiscellaneousTests.swift @@ -52,7 +52,7 @@ class MiscellaneousTestCase: XCTestCase { try fixture(name: "Miscellaneous/ExactDependencies") { fixturePath in XCTAssertBuilds(fixturePath.appending("app")) - let buildDir = fixturePath.appending(components: "app", ".build", try UserToolchain.default.triple.platformBuildPathComponent(), "debug") + let buildDir = fixturePath.appending(components: "app", ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug") XCTAssertFileExists(buildDir.appending("FooExec")) XCTAssertFileExists(buildDir.appending("FooLib1.swiftmodule")) XCTAssertFileExists(buildDir.appending("FooLib2.swiftmodule")) @@ -107,7 +107,7 @@ class MiscellaneousTestCase: XCTestCase { */ func testInternalDependencyEdges() throws { try fixture(name: "Miscellaneous/DependencyEdges/Internal") { fixturePath in - let execpath = fixturePath.appending(components: ".build", try UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Foo").pathString + let execpath = fixturePath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug", "Foo").pathString XCTAssertBuilds(fixturePath) var output = try Process.checkNonZeroExit(args: execpath) @@ -131,7 +131,7 @@ class MiscellaneousTestCase: XCTestCase { */ func testExternalDependencyEdges1() throws { try fixture(name: "DependencyResolution/External/Complex") { fixturePath in - let execpath = fixturePath.appending(components: "app", ".build", try UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Dealer").pathString + let execpath = fixturePath.appending(components: "app", ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug", "Dealer").pathString let packageRoot = fixturePath.appending("app") XCTAssertBuilds(packageRoot) @@ -158,7 +158,7 @@ class MiscellaneousTestCase: XCTestCase { */ func testExternalDependencyEdges2() throws { try fixture(name: "Miscellaneous/DependencyEdges/External") { fixturePath in - let execpath = [fixturePath.appending(components: "root", ".build", try UserToolchain.default.triple.platformBuildPathComponent(), "debug", "dep2").pathString] + let execpath = [fixturePath.appending(components: "root", ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug", "dep2").pathString] let packageRoot = fixturePath.appending("root") XCTAssertBuilds(fixturePath.appending("root")) @@ -182,7 +182,7 @@ class MiscellaneousTestCase: XCTestCase { func testSpaces() throws { try fixture(name: "Miscellaneous/Spaces Fixture") { fixturePath in XCTAssertBuilds(fixturePath) - XCTAssertFileExists(fixturePath.appending(components: ".build", try UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Module_Name_1.build", "Foo.swift.o")) + XCTAssertFileExists(fixturePath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug", "Module_Name_1.build", "Foo.swift.o")) } } @@ -204,7 +204,7 @@ class MiscellaneousTestCase: XCTestCase { try XCTSkipIf(true, "test is only supported on macOS") #endif try fixture(name: "Miscellaneous/DistantFutureDeploymentTarget") { fixturePath in - let hostTriple = try UserToolchain.default.triple + let hostTriple = try UserToolchain.default.targetTriple try executeSwiftBuild(fixturePath, Xswiftc: ["-target", "\(hostTriple.archName)-apple-macosx41.0"]) } } @@ -214,7 +214,7 @@ class MiscellaneousTestCase: XCTestCase { let systemModule = fixturePath.appending("SystemModule") // Create a shared library. let input = systemModule.appending(components: "Sources", "SystemModule.c") - let triple = try UserToolchain.default.triple + let triple = try UserToolchain.default.targetTriple let output = systemModule.appending("libSystemModule\(triple.dynamicLibraryExtension)") try systemQuietly(["clang", "-shared", input.pathString, "-o", output.pathString]) diff --git a/Tests/FunctionalTests/ModuleAliasingFixtureTests.swift b/Tests/FunctionalTests/ModuleAliasingFixtureTests.swift index 1173b5c291a..dd92109b21f 100644 --- a/Tests/FunctionalTests/ModuleAliasingFixtureTests.swift +++ b/Tests/FunctionalTests/ModuleAliasingFixtureTests.swift @@ -22,7 +22,7 @@ class ModuleAliasingFixtureTests: XCTestCase { func testModuleDirectDeps1() throws { try fixture(name: "ModuleAliasing/DirectDeps1") { fixturePath in let pkgPath = fixturePath.appending(components: "AppPkg") - let buildPath = pkgPath.appending(components: ".build", try UserToolchain.default.triple.platformBuildPathComponent(), "debug") + let buildPath = pkgPath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug") XCTAssertBuilds(pkgPath, extraArgs: ["--vv"]) XCTAssertFileExists(buildPath.appending(components: "App")) XCTAssertFileExists(buildPath.appending(components: "GameUtils.swiftmodule")) @@ -34,7 +34,7 @@ class ModuleAliasingFixtureTests: XCTestCase { func testModuleDirectDeps2() throws { try fixture(name: "ModuleAliasing/DirectDeps2") { fixturePath in let pkgPath = fixturePath.appending(components: "AppPkg") - let buildPath = pkgPath.appending(components: ".build", try UserToolchain.default.triple.platformBuildPathComponent(), "debug") + let buildPath = pkgPath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug") XCTAssertBuilds(pkgPath, extraArgs: ["--vv"]) XCTAssertFileExists(buildPath.appending(components: "App")) XCTAssertFileExists(buildPath.appending(components: "AUtils.swiftmodule")) diff --git a/Tests/FunctionalTests/ModuleMapTests.swift b/Tests/FunctionalTests/ModuleMapTests.swift index d646c8be2b9..707179ae9fc 100644 --- a/Tests/FunctionalTests/ModuleMapTests.swift +++ b/Tests/FunctionalTests/ModuleMapTests.swift @@ -22,7 +22,7 @@ class ModuleMapsTestCase: XCTestCase { private func fixture(name: String, cModuleName: String, rootpkg: String, body: @escaping (AbsolutePath, [String]) throws -> Void) throws { try SPMTestSupport.fixture(name: name) { fixturePath in let input = fixturePath.appending(components: cModuleName, "C", "foo.c") - let triple = try UserToolchain.default.triple + let triple = try UserToolchain.default.targetTriple let outdir = fixturePath.appending(components: rootpkg, ".build", triple.platformBuildPathComponent(), "debug") try makeDirectories(outdir) let output = outdir.appending("libfoo\(triple.dynamicLibraryExtension)") @@ -42,7 +42,7 @@ class ModuleMapsTestCase: XCTestCase { XCTAssertBuilds(fixturePath.appending("App"), Xld: Xld) - let triple = try UserToolchain.default.triple + let triple = try UserToolchain.default.targetTriple let targetPath = fixturePath.appending(components: "App", ".build", triple.platformBuildPathComponent()) let debugout = try Process.checkNonZeroExit(args: targetPath.appending(components: "debug", "App").pathString) XCTAssertEqual(debugout, "123\n") @@ -57,7 +57,7 @@ class ModuleMapsTestCase: XCTestCase { XCTAssertBuilds(fixturePath.appending("packageA"), Xld: Xld) func verify(_ conf: String) throws { - let triple = try UserToolchain.default.triple + let triple = try UserToolchain.default.targetTriple let out = try Process.checkNonZeroExit(args: fixturePath.appending(components: "packageA", ".build", triple.platformBuildPathComponent(), conf, "packageA").pathString) XCTAssertEqual(out, """ calling Y.bar() diff --git a/Tests/FunctionalTests/ToolsVersionTests.swift b/Tests/FunctionalTests/ToolsVersionTests.swift index cda47969570..b007beb142d 100644 --- a/Tests/FunctionalTests/ToolsVersionTests.swift +++ b/Tests/FunctionalTests/ToolsVersionTests.swift @@ -93,7 +93,7 @@ class ToolsVersionTests: XCTestCase { // Build the primary package. _ = try SwiftPM.Build.execute(packagePath: primaryPath) - let exe = primaryPath.appending(components: ".build", try UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Primary").pathString + let exe = primaryPath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent(), "debug", "Primary").pathString // v1 should get selected because v1.0.1 depends on a (way) higher set of tools. XCTAssertEqual(try Process.checkNonZeroExit(args: exe).spm_chomp(), "foo@1.0") diff --git a/Tests/PackageLoadingTests/PD_5_0_LoadingTests.swift b/Tests/PackageLoadingTests/PD_5_0_LoadingTests.swift index d8382221c8a..18873299874 100644 --- a/Tests/PackageLoadingTests/PD_5_0_LoadingTests.swift +++ b/Tests/PackageLoadingTests/PD_5_0_LoadingTests.swift @@ -612,7 +612,7 @@ class PackageDescription5_0LoadingTests: PackageDescriptionLoadingTests { let moduleTraceFilePath = path.appending("swift-module-trace") var env = EnvironmentVariables.process() env["SWIFT_LOADED_MODULE_TRACE_FILE"] = moduleTraceFilePath.pathString - let toolchain = try UserToolchain(destination: Destination.default, environment: env) + let toolchain = try UserToolchain(swiftSDK: SwiftSDK.default, environment: env) let manifestLoader = ManifestLoader( toolchain: toolchain, serializedDiagnostics: true, diff --git a/Tests/PackageModelTests/DestinationTests.swift b/Tests/PackageModelTests/DestinationTests.swift index 00c6beb7125..635a5989e70 100644 --- a/Tests/PackageModelTests/DestinationTests.swift +++ b/Tests/PackageModelTests/DestinationTests.swift @@ -277,21 +277,21 @@ private let invalidToolset = ( private let sdkRootAbsolutePath = bundleRootPath.appending(sdkRootDir) private let toolchainBinAbsolutePath = bundleRootPath.appending(toolchainBinDir) -private let parsedDestinationV2GNU = Destination( +private let parsedDestinationV2GNU = SwiftSDK( hostTriple: hostTriple, targetTriple: linuxGNUTargetTriple, toolset: .init(toolchainBinDir: toolchainBinAbsolutePath, buildFlags: extraFlags), pathsConfiguration: .init(sdkRootPath: sdkRootAbsolutePath) ) -private let parsedDestinationV2Musl = Destination( +private let parsedDestinationV2Musl = SwiftSDK( hostTriple: hostTriple, targetTriple: linuxMuslTargetTriple, toolset: .init(toolchainBinDir: toolchainBinAbsolutePath, buildFlags: extraFlags), pathsConfiguration: .init(sdkRootPath: sdkRootAbsolutePath) ) -private let parsedToolsetNoRootDestination = Destination( +private let parsedToolsetNoRootDestination = SwiftSDK( targetTriple: linuxGNUTargetTriple, toolset: .init( knownTools: [ @@ -308,7 +308,7 @@ private let parsedToolsetNoRootDestination = Destination( ) ) -private let parsedToolsetRootDestination = Destination( +private let parsedToolsetRootDestination = SwiftSDK( targetTriple: linuxGNUTargetTriple, toolset: .init( knownTools: [ @@ -355,7 +355,7 @@ final class DestinationTests: XCTestCase { let system = ObservabilitySystem.makeForTesting() let observability = system.topScope - let destinationV1Decoded = try Destination.decode( + let destinationV1Decoded = try SwiftSDK.decode( fromFile: AbsolutePath(validating: destinationV1.path), fileSystem: fs, observabilityScope: observability @@ -367,7 +367,7 @@ final class DestinationTests: XCTestCase { XCTAssertEqual( destinationV1Decoded, [ - Destination( + SwiftSDK( targetTriple: linuxGNUTargetTriple, toolset: .init(toolchainBinDir: toolchainBinAbsolutePath, buildFlags: flagsWithoutLinkerFlags), pathsConfiguration: .init( @@ -377,7 +377,7 @@ final class DestinationTests: XCTestCase { ] ) - let destinationV2Decoded = try Destination.decode( + let destinationV2Decoded = try SwiftSDK.decode( fromFile: AbsolutePath(validating: destinationV2.path), fileSystem: fs, observabilityScope: observability @@ -385,7 +385,7 @@ final class DestinationTests: XCTestCase { XCTAssertEqual(destinationV2Decoded, [parsedDestinationV2GNU]) - let toolsetNoRootDestinationV3Decoded = try Destination.decode( + let toolsetNoRootDestinationV3Decoded = try SwiftSDK.decode( fromFile: AbsolutePath(validating: toolsetNoRootDestinationV3.path), fileSystem: fs, observabilityScope: observability @@ -393,7 +393,7 @@ final class DestinationTests: XCTestCase { XCTAssertEqual(toolsetNoRootDestinationV3Decoded, [parsedToolsetNoRootDestination]) - let toolsetRootDestinationV3Decoded = try Destination.decode( + let toolsetRootDestinationV3Decoded = try SwiftSDK.decode( fromFile: AbsolutePath(validating: toolsetRootDestinationV3.path), fileSystem: fs, observabilityScope: observability @@ -401,7 +401,7 @@ final class DestinationTests: XCTestCase { XCTAssertEqual(toolsetRootDestinationV3Decoded, [parsedToolsetRootDestination]) - XCTAssertThrowsError(try Destination.decode( + XCTAssertThrowsError(try SwiftSDK.decode( fromFile: AbsolutePath(validating: missingToolsetDestinationV3.path), fileSystem: fs, observabilityScope: observability @@ -416,13 +416,13 @@ final class DestinationTests: XCTestCase { ) ) } - XCTAssertThrowsError(try Destination.decode( + XCTAssertThrowsError(try SwiftSDK.decode( fromFile: AbsolutePath(validating: invalidVersionDestinationV3.path), fileSystem: fs, observabilityScope: observability )) - XCTAssertThrowsError(try Destination.decode( + XCTAssertThrowsError(try SwiftSDK.decode( fromFile: AbsolutePath(validating: invalidToolsetDestinationV3.path), fileSystem: fs, observabilityScope: observability @@ -433,7 +433,7 @@ final class DestinationTests: XCTestCase { ) } - let toolsetNoRootSwiftSDKv4Decoded = try Destination.decode( + let toolsetNoRootSwiftSDKv4Decoded = try SwiftSDK.decode( fromFile: AbsolutePath(validating: toolsetNoRootSwiftSDKv4.path), fileSystem: fs, observabilityScope: observability @@ -441,7 +441,7 @@ final class DestinationTests: XCTestCase { XCTAssertEqual(toolsetNoRootSwiftSDKv4Decoded, [parsedToolsetNoRootDestination]) - let toolsetRootSwiftSDKv4Decoded = try Destination.decode( + let toolsetRootSwiftSDKv4Decoded = try SwiftSDK.decode( fromFile: AbsolutePath(validating: toolsetRootSwiftSDKv4.path), fileSystem: fs, observabilityScope: observability @@ -449,7 +449,7 @@ final class DestinationTests: XCTestCase { XCTAssertEqual(toolsetRootSwiftSDKv4Decoded, [parsedToolsetRootDestination]) - XCTAssertThrowsError(try Destination.decode( + XCTAssertThrowsError(try SwiftSDK.decode( fromFile: AbsolutePath(validating: missingToolsetSwiftSDKv4.path), fileSystem: fs, observabilityScope: observability @@ -464,13 +464,13 @@ final class DestinationTests: XCTestCase { ) ) } - XCTAssertThrowsError(try Destination.decode( + XCTAssertThrowsError(try SwiftSDK.decode( fromFile: AbsolutePath(validating: invalidVersionSwiftSDKv4.path), fileSystem: fs, observabilityScope: observability )) - XCTAssertThrowsError(try Destination.decode( + XCTAssertThrowsError(try SwiftSDK.decode( fromFile: AbsolutePath(validating: invalidToolsetSwiftSDKv4.path), fileSystem: fs, observabilityScope: observability diff --git a/Tests/PackageModelTests/PackageModelTests.swift b/Tests/PackageModelTests/PackageModelTests.swift index 5cbbd707d02..d509109fe9b 100644 --- a/Tests/PackageModelTests/PackageModelTests.swift +++ b/Tests/PackageModelTests/PackageModelTests.swift @@ -61,14 +61,14 @@ class PackageModelTests: XCTestCase { let sdkDir = AbsolutePath("/some/path/to/an/SDK.sdk") let toolchainPath = AbsolutePath("/some/path/to/a/toolchain.xctoolchain") - let destination = Destination( + let destination = SwiftSDK( targetTriple: triple, toolset: .init(toolchainBinDir: toolchainPath.appending(components: "usr", "bin"), buildFlags: .init()), pathsConfiguration: .init(sdkRootPath: sdkDir) ) XCTAssertEqual( - try UserToolchain.deriveSwiftCFlags(triple: triple, destination: destination, environment: .process()), + try UserToolchain.deriveSwiftCFlags(triple: triple, swiftSDK: destination, environment: .process()), [ // Needed when cross‐compiling for Android. 2020‐03‐01 "-sdk", sdkDir.pathString, diff --git a/Tests/SPMBuildCoreTests/PluginInvocationTests.swift b/Tests/SPMBuildCoreTests/PluginInvocationTests.swift index 04300f12f1c..507afe3cc45 100644 --- a/Tests/SPMBuildCoreTests/PluginInvocationTests.swift +++ b/Tests/SPMBuildCoreTests/PluginInvocationTests.swift @@ -89,10 +89,9 @@ class PluginInvocationTests: XCTestCase { // A fake PluginScriptRunner that just checks the input conditions and returns canned output. struct MockPluginScriptRunner: PluginScriptRunner { - var hostTriple: Triple { get throws { - return try UserToolchain.default.triple + return try UserToolchain.default.targetTriple } } @@ -1035,7 +1034,7 @@ class PluginInvocationTests: XCTestCase { let workspace = try Workspace( fileSystem: localFileSystem, location: try Workspace.Location(forRootPackage: packageDir, fileSystem: localFileSystem), - customHostToolchain: UserToolchain(destination: .hostDestination(), customLibrariesLocation: .init(manifestLibraryPath: fakeExtraModulesDir, pluginLibraryPath: fakeExtraModulesDir)), + customHostToolchain: UserToolchain(swiftSDK: .hostSwiftSDK(), customLibrariesLocation: .init(manifestLibraryPath: fakeExtraModulesDir, pluginLibraryPath: fakeExtraModulesDir)), customManifestLoader: ManifestLoader(toolchain: UserToolchain.default), delegate: MockWorkspaceDelegate() ) @@ -1212,13 +1211,13 @@ class PluginInvocationTests: XCTestCase { XCTAssertEqual(buildToolPlugin.capability, .buildTool) // Construct a toolchain with a made-up host/target triple - let destination = try Destination.default + let swiftSDK = try SwiftSDK.default let toolchain = try UserToolchain( - destination: Destination( + swiftSDK: SwiftSDK( hostTriple: hostTriple, targetTriple: hostTriple, - toolset: destination.toolset, - pathsConfiguration: destination.pathsConfiguration + toolset: swiftSDK.toolset, + pathsConfiguration: swiftSDK.pathsConfiguration ) ) @@ -1248,7 +1247,7 @@ class PluginInvocationTests: XCTestCase { } func testParseArtifactNotSupportedOnTargetPlatform() throws { - let hostTriple = try UserToolchain.default.triple + let hostTriple = try UserToolchain.default.targetTriple let artifactSupportedTriples = try [Triple("riscv64-apple-windows-android")] var checked = false @@ -1266,7 +1265,7 @@ class PluginInvocationTests: XCTestCase { #if !os(macOS) throw XCTSkip("platform versions are only available if the host is macOS") #else - let hostTriple = try UserToolchain.default.triple + let hostTriple = try UserToolchain.default.targetTriple let artifactSupportedTriples = try [Triple("\(hostTriple.withoutVersion().tripleString)20.0")] try checkParseArtifactsPlatformCompatibility(artifactSupportedTriples: artifactSupportedTriples, hostTriple: hostTriple) { result in @@ -1281,7 +1280,7 @@ class PluginInvocationTests: XCTestCase { } func testParseArtifactsConsidersAllSupportedTriples() throws { - let hostTriple = try UserToolchain.default.triple + let hostTriple = try UserToolchain.default.targetTriple let artifactSupportedTriples = [hostTriple, try Triple("riscv64-apple-windows-android")] try checkParseArtifactsPlatformCompatibility(artifactSupportedTriples: artifactSupportedTriples, hostTriple: hostTriple) { result in diff --git a/Tests/WorkspaceTests/InitTests.swift b/Tests/WorkspaceTests/InitTests.swift index 6113c41f10d..a8108f0ef07 100644 --- a/Tests/WorkspaceTests/InitTests.swift +++ b/Tests/WorkspaceTests/InitTests.swift @@ -87,7 +87,7 @@ class InitTests: XCTestCase { XCTAssertEqual(try fs.getDirectoryContents(path.appending("Sources")), ["main.swift"]) XCTAssertBuilds(path) - let triple = try UserToolchain.default.triple + let triple = try UserToolchain.default.targetTriple let binPath = path.appending(components: ".build", triple.platformBuildPathComponent(), "debug") #if os(Windows) XCTAssertFileExists(binPath.appending("Foo.exe")) @@ -144,7 +144,7 @@ class InitTests: XCTestCase { // Try building it XCTAssertBuilds(path) - let triple = try UserToolchain.default.triple + let triple = try UserToolchain.default.targetTriple XCTAssertFileExists(path.appending(components: ".build", triple.platformBuildPathComponent(), "debug", "Foo.swiftmodule")) } } @@ -242,7 +242,7 @@ class InitTests: XCTestCase { // Try building it. XCTAssertBuilds(packageRoot) - let triple = try UserToolchain.default.triple + let triple = try UserToolchain.default.targetTriple XCTAssertFileExists(packageRoot.appending(components: ".build", triple.platformBuildPathComponent(), "debug", "some_package.swiftmodule")) } } diff --git a/Tests/WorkspaceTests/WorkspaceTests.swift b/Tests/WorkspaceTests/WorkspaceTests.swift index 2b23dd55933..41c5f203256 100644 --- a/Tests/WorkspaceTests/WorkspaceTests.swift +++ b/Tests/WorkspaceTests/WorkspaceTests.swift @@ -7496,7 +7496,7 @@ final class WorkspaceTests: XCTestCase { let binaryArtifactsManager = try Workspace.BinaryArtifactsManager( fileSystem: fs, authorizationProvider: .none, - hostToolchain: UserToolchain(destination: .hostDestination()), + hostToolchain: UserToolchain(swiftSDK: .hostSwiftSDK()), checksumAlgorithm: checksumAlgorithm, customHTTPClient: .none, customArchiver: .none, @@ -8535,7 +8535,7 @@ final class WorkspaceTests: XCTestCase { let sandbox = AbsolutePath("/tmp/ws/") let fs = InMemoryFileSystem() let downloads = ThreadSafeKeyValueStore() - let hostToolchain = try UserToolchain(destination: .hostDestination()) + let hostToolchain = try UserToolchain(swiftSDK: .hostSwiftSDK()) let ariFiles = [ """ @@ -8545,7 +8545,7 @@ final class WorkspaceTests: XCTestCase { { "fileName": "a1.zip", "checksum": "a1", - "supportedTriples": ["\(hostToolchain.triple.tripleString)"] + "supportedTriples": ["\(hostToolchain.targetTriple.tripleString)"] } ] } @@ -8557,7 +8557,7 @@ final class WorkspaceTests: XCTestCase { { "fileName": "a2/a2.zip", "checksum": "a2", - "supportedTriples": ["\(hostToolchain.triple.tripleString)"] + "supportedTriples": ["\(hostToolchain.targetTriple.tripleString)"] } ] } @@ -8823,7 +8823,7 @@ final class WorkspaceTests: XCTestCase { func testDownloadArchiveIndexFileBadChecksum() throws { let sandbox = AbsolutePath("/tmp/ws/") let fs = InMemoryFileSystem() - let hostToolchain = try UserToolchain(destination: .hostDestination()) + let hostToolchain = try UserToolchain(swiftSDK: .hostSwiftSDK()) let ari = """ { @@ -8832,7 +8832,7 @@ final class WorkspaceTests: XCTestCase { { "fileName": "a1.zip", "checksum": "a1", - "supportedTriples": ["\(hostToolchain.triple.tripleString)"] + "supportedTriples": ["\(hostToolchain.targetTriple.tripleString)"] } ] } @@ -8942,7 +8942,7 @@ final class WorkspaceTests: XCTestCase { func testDownloadArchiveIndexFileBadArchivesChecksum() throws { let sandbox = AbsolutePath("/tmp/ws/") let fs = InMemoryFileSystem() - let hostToolchain = try UserToolchain(destination: .hostDestination()) + let hostToolchain = try UserToolchain(swiftSDK: .hostSwiftSDK()) let ari = """ { @@ -8951,7 +8951,7 @@ final class WorkspaceTests: XCTestCase { { "fileName": "a.zip", "checksum": "a", - "supportedTriples": ["\(hostToolchain.triple.tripleString)"] + "supportedTriples": ["\(hostToolchain.targetTriple.tripleString)"] } ] } @@ -9052,7 +9052,7 @@ final class WorkspaceTests: XCTestCase { func testDownloadArchiveIndexFileArchiveNotFound() throws { let sandbox = AbsolutePath("/tmp/ws/") let fs = InMemoryFileSystem() - let hostToolchain = try UserToolchain(destination: .hostDestination()) + let hostToolchain = try UserToolchain(swiftSDK: .hostSwiftSDK()) let ari = """ { @@ -9061,7 +9061,7 @@ final class WorkspaceTests: XCTestCase { { "fileName": "not-found.zip", "checksum": "a", - "supportedTriples": ["\(hostToolchain.triple.tripleString)"] + "supportedTriples": ["\(hostToolchain.targetTriple.tripleString)"] } ] } @@ -9128,10 +9128,10 @@ final class WorkspaceTests: XCTestCase { let sandbox = AbsolutePath("/tmp/ws/") let fs = InMemoryFileSystem() - let hostToolchain = try UserToolchain(destination: .hostDestination()) + let hostToolchain = try UserToolchain(swiftSDK: .hostSwiftSDK()) let androidTriple = try Triple("x86_64-unknown-linux-android") let macTriple = try Triple("arm64-apple-macosx") - let notHostTriple = hostToolchain.triple == androidTriple ? macTriple : androidTriple + let notHostTriple = hostToolchain.targetTriple == androidTriple ? macTriple : androidTriple let ari = """ { @@ -9189,7 +9189,7 @@ final class WorkspaceTests: XCTestCase { testDiagnostics(diagnostics) { result in result.check( diagnostic: .contains( - "failed retrieving 'https://a.com/a.artifactbundleindex': No supported archive was found for '\(hostToolchain.triple.tripleString)'" + "failed retrieving 'https://a.com/a.artifactbundleindex': No supported archive was found for '\(hostToolchain.targetTriple.tripleString)'" ), severity: .error ) From 18a614105a3904dab5bc0a542aa590618e4a7b98 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Fri, 14 Jul 2023 16:40:22 +0100 Subject: [PATCH 2/3] Fix build error with incomplete renaming --- Sources/PackageModel/UserToolchain.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/PackageModel/UserToolchain.swift b/Sources/PackageModel/UserToolchain.swift index 1f83666728b..7c264f82e39 100644 --- a/Sources/PackageModel/UserToolchain.swift +++ b/Sources/PackageModel/UserToolchain.swift @@ -524,7 +524,7 @@ public final class UserToolchain: Toolchain { self.includeSearchPaths = swiftSDK.pathsConfiguration.includeSearchPaths ?? [] self.librarySearchPaths = swiftSDK.pathsConfiguration.includeSearchPaths ?? [] - self.librarianPath = try destination.toolset.knownTools[.librarian]?.path ?? UserToolchain.determineLibrarian( + self.librarianPath = try swiftSDK.toolset.knownTools[.librarian]?.path ?? UserToolchain.determineLibrarian( triple: triple, binDirectories: swiftSDK.toolset.rootPaths, useXcrun: useXcrun, From 63cbe1189d3a8197f7adad59d17104d008da4334 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Tue, 18 Jul 2023 14:36:56 +0100 Subject: [PATCH 3/3] Add `@_disfavoredOverload` to deprecated `BuildParameters.init` --- Sources/SPMBuildCore/BuildParameters.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/SPMBuildCore/BuildParameters.swift b/Sources/SPMBuildCore/BuildParameters.swift index 92259b9a97a..b04660430ff 100644 --- a/Sources/SPMBuildCore/BuildParameters.swift +++ b/Sources/SPMBuildCore/BuildParameters.swift @@ -269,6 +269,7 @@ public struct BuildParameters: Encodable { public var debugInfoFormat: DebugInfoFormat @available(*, deprecated, message: "use `init` overload with `targetTriple` parameter name instead") + @_disfavoredOverload public init( dataPath: AbsolutePath, configuration: BuildConfiguration,