Skip to content

Commit 37e0dad

Browse files
Make --host-swift-package-path optional for WebAssembly recipe (#84)
Host toolchain is not always needed for DEVELOPMENT snapshot now, so make it optional.
1 parent c0d8638 commit 37e0dad

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

Sources/GeneratorCLI/GeneratorCLI.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,11 @@ extension GeneratorCLI {
264264
}
265265

266266
func run() async throws {
267-
guard let hostSwiftPackagePath = generatorOptions.hostSwiftPackagePath,
268-
let targetSwiftPackagePath = generatorOptions.targetSwiftPackagePath else {
269-
throw StringError("Missing expected argument '--host-swift-package-path' or '--target-swift-package-path'")
267+
guard let targetSwiftPackagePath = generatorOptions.targetSwiftPackagePath else {
268+
throw StringError("Missing expected argument '--target-swift-package-path'")
270269
}
271270
let recipe = WebAssemblyRecipe(
272-
hostSwiftPackagePath: FilePath(hostSwiftPackagePath),
271+
hostSwiftPackagePath: generatorOptions.hostSwiftPackagePath.map { FilePath($0) },
273272
targetSwiftPackagePath: FilePath(targetSwiftPackagePath),
274273
wasiSysroot: FilePath(wasiSysroot),
275274
swiftVersion: generatorOptions.swiftVersion

Sources/SwiftSDKGenerator/SwiftSDKRecipes/WebAssemblyRecipe.swift

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import GeneratorEngine
1515
import struct SystemPackage.FilePath
1616

1717
public struct WebAssemblyRecipe: SwiftSDKRecipe {
18-
let hostSwiftPackagePath: FilePath
18+
let hostSwiftPackagePath: FilePath?
1919
let targetSwiftPackagePath: FilePath
2020
let wasiSysroot: FilePath
2121
let swiftVersion: String
2222

2323
public init(
24-
hostSwiftPackagePath: FilePath,
24+
hostSwiftPackagePath: FilePath?,
2525
targetSwiftPackagePath: FilePath,
2626
wasiSysroot: FilePath,
2727
swiftVersion: String
@@ -48,22 +48,27 @@ public struct WebAssemblyRecipe: SwiftSDKRecipe {
4848
) async throws -> SwiftSDKProduct {
4949
let pathsConfiguration = generator.pathsConfiguration
5050
logGenerationStep("Copying Swift binaries for the host triple...")
51-
try await generator.rsync(from: self.hostSwiftPackagePath.appending("usr"), to: pathsConfiguration.toolchainDirPath)
51+
if let hostSwiftPackagePath {
52+
try await generator.rsync(from: hostSwiftPackagePath.appending("usr"), to: pathsConfiguration.toolchainDirPath)
5253

53-
logGenerationStep("Removing unused toolchain components...")
54-
let liblldbNames: [String] = try await {
55-
let libDirPath = pathsConfiguration.toolchainDirPath.appending("usr/lib")
56-
return try await generator.contentsOfDirectory(at: libDirPath).filter { dirEntry in
57-
// liblldb is version suffixed: liblldb.so.17.0.0
58-
dirEntry.hasPrefix("liblldb")
59-
}
60-
}()
61-
try await generator.removeToolchainComponents(
62-
pathsConfiguration.toolchainDirPath,
63-
platforms: unusedDarwinPlatforms + ["embedded"],
64-
libraries: unusedHostLibraries + liblldbNames,
65-
binaries: unusedHostBinaries + ["lldb", "lldb-argdumper", "lldb-server"]
66-
)
54+
logGenerationStep("Removing unused toolchain components...")
55+
let liblldbNames: [String] = try await {
56+
let libDirPath = pathsConfiguration.toolchainDirPath.appending("usr/lib")
57+
guard await generator.doesFileExist(at: libDirPath) else {
58+
return []
59+
}
60+
return try await generator.contentsOfDirectory(at: libDirPath).filter { dirEntry in
61+
// liblldb is version suffixed: liblldb.so.17.0.0
62+
dirEntry.hasPrefix("liblldb")
63+
}
64+
}()
65+
try await generator.removeToolchainComponents(
66+
pathsConfiguration.toolchainDirPath,
67+
platforms: unusedDarwinPlatforms + ["embedded"],
68+
libraries: unusedHostLibraries + liblldbNames,
69+
binaries: unusedHostBinaries + ["lldb", "lldb-argdumper", "lldb-server"]
70+
)
71+
}
6772

6873
try await self.copyTargetSwift(from: self.targetSwiftPackagePath.appending("usr/lib"), generator: generator)
6974

0 commit comments

Comments
 (0)