ashtonmeuser / godot-wasm

Interact with WebAssembly modules from Godot
https://github.com/ashtonmeuser/godot-wasm/wiki
MIT License
197 stars 12 forks source link
gdscript godot godot-engine wasm webassembly

Godot Wasm

Godot Wasm Logo

Addon Status License Version

Warning This project is still in its infancy. Interfaces are liable to change with each release until v1.0.

A Godot extension allowing for loading and interacting with WebAssembly (Wasm) modules from GDScript via the Wasmer and Wasmtime WebAssembly runtimes.

Features

Motivation

Documentation

Please refer to the Godot Wasm wiki for guides, FAQs, class documentation, etc.

Quick Start

Godot Wasm can be used as a GDExtension/GDNative addon or Godot module. See the Installation wiki page for full instructions.

Using Godot Wasm involves the following. See the Usage wiki page for full instructions.

  1. Create a WebAssembly (Wasm) module using a language of your choice. See FAQ for more information. Alternatively, a simple test module can be used.
  2. Create a new Godot Wasm instance, read your Wasm module bytecode, and instantiate the Godot Wasm module. The following assumes a Wasm module that requires no imports.
    var wasm = Wasm.new()
    var file = FileAccess.open("res://my_module.wasm", FileAccess.READ)
    var bytecode = file.get_buffer(file.get_length())
    wasm.load(bytecode, {})
  3. The Wasm module is now instantiated and can be interacted with from GDScript. For example, an exported function may be invoked using via wasm.function("my_function", [my_arg]).

See the Usage wiki page for full instructions.

Known Issues

  1. A small subset of WASI bindings are provided to the Wasm module by default. These can be overridden by the imports supplied on module instantiation. The guest Wasm module has no access to the host machines filesystem, etc. Pros for this are simplicity and increased security. Cons include more work required to run Wasm modules created in ways that require a larger set of WASI bindings e.g. TinyGo (see relevant issue).
  2. Only int and float return values are supported. While workarounds could be used, this limitation is because the only concrete types supported by Wasm are integers and floating point.
  3. Default empty args parameter for function(name, args) is not supported in Godot 3.x using Godot Wasm as an addon e.g. via the Godot Asset Library. Default Array parameters in GDNative seem to retain values between calls. Calling methods of this addon without expected arguments produces undefined behaviour. Default empty arguments are supported in Godot 4.x and Godot 3.x when using Godot Wasm as a module.
  4. Web/HTML5 export is not supported (see #15 and #18).

Relevant Discussion

There have been numerous discussions around modding/sandboxing support for Godot. Some of those are included below.