Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions content/wasm-languages/grain.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,42 @@ To use Grain, you will need to [install the Grain toolkit](https://grain-lang.or
Start with a `hello.gr` file:

```
print("content-type: text/plain\n")
print("\n)
print("Hello, World!")
module Main

provide let _start = () => {
print("content-type: text/plain")
print("")
print("Hello, World!")
}
```

Compile the program with the `grain` compiler:

```console
$ grain hello.gr
$ grain compile --release --use-start-section hello.gr
```

The above will produce a `hello.gr.wasm` file. As usual, you can run `wasmtime hello.gr.wasm` to see the output. The first time you compile a grain application, it will take a long time. After that, compiling is much faster.

To run the WebAssembly app with Spin, create a `spin.toml` file:

```
spin_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
description = "Grain example."
spin_manifest_version = 2

[application]
name = "spin-grain"
trigger = { type = "http", base = "/" }
version = "1.0.0"
description = "Grain example."
authors = ["Fermyon Engineering <[email protected]>"]

[[component]]
id = "grain-hello"
source = "hello.gr.wasm"
[component.trigger]
[[trigger.http]]
id = "trigger-grain-hello"
component = "grain-hello"
route = "/"
# Spin components written in Grain use the Wagi HTTP executor
executor = { type = "wagi" }

[component.grain-hello]
source = "hello.gr.wasm"
```

From there, you can use `spin up` to start a server, and see the results on `http://localhost:3000`.
Expand Down
Loading