Skip to content

Commit

Permalink
example: build with Go and TinyGo
Browse files Browse the repository at this point in the history
The new code should work with both Go and TinyGo.
Also move, then main.go to separate folders, that way different IDE-s
and tools work with them better.
  • Loading branch information
egonelbre committed Oct 17, 2023
1 parent d89cd4f commit 634d799
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: actions/setup-go@v3
with:
cache: true
go-version: '1.21.1'
go-version: '1.21.3'

- name: Install TinyGo
uses: acifani/[email protected]
Expand All @@ -31,23 +31,19 @@ jobs:
binaryen-version: "116"

- name: Compile example
working-directory: go-pdk
run: |
pushd go-pdk
ls -a
pushd example
go mod download
popd
ls -a example
make -B example
- name: Test example
working-directory: go-pdk
run: |
cd go-pdk
# --wasi is needed as there is currently some issue compiling Go PDK plugins without wasi
TEST=$(extism call example/example.wasm --wasi --github-token="$GITHUB_TOKEN" --input "this is a test" --set-config='{"thing": "1", "a": "b"}' count_vowels)
TEST=$(extism call example/tiny_countvowels.wasm --wasi --github-token="$GITHUB_TOKEN" --input "this is a test" --set-config='{"thing": "1", "a": "b"}' count_vowels)
echo $TEST | grep '"count": 4'
echo $TEST | grep '"config": "1"'
echo $TEST | grep '"a": "this is var a"'
extism call example/http.wasm --github-token="$GITHUB_TOKEN" --wasi http_get --allow-host "jsonplaceholder.typicode.com" | grep '"userId": 1'
extism call example/tiny_http.wasm --wasi http_get --github-token="$GITHUB_TOKEN" --allow-host "jsonplaceholder.typicode.com" | grep '"userId": 1'
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
.PHONY: example
example:
tinygo build -o example/example.wasm -target wasi example/main.go
tinygo build -o example/http.wasm -target wasi example/http.go
tinygo build -o example/tiny_countvowels.wasm -target wasi ./example/countvowels
tinygo build -o example/tiny_http.wasm -target wasi ./example/http

GOOS=wasip1 GOARCH=wasm go build -o example/std_countvowels.wasm ./example/countvowels
GOOS=wasip1 GOARCH=wasm go build -o example/std_http.wasm ./example/http

test:
extism call example/example.wasm count_vowels --wasi --input "this is a test" --set-config '{"thing": "1234"}'
@echo ""
extism call example/http.wasm http_get --wasi --log-level info --allow-host "jsonplaceholder.typicode.com"
extism call example/tiny_countvowels.wasm count_vowels --wasi --input "this is a test" --set-config '{"thing": "1234"}'
extism call example/tiny_http.wasm http_get --wasi --log-level info --allow-host "jsonplaceholder.typicode.com"

extism call example/std_countvowels.wasm count_vowels --wasi --input "this is a test" --set-config '{"thing": "1234"}'
extism call example/std_http.wasm http_get --wasi --log-level info --allow-host "jsonplaceholder.typicode.com"
File renamed without changes.
File renamed without changes.

0 comments on commit 634d799

Please sign in to comment.