-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vaughn Dice <[email protected]>
- Loading branch information
Showing
1 changed file
with
19 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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`. | ||
|