diff --git a/README.md b/README.md index a5da6fc..9f0fd27 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,8 @@ installed, in case you've used the `swift experimental-sdk install` command befo ## Supported platforms and minimum versions -macOS as a host platform and a few Linux distributions as target platforms are supported by the generator. -Support for Linux as a host platform is currently in development. Eventually, the generator will allow cross-compiling between any -Linux distributions officially supported by the Swift project. +macOS as a host platform and Linux as both host and target platforms are supported by the generator. +The generator also allows cross-compiling between any Linux distributions officially supported by the Swift project. | Platform | Supported Version as Host | Supported Version as Target | | -: | :- | :- | diff --git a/Sources/GeneratorCLI/GeneratorCLI.swift b/Sources/GeneratorCLI/GeneratorCLI.swift index 9634c55..9f1af3d 100644 --- a/Sources/GeneratorCLI/GeneratorCLI.swift +++ b/Sources/GeneratorCLI/GeneratorCLI.swift @@ -17,19 +17,29 @@ import struct SystemPackage.FilePath @main struct GeneratorCLI: AsyncParsableCommand { + static let appLogger = Logger(label: "org.swift.swift-sdk-generator") + static let configuration = CommandConfiguration( commandName: "swift-sdk-generator", subcommands: [MakeLinuxSDK.self, MakeWasmSDK.self], defaultSubcommand: MakeLinuxSDK.self ) + static func loggerWithLevel(from options: GeneratorOptions) -> Logger { + var logger = self.appLogger + if options.verbose { + logger.logLevel = .debug + } + return logger + } + static func run( recipe: some SwiftSDKRecipe, targetTriple: Triple, options: GeneratorOptions ) async throws { + let logger = loggerWithLevel(from: options) let elapsed = try await ContinuousClock().measure { - let logger = Logger(label: "org.swift.swift-sdk-generator") let generator = try await SwiftSDKGenerator( bundleVersion: options.bundleVersion, targetTriple: targetTriple, @@ -57,7 +67,7 @@ struct GeneratorCLI: AsyncParsableCommand { try await generatorTask.value } - print("\nTime taken for this generator run: \(elapsed.intervalString).") + logger.info("Generator run finished successfully.", metadata: ["elapsedTime": .string(elapsed.intervalString)]) } } @@ -151,7 +161,7 @@ extension GeneratorCLI { let current = try SwiftSDKGenerator.getCurrentTriple(isVerbose: self.verbose) if let arch = hostArch { let target = Triple(arch: arch, vendor: current.vendor!, os: current.os!) - print("deprecated: Please use `--host \(target.triple)` instead of `--host-arch \(arch)`") + appLogger.warning("deprecated: Please use `--host \(target.triple)` instead of `--host-arch \(arch)`") return target } return current @@ -202,14 +212,14 @@ extension GeneratorCLI { } if let arch = generatorOptions.targetArch { let target = Triple(arch: arch, vendor: nil, os: .linux, environment: .gnu) - print("deprecated: Please use `--target \(target.triple)` instead of `--target-arch \(arch)`") + appLogger.warning("deprecated: Please use `--target \(target.triple)` instead of `--target-arch \(arch)`") } return Triple(arch: hostTriple.arch!, vendor: nil, os: .linux, environment: .gnu) } func run() async throws { if self.isInvokedAsDefaultSubcommand() { - print( + appLogger.warning( "deprecated: Please explicitly specify the subcommand to run. For example: $ swift-sdk-generator make-linux-sdk" ) } @@ -236,7 +246,8 @@ extension GeneratorCLI { fromContainerImage: self.fromContainerImage, hostSwiftPackagePath: self.generatorOptions.hostSwiftPackagePath, targetSwiftPackagePath: self.generatorOptions.targetSwiftPackagePath, - includeHostToolchain: self.generatorOptions.hostToolchain + includeHostToolchain: self.generatorOptions.hostToolchain, + logger: loggerWithLevel(from: self.generatorOptions) ) try await GeneratorCLI.run(recipe: recipe, targetTriple: targetTriple, options: self.generatorOptions) } @@ -290,7 +301,8 @@ extension GeneratorCLI { }, targetSwiftPackagePath: FilePath(targetSwiftPackagePath), wasiSysroot: FilePath(self.wasiSysroot), - swiftVersion: self.generatorOptions.swiftVersion + swiftVersion: self.generatorOptions.swiftVersion, + logger: loggerWithLevel(from: self.generatorOptions) ) let targetTriple = self.deriveTargetTriple() try await GeneratorCLI.run(recipe: recipe, targetTriple: targetTriple, options: self.generatorOptions) diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift index 10a5ebc..0b52cee 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift @@ -18,7 +18,7 @@ extension SwiftSDKGenerator { baseDockerImage: String, sdkDirPath: FilePath ) async throws { - logGenerationStep("Launching a container to extract the Swift SDK for the target triple...") + logger.info("Launching a container to extract the Swift SDK for the target triple...") try await withDockerContainer(fromImage: baseDockerImage) { containerID in try await inTemporaryDirectory { generator, _ in let sdkUsrPath = sdkDirPath.appending("usr") @@ -102,7 +102,7 @@ extension SwiftSDKGenerator { } func copyTargetSwift(from distributionPath: FilePath, sdkDirPath: FilePath) async throws { - logGenerationStep("Copying Swift core libraries for the target triple into Swift SDK bundle...") + logger.info("Copying Swift core libraries for the target triple into Swift SDK bundle...") for (pathWithinPackage, pathWithinSwiftSDK) in [ ("lib/swift", sdkDirPath.appending("usr/lib")), diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Download.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Download.swift index b9f7124..46aeb44 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Download.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Download.swift @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// import AsyncAlgorithms +import Logging import Helpers import RegexBuilder @@ -23,13 +24,19 @@ import struct SystemPackage.FilePath private let ubuntuAMD64Mirror = "http://gb.archive.ubuntu.com/ubuntu" private let ubuntuARM64Mirror = "http://ports.ubuntu.com/ubuntu-ports" +extension FilePath { + var metadataValue: Logger.MetadataValue { + .string(self.string) + } +} + extension SwiftSDKGenerator { func downloadArtifacts( _ client: some HTTPClientProtocol, _ engine: QueryEngine, downloadableArtifacts: inout DownloadableArtifacts, itemsToDownload: @Sendable (DownloadableArtifacts) -> [DownloadableArtifacts.Item] ) async throws { - logGenerationStep("Downloading required toolchain packages...") + logger.info("Downloading required toolchain packages...") let hostLLVMURL = downloadableArtifacts.hostLLVM.remoteURL // Workaround an issue with github.com returning 400 instead of 404 status to HEAD requests from AHC. let isLLVMBinaryArtifactAvailable = try await type(of: client).with(http1Only: true) { @@ -46,7 +53,7 @@ extension SwiftSDKGenerator { let results = try await withThrowingTaskGroup(of: FileCacheRecord.self) { group in for item in itemsToDownload(downloadableArtifacts) { group.addTask { - try await engine[DownloadArtifactQuery(artifact: item, httpClient: client)] + try await engine[DownloadArtifactQuery(artifact: item, httpClient: client, logger: self.logger)] } } @@ -57,10 +64,10 @@ extension SwiftSDKGenerator { return result } - print("Using downloaded artifacts in these locations:") - for path in results.map(\.path) { - print(path) - } + logger.info("Using downloaded artifacts from cache") + logger.debug("Using downloaded artifacts in these locations.", metadata: [ + "paths": .array(results.map(\.path.metadataValue)) + ]) } func downloadUbuntuPackages( @@ -70,7 +77,7 @@ extension SwiftSDKGenerator { versionsConfiguration: VersionsConfiguration, sdkDirPath: FilePath ) async throws { - logGenerationStep("Parsing Ubuntu packages list...") + logger.debug("Parsing Ubuntu packages list...") async let mainPackages = try await client.parseUbuntuPackagesList( ubuntuRelease: versionsConfiguration.linuxDistribution.release, @@ -108,12 +115,13 @@ extension SwiftSDKGenerator { ) } - print("Downloading \(urls.count) Ubuntu packages...") + logger.info("Downloading Ubuntu packages...", metadata: ["packageCount": .stringConvertible(urls.count)]) try await inTemporaryDirectory { fs, tmpDir in let downloadedFiles = try await self.downloadFiles(from: urls, to: tmpDir, client, engine) - report(downloadedFiles: downloadedFiles) + await report(downloadedFiles: downloadedFiles) for fileName in urls.map(\.lastPathComponent) { + logger.debug("Extracting deb package...", metadata: ["fileName": .string(fileName)]) try await fs.unpack(file: tmpDir.appending(fileName), into: sdkDirPath) } } @@ -148,13 +156,16 @@ extension SwiftSDKGenerator { return result } } -} -private func report(downloadedFiles: [(URL, UInt64)]) { - let byteCountFormatter = ByteCountFormatter() + private func report(downloadedFiles: [(URL, UInt64)]) { + let byteCountFormatter = ByteCountFormatter() - for (url, bytes) in downloadedFiles { - print("\(url) – \(byteCountFormatter.string(fromByteCount: Int64(bytes)))") + for (url, bytes) in downloadedFiles { + logger.debug("Downloaded package", metadata: [ + "url": .string(url.absoluteString), + "size": .string(byteCountFormatter.string(fromByteCount: Int64(bytes))) + ]) + } } } diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Entrypoint.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Entrypoint.swift index 448f225..c4ec429 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Entrypoint.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Entrypoint.swift @@ -59,20 +59,20 @@ public extension SwiftSDKGenerator { try await generateArtifactBundleManifest(hostTriples: swiftSDKProduct.hostTriples) - logGenerationStep( + // Extra spaces added for readability for the user + logger.info( """ + + All done! Install the newly generated SDK with this command: swift experimental-sdk install \(pathsConfiguration.artifactBundlePath) After that, use the newly installed SDK when building with this command: swift build --experimental-swift-sdk \(artifactID) + """ ) } } } } - -func logGenerationStep(_ message: String) { - print("\n\(message)") -} diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Fixup.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Fixup.swift index 4db44f1..ea587cb 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Fixup.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Fixup.swift @@ -17,7 +17,7 @@ import struct Foundation.Data extension SwiftSDKGenerator { func fixAbsoluteSymlinks(sdkDirPath: FilePath) throws { - logGenerationStep("Fixing up absolute symlinks...") + logger.info("Fixing up absolute symlinks...") for (source, absoluteDestination) in try findSymlinks(at: sdkDirPath).filter({ $1.string.hasPrefix("/") @@ -51,7 +51,7 @@ extension SwiftSDKGenerator { func symlinkClangHeaders() throws { let swiftStaticClangPath = self.pathsConfiguration.toolchainDirPath.appending("usr/lib/swift_static/clang") if !doesFileExist(at: swiftStaticClangPath) { - logGenerationStep("Symlinking clang headers...") + logger.info("Symlinking clang headers...") try self.createSymlink( at: self.pathsConfiguration.toolchainDirPath.appending("usr/lib/swift_static/clang"), pointingTo: "../swift/clang" diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Metadata.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Metadata.swift index 2d1a62d..b9985dc 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Metadata.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Metadata.swift @@ -22,7 +22,7 @@ private let encoder: JSONEncoder = { extension SwiftSDKGenerator { func generateToolsetJSON(recipe: SwiftSDKRecipe) throws -> FilePath { - logGenerationStep("Generating toolset JSON file...") + logger.info("Generating toolset JSON file...") let toolsetJSONPath = pathsConfiguration.swiftSDKRootPath.appending("toolset.json") @@ -44,7 +44,7 @@ extension SwiftSDKGenerator { } func generateDestinationJSON(toolsetPath: FilePath, sdkDirPath: FilePath, recipe: SwiftSDKRecipe) throws { - logGenerationStep("Generating destination JSON file...") + logger.info("Generating destination JSON file...") let destinationJSONPath = pathsConfiguration.swiftSDKRootPath.appending("swift-sdk.json") @@ -87,7 +87,7 @@ extension SwiftSDKGenerator { } func generateArtifactBundleManifest(hostTriples: [Triple]?) throws { - logGenerationStep("Generating .artifactbundle manifest file...") + logger.info("Generating .artifactbundle info JSON file...") let artifactBundleManifestPath = pathsConfiguration.artifactBundlePath.appending("info.json") diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Unpack.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Unpack.swift index ff48e7f..d025768 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Unpack.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Unpack.swift @@ -45,7 +45,7 @@ let unusedHostLibraries = [ extension SwiftSDKGenerator { func unpackHostSwift(hostSwiftPackagePath: FilePath) async throws { - logGenerationStep("Unpacking and copying Swift binaries for the host triple...") + logger.info("Unpacking and copying Swift binaries for the host triple...") let pathsConfiguration = self.pathsConfiguration try self.createDirectoryIfNeeded(at: pathsConfiguration.toolchainDirPath) @@ -98,7 +98,7 @@ extension SwiftSDKGenerator { relativePathToRoot: [FilePath.Component], sdkDirPath: FilePath ) async throws { - logGenerationStep("Unpacking Swift distribution for the target triple...") + logger.info("Unpacking Swift distribution for the target triple...") try await inTemporaryDirectory { fs, tmpDir in try await fs.unpack(file: targetSwiftPackagePath, into: tmpDir) @@ -109,7 +109,7 @@ extension SwiftSDKGenerator { } func prepareLLDLinker(_ engine: QueryEngine, llvmArtifact: DownloadableArtifacts.Item) async throws { - logGenerationStep("Unpacking and copying `lld` linker...") + logger.info("Unpacking and copying `lld` linker...") let pathsConfiguration = self.pathsConfiguration let targetOS = self.targetTriple.os diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator.swift index 53637c6..0db1d5e 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator.swift @@ -34,8 +34,6 @@ public actor SwiftSDKGenerator { isVerbose: Bool, logger: Logger ) async throws { - logGenerationStep("Looking up configuration values...") - let sourceRoot = FilePath(#filePath) .removingLastComponent() .removingLastComponent() @@ -253,7 +251,11 @@ public actor SwiftSDKGenerator { let isVerbose = self.isVerbose try await self.inTemporaryDirectory { _, tmp in try await Shell.run(#"cd "\#(tmp)" && ar -x "\#(debFile)""#, shouldLogCommands: isVerbose) - try await print(Shell.readStdout("ls \(tmp)")) + if isVerbose { + let cmd = "ls \(tmp)" + let lsOutput = try await Shell.readStdout(cmd) + logger.debug("Files unpacked from deb file", metadata: ["cmd": .string(cmd), "output": .string(lsOutput)]) + } try await Shell.run( #"tar -C "\#(directoryPath)" -xf "\#(tmp)"/data.tar.*"#, diff --git a/Sources/SwiftSDKGenerator/Queries/DownloadArtifactQuery.swift b/Sources/SwiftSDKGenerator/Queries/DownloadArtifactQuery.swift index b95fb26..041737c 100644 --- a/Sources/SwiftSDKGenerator/Queries/DownloadArtifactQuery.swift +++ b/Sources/SwiftSDKGenerator/Queries/DownloadArtifactQuery.swift @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// import class Foundation.ByteCountFormatter +import Logging import Helpers import struct SystemPackage.FilePath @@ -18,9 +19,10 @@ struct DownloadArtifactQuery: Query { var cacheKey: some CacheKey { self.artifact } let artifact: DownloadableArtifacts.Item let httpClient: any HTTPClientProtocol + let logger: Logger func run(engine: QueryEngine) async throws -> FilePath { - print("Downloading remote artifact not available in local cache: \(self.artifact.remoteURL)") + logger.info("Downloading remote artifact not available in local cache", metadata: ["remoteUrl": .string(self.artifact.remoteURL.absoluteString)]) let stream = self.httpClient.streamDownloadProgress( from: self.artifact.remoteURL, to: self.artifact.localPath ) @@ -32,6 +34,26 @@ struct DownloadArtifactQuery: Query { } return self.artifact.localPath } + + private func report(progress: DownloadProgress, for artifact: DownloadableArtifacts.Item) { + let byteCountFormatter = ByteCountFormatter() + + if let total = progress.totalBytes { + logger.debug(""" + \(artifact.remoteURL.lastPathComponent) \( + byteCountFormatter + .string(fromByteCount: Int64(progress.receivedBytes)) + )/\( + byteCountFormatter + .string(fromByteCount: Int64(total)) + ) + """) + } else { + logger.debug( + "\(artifact.remoteURL.lastPathComponent) \(byteCountFormatter.string(fromByteCount: Int64(progress.receivedBytes)))" + ) + } + } } /// Checks whether two given progress value are different enough from each other. Used for filtering out progress @@ -52,23 +74,3 @@ private func didProgressChangeSignificantly( return current.receivedBytes - previous.receivedBytes > 1024 * 1024 * 1024 } - -private func report(progress: DownloadProgress, for artifact: DownloadableArtifacts.Item) { - let byteCountFormatter = ByteCountFormatter() - - if let total = progress.totalBytes { - print(""" - \(artifact.remoteURL.lastPathComponent) \( - byteCountFormatter - .string(fromByteCount: Int64(progress.receivedBytes)) - )/\( - byteCountFormatter - .string(fromByteCount: Int64(total)) - ) - """) - } else { - print( - "\(artifact.remoteURL.lastPathComponent) \(byteCountFormatter.string(fromByteCount: Int64(progress.receivedBytes)))" - ) - } -} diff --git a/Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift b/Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift index a22fe10..ffa9266 100644 --- a/Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift +++ b/Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// import Foundation +import Logging import Helpers import struct SystemPackage.FilePath @@ -33,6 +34,7 @@ public struct LinuxRecipe: SwiftSDKRecipe { let targetSwiftSource: TargetSwiftSource let hostSwiftSource: HostSwiftSource let versionsConfiguration: VersionsConfiguration + public let logger: Logger var shouldUseDocker: Bool { if case .docker = self.targetSwiftSource { @@ -52,7 +54,8 @@ public struct LinuxRecipe: SwiftSDKRecipe { fromContainerImage: String?, hostSwiftPackagePath: String?, targetSwiftPackagePath: String?, - includeHostToolchain: Bool = false + includeHostToolchain: Bool = false, + logger: Logger ) throws { let versionsConfiguration = try VersionsConfiguration( swiftVersion: swiftVersion, @@ -88,7 +91,8 @@ public struct LinuxRecipe: SwiftSDKRecipe { linuxDistribution: linuxDistribution, targetSwiftSource: targetSwiftSource, hostSwiftSource: hostSwiftSource, - versionsConfiguration: versionsConfiguration + versionsConfiguration: versionsConfiguration, + logger: logger ) } @@ -98,7 +102,8 @@ public struct LinuxRecipe: SwiftSDKRecipe { linuxDistribution: LinuxDistribution, targetSwiftSource: TargetSwiftSource, hostSwiftSource: HostSwiftSource, - versionsConfiguration: VersionsConfiguration + versionsConfiguration: VersionsConfiguration, + logger: Logger ) { self.mainTargetTriple = mainTargetTriple self.mainHostTriple = mainHostTriple @@ -106,6 +111,7 @@ public struct LinuxRecipe: SwiftSDKRecipe { self.targetSwiftSource = targetSwiftSource self.hostSwiftSource = hostSwiftSource self.versionsConfiguration = versionsConfiguration + self.logger = logger } public func applyPlatformOptions(toolset: inout Toolset, targetTriple: Triple) { @@ -295,7 +301,7 @@ public struct LinuxRecipe: SwiftSDKRecipe { let autolinkExtractPath = generator.pathsConfiguration.toolchainBinDirPath.appending("swift-autolink-extract") if await !generator.doesFileExist(at: autolinkExtractPath) { - logGenerationStep("Fixing `swift-autolink-extract` symlink...") + logger.info("Fixing `swift-autolink-extract` symlink...") try await generator.createSymlink(at: autolinkExtractPath, pointingTo: "swift") } } diff --git a/Sources/SwiftSDKGenerator/SwiftSDKRecipes/SwiftSDKRecipe.swift b/Sources/SwiftSDKGenerator/SwiftSDKRecipes/SwiftSDKRecipe.swift index baeda00..17908a4 100644 --- a/Sources/SwiftSDKGenerator/SwiftSDKRecipes/SwiftSDKRecipe.swift +++ b/Sources/SwiftSDKGenerator/SwiftSDKRecipes/SwiftSDKRecipe.swift @@ -10,6 +10,7 @@ // //===----------------------------------------------------------------------===// +import Logging import Helpers import struct SystemPackage.FilePath @@ -34,6 +35,9 @@ public protocol SwiftSDKRecipe: Sendable { /// The default identifier of the Swift SDK var defaultArtifactID: String { get } + /// The logger to use for recipe generators. + var logger: Logger { get } + /// The main entrypoint of the recipe to make a Swift SDK func makeSwiftSDK(generator: SwiftSDKGenerator, engine: QueryEngine, httpClient: some HTTPClientProtocol) async throws -> SwiftSDKProduct diff --git a/Sources/SwiftSDKGenerator/SwiftSDKRecipes/WebAssemblyRecipe.swift b/Sources/SwiftSDKGenerator/SwiftSDKRecipes/WebAssemblyRecipe.swift index e935546..21b2485 100644 --- a/Sources/SwiftSDKGenerator/SwiftSDKRecipes/WebAssemblyRecipe.swift +++ b/Sources/SwiftSDKGenerator/SwiftSDKRecipes/WebAssemblyRecipe.swift @@ -10,6 +10,7 @@ // //===----------------------------------------------------------------------===// +import Logging import Helpers import struct SystemPackage.FilePath @@ -18,6 +19,7 @@ public struct WebAssemblyRecipe: SwiftSDKRecipe { let targetSwiftPackagePath: FilePath let wasiSysroot: FilePath let swiftVersion: String + public let logger: Logger public struct HostToolchainPackage: Sendable { let path: FilePath @@ -33,12 +35,14 @@ public struct WebAssemblyRecipe: SwiftSDKRecipe { hostSwiftPackage: HostToolchainPackage?, targetSwiftPackagePath: FilePath, wasiSysroot: FilePath, - swiftVersion: String + swiftVersion: String, + logger: Logger ) { self.hostSwiftPackage = hostSwiftPackage self.targetSwiftPackagePath = targetSwiftPackagePath self.wasiSysroot = wasiSysroot self.swiftVersion = swiftVersion + self.logger = logger } public var defaultArtifactID: String { @@ -96,13 +100,13 @@ public struct WebAssemblyRecipe: SwiftSDKRecipe { let pathsConfiguration = generator.pathsConfiguration let targetSwiftLibPath = self.targetSwiftPackagePath.appending("usr/lib") - logGenerationStep("Copying Swift binaries for the host triple...") + logger.info("Copying Swift binaries for the host triple...") var hostTriples: [Triple]? = nil if let hostSwiftPackage { hostTriples = [hostSwiftPackage.triple] try await generator.rsync(from: hostSwiftPackage.path.appending("usr"), to: pathsConfiguration.toolchainDirPath) - logGenerationStep("Removing unused toolchain components...") + logger.info("Removing unused toolchain components...") let liblldbNames: [String] = try await { let libDirPath = pathsConfiguration.toolchainDirPath.appending("usr/lib") guard await generator.doesFileExist(at: libDirPath) else { @@ -133,7 +137,7 @@ public struct WebAssemblyRecipe: SwiftSDKRecipe { if await !generator.doesFileExist(at: autolinkExtractPath), await generator.doesFileExist(at: generator.pathsConfiguration.toolchainBinDirPath.appending("swift")) { - logGenerationStep("Fixing `swift-autolink-extract` symlink...") + logger.info("Fixing `swift-autolink-extract` symlink...") try await generator.createSymlink(at: autolinkExtractPath, pointingTo: "swift") } @@ -147,7 +151,7 @@ public struct WebAssemblyRecipe: SwiftSDKRecipe { /// Merge the target Swift package into the Swift SDK bundle derived from the host Swift package. func mergeTargetSwift(from distributionPath: FilePath, generator: SwiftSDKGenerator) async throws { let pathsConfiguration = generator.pathsConfiguration - logGenerationStep("Copying Swift core libraries for the target triple into Swift SDK bundle...") + logger.info("Copying Swift core libraries for the target triple into Swift SDK bundle...") for (pathWithinPackage, pathWithinSwiftSDK, isOptional) in [ ("clang", pathsConfiguration.toolchainDirPath.appending("usr/lib"), false), ("swift/clang", pathsConfiguration.toolchainDirPath.appending("usr/lib/swift"), false), @@ -159,7 +163,7 @@ public struct WebAssemblyRecipe: SwiftSDKRecipe { ("swift_static/CoreFoundation", pathsConfiguration.toolchainDirPath.appending("usr/lib/swift_static"), true), ] { if isOptional, await !(generator.doesFileExist(at: distributionPath.appending(pathWithinPackage))) { - logGenerationStep("Skipping optional path \(pathWithinPackage)") + logger.debug("Skipping optional path \(pathWithinPackage)") continue } try await generator.rsync(from: distributionPath.appending(pathWithinPackage), to: pathWithinSwiftSDK) diff --git a/Tests/SwiftSDKGeneratorTests/ArchitectureMappingTests.swift b/Tests/SwiftSDKGeneratorTests/ArchitectureMappingTests.swift index a06551a..9202c2a 100644 --- a/Tests/SwiftSDKGeneratorTests/ArchitectureMappingTests.swift +++ b/Tests/SwiftSDKGeneratorTests/ArchitectureMappingTests.swift @@ -15,6 +15,8 @@ import Logging import XCTest final class ArchitectureMappingTests: XCTestCase { + let logger = Logger(label: "ArchitectureMappingTests") + /// Swift on macOS, Swift on Linux and Debian packages all use /// different names for the x86 and Arm architectures: /// @@ -54,7 +56,8 @@ final class ArchitectureMappingTests: XCTestCase { withDocker: false, fromContainerImage: nil, hostSwiftPackagePath: nil, - targetSwiftPackagePath: nil + targetSwiftPackagePath: nil, + logger: logger ) // LocalSwiftSDKGenerator constructs URLs and paths which depend on architectures let sdk = try await SwiftSDKGenerator( diff --git a/Tests/SwiftSDKGeneratorTests/SwiftSDKRecipes/LinuxRecipeTests.swift b/Tests/SwiftSDKGeneratorTests/SwiftSDKRecipes/LinuxRecipeTests.swift index 75f9737..436b705 100644 --- a/Tests/SwiftSDKGeneratorTests/SwiftSDKRecipes/LinuxRecipeTests.swift +++ b/Tests/SwiftSDKGeneratorTests/SwiftSDKRecipes/LinuxRecipeTests.swift @@ -10,11 +10,14 @@ // //===----------------------------------------------------------------------===// +import Logging import XCTest @testable import SwiftSDKGenerator final class LinuxRecipeTests: XCTestCase { + let logger = Logger(label: "LinuxRecipeTests") + func createRecipe( hostTriple: Triple = Triple("x86_64-unknown-linux-gnu"), swiftVersion: String = "6.0", @@ -33,7 +36,8 @@ final class LinuxRecipeTests: XCTestCase { withDocker: withDocker, fromContainerImage: fromContainerImage, hostSwiftPackagePath: hostSwiftPackagePath, targetSwiftPackagePath: targetSwiftPackagePath, - includeHostToolchain: includeHostToolchain + includeHostToolchain: includeHostToolchain, + logger: logger ) } diff --git a/Tests/SwiftSDKGeneratorTests/SwiftSDKRecipes/WebAssemblyRecipe.swift b/Tests/SwiftSDKGeneratorTests/SwiftSDKRecipes/WebAssemblyRecipe.swift index 8bb770c..71eff42 100644 --- a/Tests/SwiftSDKGeneratorTests/SwiftSDKRecipes/WebAssemblyRecipe.swift +++ b/Tests/SwiftSDKGeneratorTests/SwiftSDKRecipes/WebAssemblyRecipe.swift @@ -10,17 +10,21 @@ // //===----------------------------------------------------------------------===// +import Logging import XCTest @testable import SwiftSDKGenerator final class WebAssemblyRecipeTests: XCTestCase { + let logger = Logger(label: "WebAssemblyRecipeTests") + func createRecipe() -> WebAssemblyRecipe { WebAssemblyRecipe( hostSwiftPackage: nil, targetSwiftPackagePath: "./target-toolchain", wasiSysroot: "./wasi-sysroot", - swiftVersion: "5.10" + swiftVersion: "5.10", + logger: logger ) }