@@ -17,7 +17,7 @@ import struct SystemPackage.FilePath
1717
1818package struct WebAssemblyRecipe : SwiftSDKRecipe {
1919 let hostSwiftPackage : HostToolchainPackage ?
20- let targetSwiftPackagePath : FilePath
20+ let targetSwiftPackagePath : FilePath ?
2121 let wasiSysroot : FilePath
2222 let swiftVersion : String
2323 package let logger : Logger
@@ -34,7 +34,7 @@ package struct WebAssemblyRecipe: SwiftSDKRecipe {
3434
3535 package init (
3636 hostSwiftPackage: HostToolchainPackage ? ,
37- targetSwiftPackagePath: FilePath ,
37+ targetSwiftPackagePath: FilePath ? ,
3838 wasiSysroot: FilePath ,
3939 swiftVersion: String ,
4040 logger: Logger
@@ -47,7 +47,10 @@ package struct WebAssemblyRecipe: SwiftSDKRecipe {
4747 }
4848
4949 package var defaultArtifactID : String {
50- " \( self . swiftVersion) _wasm "
50+ if hostSwiftPackage == nil && targetSwiftPackagePath == nil {
51+ return " wasm "
52+ }
53+ return " \( self . swiftVersion) _wasm "
5154 }
5255
5356 package let shouldSupportEmbeddedSwift = true
@@ -140,71 +143,71 @@ package struct WebAssemblyRecipe: SwiftSDKRecipe {
140143 httpClient: some HTTPClientProtocol
141144 ) async throws -> SwiftSDKProduct {
142145 let pathsConfiguration = generator. pathsConfiguration
143- let targetSwiftLibPath = self . targetSwiftPackagePath. appending ( " usr/lib " )
144-
145- logger. info ( " Copying Swift binaries for the host triple... " )
146146 var hostTriples : [ Triple ] ? = nil
147- if let hostSwiftPackage {
148- hostTriples = hostSwiftPackage. triples
149- try await generator. rsync (
150- from: hostSwiftPackage. path. appending ( " usr " ) ,
151- to: pathsConfiguration. toolchainDirPath
152- )
147+ if let targetSwiftLibPath = self . targetSwiftPackagePath? . appending ( " usr/lib " ) {
148+ logger. info ( " Copying Swift binaries for the host triple... " )
149+ if let hostSwiftPackage {
150+ hostTriples = hostSwiftPackage. triples
151+ try await generator. rsync (
152+ from: hostSwiftPackage. path. appending ( " usr " ) ,
153+ to: pathsConfiguration. toolchainDirPath
154+ )
153155
154- logger. info ( " Removing unused toolchain components... " )
155- let liblldbNames : [ String ] = try await {
156- let libDirPath = pathsConfiguration. toolchainDirPath. appending ( " usr/lib " )
157- guard await generator. doesFileExist ( at: libDirPath) else {
158- return [ ]
159- }
160- return try await generator. contentsOfDirectory ( at: libDirPath) . filter { dirEntry in
161- // liblldb is version suffixed: liblldb.so.17.0.0
162- dirEntry. hasPrefix ( " liblldb " )
163- }
164- } ( )
165- try await generator. removeToolchainComponents (
166- pathsConfiguration. toolchainDirPath,
167- platforms: unusedTargetPlatforms,
168- libraries: unusedHostLibraries + liblldbNames,
169- binaries: unusedHostBinaries + [ " lldb " , " lldb-argdumper " , " lldb-server " ]
170- )
171- // Merge target Swift package with the host package.
172- try await self . mergeTargetSwift ( from: targetSwiftLibPath, generator: generator)
173- } else {
174- // Simply copy the target Swift package into the SDK bundle when building host-agnostic SDK.
175- try await generator. createDirectoryIfNeeded (
176- at: pathsConfiguration. toolchainDirPath. appending ( " usr " )
177- )
178- try await generator. copy (
179- from: targetSwiftLibPath,
180- to: pathsConfiguration. toolchainDirPath. appending ( " usr/lib " )
181- )
182- }
183-
184- let autolinkExtractPath = pathsConfiguration. toolchainBinDirPath. appending (
185- " swift-autolink-extract "
186- )
156+ logger. info ( " Removing unused toolchain components... " )
157+ let liblldbNames : [ String ] = try await {
158+ let libDirPath = pathsConfiguration. toolchainDirPath. appending ( " usr/lib " )
159+ guard await generator. doesFileExist ( at: libDirPath) else {
160+ return [ ]
161+ }
162+ return try await generator. contentsOfDirectory ( at: libDirPath) . filter { dirEntry in
163+ // liblldb is version suffixed: liblldb.so.17.0.0
164+ dirEntry. hasPrefix ( " liblldb " )
165+ }
166+ } ( )
167+ try await generator. removeToolchainComponents (
168+ pathsConfiguration. toolchainDirPath,
169+ platforms: unusedTargetPlatforms,
170+ libraries: unusedHostLibraries + liblldbNames,
171+ binaries: unusedHostBinaries + [ " lldb " , " lldb-argdumper " , " lldb-server " ]
172+ )
173+ // Merge target Swift package with the host package.
174+ try await self . mergeTargetSwift ( from: targetSwiftLibPath, generator: generator)
175+ } else {
176+ // Simply copy the target Swift package into the SDK bundle when building host-agnostic SDK.
177+ try await generator. createDirectoryIfNeeded (
178+ at: pathsConfiguration. toolchainDirPath. appending ( " usr " )
179+ )
180+ try await generator. copy (
181+ from: targetSwiftLibPath,
182+ to: pathsConfiguration. toolchainDirPath. appending ( " usr/lib " )
183+ )
184+ }
187185
188- // WebAssembly object file requires `swift-autolink-extract`
189- if await !generator. doesFileExist ( at: autolinkExtractPath) ,
190- await generator. doesFileExist (
191- at: generator. pathsConfiguration. toolchainBinDirPath. appending ( " swift " )
186+ let autolinkExtractPath = pathsConfiguration. toolchainBinDirPath. appending (
187+ " swift-autolink-extract "
192188 )
193- {
194- logger. info ( " Fixing `swift-autolink-extract` symlink... " )
195- try await generator. createSymlink ( at: autolinkExtractPath, pointingTo: " swift " )
196- }
197189
198- // TODO: Remove this once we drop support for Swift 6.2
199- // Embedded Swift looks up clang compiler-rt in a different path.
200- let embeddedCompilerRTPath = pathsConfiguration. toolchainDirPath. appending (
201- " usr/lib/swift/clang/lib/wasip1 "
202- )
203- if await !generator. doesFileExist ( at: embeddedCompilerRTPath) {
204- try await generator. createSymlink (
205- at: embeddedCompilerRTPath,
206- pointingTo: " ../../../swift_static/clang/lib/wasi "
190+ // WebAssembly object file requires `swift-autolink-extract`
191+ if await !generator. doesFileExist ( at: autolinkExtractPath) ,
192+ await generator. doesFileExist (
193+ at: generator. pathsConfiguration. toolchainBinDirPath. appending ( " swift " )
194+ )
195+ {
196+ logger. info ( " Fixing `swift-autolink-extract` symlink... " )
197+ try await generator. createSymlink ( at: autolinkExtractPath, pointingTo: " swift " )
198+ }
199+
200+ // TODO: Remove this once we drop support for Swift 6.2
201+ // Embedded Swift looks up clang compiler-rt in a different path.
202+ let embeddedCompilerRTPath = pathsConfiguration. toolchainDirPath. appending (
203+ " usr/lib/swift/clang/lib/wasip1 "
207204 )
205+ if await !generator. doesFileExist ( at: embeddedCompilerRTPath) {
206+ try await generator. createSymlink (
207+ at: embeddedCompilerRTPath,
208+ pointingTo: " ../../../swift_static/clang/lib/wasi "
209+ )
210+ }
208211 }
209212
210213 // Copy the WASI sysroot into the SDK bundle.
0 commit comments