Skip to content

Symlink libclang_rt.builtins.a for Embedded Swift for WASI #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 16, 2025

Conversation

MaxDesiatov
Copy link
Contributor

@MaxDesiatov MaxDesiatov commented May 16, 2025

Embedded Swift looks up Clang's compiler-rt static library 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 the directory the static library is located in.

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.
@MaxDesiatov MaxDesiatov added the bug Something isn't working label May 16, 2025
"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!

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

Copy link
Member

@kateinoigakukun kateinoigakukun left a comment

Choose a reason for hiding this comment

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

Thanks!

@MaxDesiatov MaxDesiatov merged commit d7264b7 into main May 16, 2025
20 checks passed
@MaxDesiatov MaxDesiatov deleted the maxd/compiler-rt branch May 16, 2025 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants