migueldeicaza / SwiftGodot

New Godot bindings for Swift
https://migueldeicaza.github.io/SwiftGodotDocs/tutorials/swiftgodot-tutorials/
MIT License
1.11k stars 74 forks source link

WebAssembly support #447

Open migueldeicaza opened 6 months ago

migueldeicaza commented 6 months ago

We would like to make it so that developers that want to use SwiftGodot can target Wasm, a popular platform for Godot to be deployed to.

This issue is intended to keep track of the various findings, it will be edited as we find out more information, so this text will change.

Here is roughly where we stand right now:

  1. Godot seems to use the Emscripten ABI
  2. Swift/Wasm seems to use the WASI API, and these are different
  3. We use a lot of Macros, and SwiftWasm does not currently support it, but there is a patch coming soon https://github.com/apple/swift-package-manager/pull/7118

While SwiftWASM only supports the executable target, it seems that in the Wasm world, even regular executables can be treated as libraries, so we would need to figure out a way of stitching those together. One possible problem with this approach is that currently we might assume that the extension and Godot share the same memory address space so this could be a problem.

Things that we could also consider:

  1. Compiling Godot as a library
  2. Have our build system link Godot with the SwiftGodot target, like SwiftGodotKit in a way.

Discussion links

Initial discussion on using SwiftWasm for Godot: https://discord.com/channels/780838335798706197/802944960881098752/1208500336671854662

Recent discussion:

https://discord.com/channels/780838335798706197/790246707648135229/1225627478471610398

Resoures

Setting up Swift for WASM: https://book.swiftwasm.org/getting-started/setup.html

SwiftGodot without Macros dependency, useful to prototype, courtesy of @PadraigK: https://github.com/PadraigK/SwiftGodotLite/tree/main

migueldeicaza commented 2 hours ago

There are a few updates shared on Slack.

  1. The ABI between Godot and Swift was sorted out, the details of how are not clear to me yet

image image

  1. There is some discussion on how this got started using --triple wasm32-unknown-none-wasm and https://github.com/apple/swift-for-wasm-examples

  2. Talk on Swift for WASM that might be relevant: https://youtu.be/cX5pITN0uFM?si=G7yNZL-HCP5WPbcJ

  3. This comment might be a correction over our previous assumptions:

swift doesn’t use the WASI api if you don’t ask it to. You can specify either --triple wasm32-unknown-none-wasm which works with emscripten ( I have linked these and ran them with a godot game ), or you can target the WASI api with the wasi triple