Skip to content

Commit

Permalink
docs(wasm-languages): grain updates
Browse files Browse the repository at this point in the history
Signed-off-by: Vaughn Dice <[email protected]>
  • Loading branch information
vdice committed Oct 30, 2024
1 parent 1ce2fcc commit 0ac5b1d
Showing 1 changed file with 19 additions and 13 deletions.
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

0 comments on commit 0ac5b1d

Please sign in to comment.