Building Golem Components in MoonBit
Building Golem components having an application manifest is straightforward, just use the golem
command line interface:
golem app build
If the project was created using golem app new
as recommended, the golem app build
command will always work as expected.
The result of the golem app build
command is a WebAssembly component file ready to be uploaded to Golem. It does not have to be specified explicitly, as the golem
tool will automatically find the correct file when doing for example:
golem component add
Regenerating the stubs
A custom command is provided to regenerate the stubs to be implemented:
golem app regenerate-stubs
This command will rewrite the stub code in the source directory, removing any existing change into it! Make sure the previous code is copied elsewhere before running this command. It is not mandatory to ever run this command, but then when the exported WIT interface changes, the changes will have to be reflected manually in the source code.
Under the hood
Building Golem components written in MoonBit involves a few steps.
Generating bindings
The first step is to generate bindings using wit-bindgen moonbit
.
Building the component
Building the component into core WASM module using moon build --target wasm
.
Embedding the WIT specification
Before converting the resulting WASM module into a Golem component, the WIT specification is embedded in a custom section using wasm-tools component embed
.
Converting to a Golem component
Finally the WASM module is converted into a component using wasm-tools component new
.