Add support for WebAssembly Macros
This PR allows CompilerPlugins to be built with a wasm32-unknown-wasi target, enabling them to be invoked by the Wasm Plugin runtime in https://github.com/apple/swift/pull/73031.
I've chosen to create a swift_wasm_macro_pump export to allow the caller to "drive the event loop" since issuing a read would by default be blocking. We need nonblocking IO because some runtimes (eg JavaScriptCore) run Wasm on the same thread as the rest of the interpreted code (JavaScript).
To test this, one can build an example macro with
Examples$ swift build \
--experimental-swift-sdk wasm32-unknown-wasi \
--product MacroExamplesImplementation \
-c release
And then, with the changes from the swift and swift-driver PRs, a client can be compiled with
Examples$ swiftc Client.swift \
-load-plugin-executable .build/release/MacroExamplesImplementation.wasm#MacroExamplesImplementation
A couple of things worth mentioning:
- I didn't add
wasm_support.cto the CMake source set for _SwiftSyntaxCShims since I don't think we ever build SwiftSyntax for WASI with CMake — and I'm not sure how I would even test that. Is this okay or should I try to allow cross-compiling with CMake? - Can we add a smoke test to ensure that SwiftSyntax continues to build for WASI? Unsure of the best way to go about doing this.
@kabiroberai
- Can we add a smoke test to ensure that SwiftSyntax continues to build for WASI? Unsure of the best way to go about doing this.
I'm not sure we have a way to run smoke test with Wasm target in CI right now. But we are trying to build Wasm SDK in CI here https://github.com/apple/swift/pull/72728 and after the integration, we will be able to use Wasm target in CI.
Hey @rintaro, could you please take another look at this when you have a minute? Thanks!
@swift-ci Please test
@rintaro I updated spi.yml which should fix the test failure — could you please request a re-run?
@swift-ci Please test
would appreciate another run, third time's the charm hopefully 🤞
@swift-ci test
@swift-ci please test Windows
Hi folks, seems like the one remaining request is to adjust the indentation here once the corresponding fix lands in swift-format: https://github.com/apple/swift-syntax/pull/2623#discussion_r1639172780
Seeing as the swift-format PR is in turn blocked by some CI issues, would it make sense to merge this PR without that one whitespace change and follow up once the swift-format PR lands?
@swift-ci test
Linux and macOS are green! Can we please run the Windows suite too? cc @kateinoigakukun
@swift-ci test Windows
👋 seeing as all tests have passed are we good to merge this?
👋 seeing as all tests have passed are we good to merge this?
Unfortunately, it looks like all CI jobs have failed, and this PR has not been approved by any code owners. So it's not ready to merge yet.
looks like CI was re-run today and a few things are out of sync now. will bring it back into working condition.
Thanks!
🙌 could we please run CI again?
@swift-ci test
@swift-ci Please test Windows