Skip to content

Commit 13c0c51

Browse files
WasmSDK: Copy swift-foundation headers and apinotes into the Swift SDK bundle (#129)
* WasmSDK: Copy swift-foundation headers and apinotes into the Swift SDK bundle Those files are recently added to the toolchain, and they are required to build Swift code that uses Foundation on WebAssembly. We had been manually specifying the paths to copy from the target package into the SDK, but we now build host-agnostic SDKS. So we can just copy the whole `usr/lib` from the target Swift package into the SDK bundle instead of adding individual new paths. The host-specific build path is still used for 5.10 SDKs, so keep the old code as is for now, but it will be removed in the future. * Create swift.xctoolchain/usr directory before copying target package --------- Co-authored-by: Max Desiatov <[email protected]>
1 parent feec0b2 commit 13c0c51

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Sources/SwiftSDKGenerator/SwiftSDKRecipes/WebAssemblyRecipe.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ public struct WebAssemblyRecipe: SwiftSDKRecipe {
9494
httpClient: some HTTPClientProtocol
9595
) async throws -> SwiftSDKProduct {
9696
let pathsConfiguration = generator.pathsConfiguration
97+
let targetSwiftLibPath = self.targetSwiftPackagePath.appending("usr/lib")
98+
9799
logGenerationStep("Copying Swift binaries for the host triple...")
98100
var hostTriples: [Triple]? = nil
99101
if let hostSwiftPackage {
@@ -117,10 +119,14 @@ public struct WebAssemblyRecipe: SwiftSDKRecipe {
117119
libraries: unusedHostLibraries + liblldbNames,
118120
binaries: unusedHostBinaries + ["lldb", "lldb-argdumper", "lldb-server"]
119121
)
122+
// Merge target Swift package with the host package.
123+
try await self.mergeTargetSwift(from: targetSwiftLibPath, generator: generator)
124+
} else {
125+
// Simply copy the target Swift package into the SDK bundle when building host-agnostic SDK.
126+
try await generator.createDirectoryIfNeeded(at: pathsConfiguration.toolchainDirPath.appending("usr"))
127+
try await generator.copy(from: targetSwiftLibPath, to: pathsConfiguration.toolchainDirPath.appending("usr/lib"))
120128
}
121129

122-
try await self.copyTargetSwift(from: self.targetSwiftPackagePath.appending("usr/lib"), generator: generator)
123-
124130
let autolinkExtractPath = generator.pathsConfiguration.toolchainBinDirPath.appending("swift-autolink-extract")
125131

126132
// WebAssembly object file requires `swift-autolink-extract`
@@ -138,7 +144,8 @@ public struct WebAssemblyRecipe: SwiftSDKRecipe {
138144
return SwiftSDKProduct(sdkDirPath: sdkDirPath, hostTriples: hostTriples)
139145
}
140146

141-
func copyTargetSwift(from distributionPath: FilePath, generator: SwiftSDKGenerator) async throws {
147+
/// Merge the target Swift package into the Swift SDK bundle derived from the host Swift package.
148+
func mergeTargetSwift(from distributionPath: FilePath, generator: SwiftSDKGenerator) async throws {
142149
let pathsConfiguration = generator.pathsConfiguration
143150
logGenerationStep("Copying Swift core libraries for the target triple into Swift SDK bundle...")
144151
for (pathWithinPackage, pathWithinSwiftSDK, isOptional) in [

0 commit comments

Comments
 (0)