-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch to wit impl, add rust and tinygo examples
- Loading branch information
Showing
24 changed files
with
242 additions
and
145 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
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "funcgg_example_rust" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
wit-bindgen = "0.38.0" |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
wit_bindgen::generate!({ | ||
world: "run", | ||
path: "../../wit/funcgg.wit", | ||
}); | ||
|
||
// https://github.com/bytecodealliance/wasi-rs | ||
|
||
fn main() { | ||
funcgg::runtime::responder::set_header("X-Foo", "bar"); | ||
funcgg::runtime::responder::set_status(200); | ||
|
||
println!("Environment variables:"); | ||
for (key, value) in std::env::vars() { | ||
println!("{}: {}", key, value); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// This file exists for testing this package without WebAssembly, | ||
// allowing empty function bodies with a //go:wasmimport directive. | ||
// See https://pkg.go.dev/cmd/compile for more information. |
13 changes: 13 additions & 0 deletions
13
examples/tinygo/gen/funcgg/runtime/responder/responder.wasm.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
examples/tinygo/gen/funcgg/runtime/responder/responder.wit.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/robherley/func.gg/examples/tinygo | ||
|
||
go 1.23.1 | ||
|
||
require go.bytecodealliance.org/cm v0.1.0 |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go.bytecodealliance.org/cm v0.1.0 h1:78Rk4d5rgir5Hm+LMFpDWhjmFBWrKDFPSKUwDBj+nwo= | ||
go.bytecodealliance.org/cm v0.1.0/go.mod h1:NZ2UT0DyGhBfpIPOxPMCuG6g1YTR4YF3xweD7mHX5VQ= |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/robherley/func.gg/examples/tinygo/gen/funcgg/runtime/responder" | ||
) | ||
|
||
//go:generate wit-bindgen-go generate -o gen/ ../../wit/ | ||
|
||
func main() { | ||
responder.SetStatus(200) | ||
responder.SetHeader("Content-Type", "application/json") | ||
|
||
fmt.Println("{") | ||
|
||
x := 26 | ||
for i := range x { | ||
fmt.Printf(" %q: %d", string('A'+i), i) | ||
if i < x-1 { | ||
fmt.Print(",") | ||
} | ||
fmt.Println() | ||
time.Sleep(1 * time.Second) | ||
} | ||
|
||
fmt.Println("}") | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eo pipefail | ||
|
||
ROOT=$(realpath "$(dirname "$0")/..") | ||
|
||
dependencies=(cargo wasm-tools wkg tinygo) | ||
|
||
for dep in "${dependencies[@]}"; do | ||
if ! command -v "$dep" &> /dev/null; then | ||
echo "error: $dep is not installed." >&2 | ||
exit 1 | ||
fi | ||
done | ||
|
||
"$ROOT/script/wit-fetch" | ||
"$ROOT/script/build-examples" |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eo pipefail | ||
|
||
cargo run |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eo pipefail | ||
|
||
ROOT=$(realpath "$(dirname "$0")/..") | ||
|
||
if ! command -v wkg &> /dev/null; then | ||
echo "wkg is not installed: https://github.com/bytecodealliance/wasm-pkg-tools" | ||
exit 1 | ||
fi | ||
|
||
pushd "$ROOT" > /dev/null | ||
wkg wit fetch | ||
popd > /dev/null |
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
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
Oops, something went wrong.