diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3a4e09b3..74c88e63 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,6 +6,8 @@ on: - master - staging - trying + pull_request: + branches: [master] schedule: - cron: '0 2 * * *' # To test `wasmer-nightly` with `libwasmer_archive_name`. @@ -74,6 +76,12 @@ jobs: export CGO_LDFLAGS="-Wl,-rpath,$(pwd)/libwasmer/lib/ -L$(pwd)/libwasmer/lib/ -lwasmer" just test -tags custom_wasmer_runtime + - name: Run e2e tests (default) + if: ${{ !matrix.target.libwasmer_archive_name }} + shell: bash + run: | + just e2e + - name: Run all the examples shell: bash run: | diff --git a/e2e/.gitignore b/e2e/.gitignore new file mode 100644 index 00000000..1d88b4fe --- /dev/null +++ b/e2e/.gitignore @@ -0,0 +1,2 @@ +vendor +app diff --git a/e2e/go.mod b/e2e/go.mod new file mode 100644 index 00000000..715b16bd --- /dev/null +++ b/e2e/go.mod @@ -0,0 +1,3 @@ +module wasmer-go.org/app/v2 + +go 1.16 diff --git a/e2e/main.go b/e2e/main.go new file mode 100644 index 00000000..0252795e --- /dev/null +++ b/e2e/main.go @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "io/ioutil" + + wasmer "github.com/wasmerio/wasmer-go/wasmer" +) + +func main() { + // fmt.Println(C.ffi_lz4_version_number()) + wasmBytes, _ := ioutil.ReadFile("simple.wasm") + + engine := wasmer.NewEngine() + store := wasmer.NewStore(engine) + + // Compiles the module + module, _ := wasmer.NewModule(store, wasmBytes) + + // Instantiates the module + importObject := wasmer.NewImportObject() + instance, _ := wasmer.NewInstance(module, importObject) + + // Gets the `sum` exported function from the WebAssembly instance. + sum, _ := instance.Exports.GetFunction("sum") + + // Calls that exported function with Go standard values. The WebAssembly + // types are inferred and values are casted automatically. + result, _ := sum(5, 37) + + fmt.Println(result) // 42! +} diff --git a/e2e/simple.wasm b/e2e/simple.wasm new file mode 100644 index 00000000..68939290 Binary files /dev/null and b/e2e/simple.wasm differ diff --git a/e2e/test.sh b/e2e/test.sh new file mode 100755 index 00000000..d0af2b2c --- /dev/null +++ b/e2e/test.sh @@ -0,0 +1,8 @@ +#!/bin/bash +rm -r vendor || echo 'error ignored' +mkdir -p vendor/github.com/wasmerio/wasmer-go +cp -r ../wasmer vendor/github.com/wasmerio/wasmer-go +GODEBUG=cgocheck=2 go build -o app +ldd app || echo 'error ignored' +otool -L app || echo 'error ignored' +./app diff --git a/justfile b/justfile index 117a72e4..e62f1a06 100644 --- a/justfile +++ b/justfile @@ -11,6 +11,11 @@ examples: # Run the examples. GODEBUG=cgocheck=2 go test -v +e2e: + #!/usr/bin/env bash + cd e2e + ./test.sh + # Preview the documentation (needs `godoc`, see `go get -v golang.org/x/tools/cmd/godoc`). preview-doc ADDRESS="0.0.0.0" PORT="9090": @echo "Starting godoc preview..."