swift-syntax icon indicating copy to clipboard operation
swift-syntax copied to clipboard

Add support for WebAssembly Macros

Open kabiroberai opened this issue 2 years ago • 2 comments

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

kabiroberai avatar Apr 24 '24 19:04 kabiroberai

A couple of things worth mentioning:

  1. I didn't add wasm_support.c to 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?
  2. 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 avatar Apr 24 '24 22:04 kabiroberai

@kabiroberai

  1. 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.

kateinoigakukun avatar Apr 25 '24 04:04 kateinoigakukun

Hey @rintaro, could you please take another look at this when you have a minute? Thanks!

kabiroberai avatar May 31 '24 00:05 kabiroberai

@swift-ci Please test

rintaro avatar Jun 12 '24 22:06 rintaro

@rintaro I updated spi.yml which should fix the test failure — could you please request a re-run?

kabiroberai avatar Jun 13 '24 07:06 kabiroberai

@swift-ci Please test

kateinoigakukun avatar Jun 13 '24 07:06 kateinoigakukun

would appreciate another run, third time's the charm hopefully 🤞

kabiroberai avatar Jun 13 '24 16:06 kabiroberai

@swift-ci test

kateinoigakukun avatar Jun 13 '24 16:06 kateinoigakukun

@swift-ci please test Windows

DougGregor avatar Jun 13 '24 22:06 DougGregor

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?

kabiroberai avatar Jun 15 '24 08:06 kabiroberai

@swift-ci test

kateinoigakukun avatar Jun 18 '24 07:06 kateinoigakukun

Linux and macOS are green! Can we please run the Windows suite too? cc @kateinoigakukun

kabiroberai avatar Jun 23 '24 13:06 kabiroberai

@swift-ci test Windows

kateinoigakukun avatar Jun 23 '24 13:06 kateinoigakukun

👋 seeing as all tests have passed are we good to merge this?

kabiroberai avatar Jun 29 '24 10:06 kabiroberai

👋 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.

grynspan avatar Jun 29 '24 14:06 grynspan

looks like CI was re-run today and a few things are out of sync now. will bring it back into working condition.

kabiroberai avatar Jun 29 '24 14:06 kabiroberai

Thanks!

grynspan avatar Jun 29 '24 20:06 grynspan

🙌 could we please run CI again?

kabiroberai avatar Jun 30 '24 15:06 kabiroberai

@swift-ci test

kateinoigakukun avatar Jun 30 '24 15:06 kateinoigakukun

@swift-ci Please test Windows

ahoppen avatar Jul 01 '24 08:07 ahoppen