Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ package struct WebAssemblyRecipe: SwiftSDKRecipe {
)
}

let autolinkExtractPath = generator.pathsConfiguration.toolchainBinDirPath.appending(
let autolinkExtractPath = pathsConfiguration.toolchainBinDirPath.appending(
"swift-autolink-extract"
)

Expand All @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about symlinking the platform directly itself instead of for each individual file?

Copy link
Contributor Author

@MaxDesiatov MaxDesiatov May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It expects libclang_rt.builtins.a, while the name of the symlinked file is libclang_rt.builtins-wasm32.a

Copy link
Contributor Author

@MaxDesiatov MaxDesiatov May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC if we encode the arch name in the directory name, then it shouldn't be included in the file name, and vice versa. So different names for files are still needed.

Copy link
Member

@kateinoigakukun kateinoigakukun May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think the clang driver just prints error message while assuming the new per-target directory layout, but it also looks up the old layout. Could you try the directory symlink approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't seem to work if symlinking wasm32-unknown-wasip1 to wasi is what you're suggesting:

> ls ~/.swiftpm/swift-sdks/swift-DEVELOPMENT-SNAPSHOT_wasm.artifactbundle/swift-DEVELOPMENT-SNAPSHOT_wasm/wasm32-unknown-wasi/swift.xctoolchain/usr/lib/swift/clang/lib/wasm32-unknown-wasip1
╭───┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬──────┬──────────┬─────────────╮
│ # │                                                                                                                 name                                                                                                                 │ type │   size   │  modified   │
├───┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────┼──────────┼─────────────┤
│ 0 │ /home/mdesiatov/.swiftpm/swift-sdks/swift-DEVELOPMENT-SNAPSHOT_wasm.artifactbundle/swift-DEVELOPMENT-SNAPSHOT_wasm/wasm32-unknown-wasi/swift.xctoolchain/usr/lib/swift/clang/lib/wasm32-unknown-wasip1/libclang_rt.builtins-wasm32.a │ file │ 306.4 kB │ an hour ago │
╰───┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴──────┴──────────┴─────────────╯
> swift build --swift-sdk swift-DEVELOPMENT-SNAPSHOT_wasm-embedded -c release
Building for production...
wasm-ld: error: cannot open /home/mdesiatov/.swiftpm/swift-sdks/swift-DEVELOPMENT-SNAPSHOT_wasm.artifactbundle/swift-DEVELOPMENT-SNAPSHOT_wasm/wasm32-unknown-wasi/swift.xctoolchain/usr/lib/swift/clang/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a: No such file or directory

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I meant symlinking wasip1 to wasi.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that worked, thanks!

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)
Expand Down