From d022f27b93c4fdebb0f7416e6b2ff43d3271770e Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Fri, 16 May 2025 13:57:03 +0100 Subject: [PATCH 1/2] Symlink `libclang_rt.builtins.a` for Embedded Swift for WASI Embedded Swift looks up clang compiler-rt in a different path than non-embedded. These paths could be normalized in the future, but for now the easiest fix seems to be just to symlink this static library. --- .../SwiftSDKRecipes/WebAssemblyRecipe.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftSDKGenerator/SwiftSDKRecipes/WebAssemblyRecipe.swift b/Sources/SwiftSDKGenerator/SwiftSDKRecipes/WebAssemblyRecipe.swift index de9a8d9..082c6e0 100644 --- a/Sources/SwiftSDKGenerator/SwiftSDKRecipes/WebAssemblyRecipe.swift +++ b/Sources/SwiftSDKGenerator/SwiftSDKRecipes/WebAssemblyRecipe.swift @@ -181,7 +181,7 @@ package struct WebAssemblyRecipe: SwiftSDKRecipe { ) } - let autolinkExtractPath = generator.pathsConfiguration.toolchainBinDirPath.appending( + let autolinkExtractPath = pathsConfiguration.toolchainBinDirPath.appending( "swift-autolink-extract" ) @@ -195,6 +195,17 @@ package struct WebAssemblyRecipe: SwiftSDKRecipe { try await generator.createSymlink(at: autolinkExtractPath, pointingTo: "swift") } + // Embedded Swift looks up clang compiler-rt in a different path. + let embeddedCompilerRTPath = pathsConfiguration.toolchainDirPath.appending( + "usr/lib/swift/clang/lib/wasm32-unknown-wasip1" + ) + + try await generator.createDirectoryIfNeeded(at: embeddedCompilerRTPath) + try await generator.createSymlink( + at: embeddedCompilerRTPath.appending("libclang_rt.builtins.a"), + pointingTo: "../../../../swift_static/clang/lib/wasi/libclang_rt.builtins-wasm32.a" + ) + // Copy the WASI sysroot into the SDK bundle. let sdkDirPath = pathsConfiguration.swiftSDKRootPath.appending("WASI.sdk") try await generator.rsyncContents(from: self.wasiSysroot, to: sdkDirPath) From f2e39cbd6afe4f293495400eef4ce45545a791da Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Fri, 16 May 2025 14:54:12 +0100 Subject: [PATCH 2/2] Simplify the symlink pointing to a directory instead --- .../SwiftSDKRecipes/WebAssemblyRecipe.swift | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Sources/SwiftSDKGenerator/SwiftSDKRecipes/WebAssemblyRecipe.swift b/Sources/SwiftSDKGenerator/SwiftSDKRecipes/WebAssemblyRecipe.swift index 082c6e0..8497f9b 100644 --- a/Sources/SwiftSDKGenerator/SwiftSDKRecipes/WebAssemblyRecipe.swift +++ b/Sources/SwiftSDKGenerator/SwiftSDKRecipes/WebAssemblyRecipe.swift @@ -197,14 +197,10 @@ package struct WebAssemblyRecipe: SwiftSDKRecipe { // Embedded Swift looks up clang compiler-rt in a different path. let embeddedCompilerRTPath = pathsConfiguration.toolchainDirPath.appending( - "usr/lib/swift/clang/lib/wasm32-unknown-wasip1" + "usr/lib/swift/clang/lib/wasip1" ) - try await generator.createDirectoryIfNeeded(at: embeddedCompilerRTPath) - try await generator.createSymlink( - at: embeddedCompilerRTPath.appending("libclang_rt.builtins.a"), - pointingTo: "../../../../swift_static/clang/lib/wasi/libclang_rt.builtins-wasm32.a" - ) + try await generator.createSymlink(at: embeddedCompilerRTPath, pointingTo: "wasi") // Copy the WASI sysroot into the SDK bundle. let sdkDirPath = pathsConfiguration.swiftSDKRootPath.appending("WASI.sdk")