Grain
Grain (opens in a new tab) is a functional language targeting WASM. Its standard library uses WASI Preview 1.
First install grain
from its official source:
brew install --no-quarantine --cask grain-lang/tap/grain
You also have to install everything as described in Common tooling.
The easiest way to get started once the tooling is installed is to use the golem new
command as described in the Quickstart.
Otherwise you can start writing some code, the whole program will be exposed to Golem as a single parameterless run
function:
let example1 = (a, b) => {
print(a)
print(b)
a + b
}
print("Hello world!")
example1(100, 10)
First we have to compile the grain
program to WASM:
grain compile --release main.gr
This results in a main.gr.wasm
file which is a WASM module. We cannot write any WIT documents because there is no Grain binding generator available currently. This makes Grain a Tier 2 language, so we can convert the compiled module into a WASM component using the adapter from the tier2
directory of the golem package:
wasm-tools component new main.gr.wasm -o component.wasm --adapt tier2/wasi_snapshot_preview1.wasm
The resulting component.wasm
is ready to be used with Golem!