Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2025 01 25 Project cleanup #418

Merged
merged 13 commits into from
Feb 1, 2025
Merged
91 changes: 75 additions & 16 deletions .github/workflows/test.yml → .github/workflows/code-qa.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,95 @@
name: Build and Test
name: Code QA

on:
pull_request:
branches:
- master
push:
branches:
- master
- staging
- trying
schedule:
- cron: '0 2 * * *' # To test `wasmer-nightly` with `libwasmer_archive_name`.

jobs:
staticcheck:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.23"

- name: Staticcheck
run: |
go install honnef.co/go/tools/cmd/[email protected]
staticcheck ./...
gofumpt:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.23"

- name: Gofumpt
run: |
go install mvdan.cc/[email protected]
output=$(gofumpt -l .)
if [ ! -z "$output" ]; then echo "$output" && exit 1; fi
shell: bash

govulncheck:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.23"

- name: Vulnerabilities
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...

govet:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.23"

- name: Vet
run: |
go vet ./...

test:
name: Build and Test

strategy:
matrix:
go: [1.14, 1.15]
go: [1.21, 1.22]
target:
- id: 'linux-amd64'
os: 'ubuntu-18.04'
- id: "linux-amd64"
os: "ubuntu-24.04"

#- id: 'linux-aarch64'
# os: ['self-hosted', 'linux', 'ARM64']

- id: 'darwin-amd64'
os: 'macos-latest'
- id: "darwin-amd64"
os: "macos-latest"

- id: 'linux-amd64'
os: 'ubuntu-18.04'
libwasmer_archive_name: 'wasmer-linux-amd64.tar.gz'
- id: "linux-amd64"
os: "ubuntu-24.04"
libwasmer_archive_name: "wasmer-linux-amd64.tar.gz"
fail-fast: true

runs-on: ${{ matrix.target.os }}

steps:
- name: Check out code
uses: actions/checkout@v2
Expand Down Expand Up @@ -66,7 +123,8 @@ jobs:
continue-on-error: true
shell: bash
run: |
libwasmer_url=$(curl -s https://api.github.com/repos/wasmerio/wasmer-nightly/releases/latest | jq --raw-output '.assets[] | select(.name == "${{ matrix.target.libwasmer_archive_name }}") | .browser_download_url')
libwasmer_url=$(curl -s https://api.github.com/repos/wasmerio/wasmer/releases/latest | \
jq --raw-output '.assets[] | select(.name == "${{ matrix.target.libwasmer_archive_name }}") | .browser_download_url')
mkdir -p libwasmer
curl -L $libwasmer_url > release.tar.gz
tar xzvf release.tar.gz -C libwasmer
Expand All @@ -78,6 +136,7 @@ jobs:
shell: bash
run: |
just examples

# Skipped for now because of Github banning the API request from actions.
# You can find more info in this PR: https://github.com/wasmerio/wasmer-go/pull/118#issuecomment-588487544
# - name: Test bazel build
Expand Down
3 changes: 2 additions & 1 deletion examples/appendices/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import (
"fmt"
wasmer "github.com/wasmerio/wasmer-go/wasmer"
"io/ioutil"

Check failure on line 5 in examples/appendices/simple.go

View workflow job for this annotation

GitHub Actions / staticcheck

"io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details. (SA1019)

wasmer "github.com/wasmerio/wasmer-go/wasmer"
)

func main() {
Expand Down
3 changes: 0 additions & 3 deletions examples/example_early_exit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func ExampleFunction_Call() {

fmt.Println("Compiling module...")
module, err := wasmer.NewModule(store, wasmBytes)

if err != nil {
fmt.Println("Failed to compile module:", err)
}
Expand All @@ -80,7 +79,6 @@ func ExampleFunction_Call() {
fmt.Println("Instantiating module...")
// Let's instantiate the Wasm module.
instance, err := wasmer.NewInstance(module, importObject)

if err != nil {
panic(fmt.Sprintln("Failed to instantiate the module:", err))
}
Expand All @@ -90,7 +88,6 @@ func ExampleFunction_Call() {
// Get the `run` function which we'll use as our entrypoint.
fmt.Println("Calling `run` function...")
run, err := instance.Exports.GetFunction("run")

if err != nil {
panic(fmt.Sprintln("Failed to retrieve the `run` function:", err))
}
Expand Down
4 changes: 1 addition & 3 deletions examples/example_errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package wasmer

import (
"fmt"

"github.com/wasmerio/wasmer-go/wasmer"
)

Expand Down Expand Up @@ -45,7 +46,6 @@ func ExampleError() {

fmt.Println("Compiling module...")
module, err := wasmer.NewModule(store, wasmBytes)

if err != nil {
fmt.Println("Failed to compile module:", err)
}
Expand All @@ -56,7 +56,6 @@ func ExampleError() {
fmt.Println("Instantiating module...")
// Let's instantiate the Wasm module.
instance, err := wasmer.NewInstance(module, importObject)

if err != nil {
panic(fmt.Sprintln("Failed to instantiate the module:", err))
}
Expand All @@ -69,7 +68,6 @@ func ExampleError() {
//
// Let's get it.
divByZero, err := instance.Exports.GetFunction("div_by_zero")

if err != nil {
panic(fmt.Sprintln("Failed to get the `div_by_zero` function:", err))
}
Expand Down
6 changes: 1 addition & 5 deletions examples/example_exports_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package wasmer

import (
"fmt"

"github.com/wasmerio/wasmer-go/wasmer"
)

Expand All @@ -44,7 +45,6 @@ func ExampleFunction() {

fmt.Println("Compiling module...")
module, err := wasmer.NewModule(store, wasmBytes)

if err != nil {
fmt.Println("Failed to compile module:", err)
}
Expand All @@ -55,7 +55,6 @@ func ExampleFunction() {
fmt.Println("Instantiating module...")
// Let's instantiate the Wasm module.
instance, err := wasmer.NewInstance(module, importObject)

if err != nil {
panic(fmt.Sprintln("Failed to instantiate the module:", err))
}
Expand All @@ -65,15 +64,13 @@ func ExampleFunction() {
// The Wasm module exports a function called `sum`. Let's get
// it.
sum, err := instance.Exports.GetRawFunction("sum")

if err != nil {
panic(fmt.Sprintln("Failed to retrieve the `sum` function:", err))
}

fmt.Println("Calling `sum` function...")
// Let's call the `sum` exported function.
result, err := sum.Call(1, 2)

if err != nil {
panic(fmt.Sprintln("Failed to call the `sum` function:", err))
}
Expand All @@ -90,7 +87,6 @@ func ExampleFunction() {
// statically typed Rust values of type `i32` and `i32`. The
// result, in this case particular case, in a unit of type `i32`.
result, err = sumNative(3, 4)

if err != nil {
panic(fmt.Sprintln("Failed to call the `sum` function natively:", err))
}
Expand Down
18 changes: 3 additions & 15 deletions examples/example_exports_global_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// This example illustrates how to use exported globals. They come
// in 2 flavors:
//
// 1. Immutable globals (const),
// 2. Mutable globals.
// 1. Immutable globals (const),
// 2. Mutable globals.
//
// You can run the example directly by executing in Wasmer root:
//
Expand All @@ -18,6 +18,7 @@ package wasmer

import (
"fmt"

"github.com/wasmerio/wasmer-go/wasmer"
)

Expand All @@ -44,7 +45,6 @@ func ExampleGlobal_Set() {

fmt.Println("Compiling module...")
module, err := wasmer.NewModule(store, wasmBytes)

if err != nil {
fmt.Println("Failed to compile module:", err)
}
Expand All @@ -55,7 +55,6 @@ func ExampleGlobal_Set() {
fmt.Println("Instantiating module...")
// Let's instantiate the Wasm module.
instance, err := wasmer.NewInstance(module, importObject)

if err != nil {
panic(fmt.Sprintln("Failed to instantiate the module:", err))
}
Expand All @@ -64,13 +63,11 @@ func ExampleGlobal_Set() {
//
// The Wasm module exports some globals. Let's get them.
one, err := instance.Exports.GetGlobal("one")

if err != nil {
panic(fmt.Sprintln("Failed to retrieve the `one` global:", err))
}

some, err := instance.Exports.GetGlobal("some")

if err != nil {
panic(fmt.Sprintln("Failed to retrieve the `some` global:", err))
}
Expand All @@ -91,19 +88,16 @@ func ExampleGlobal_Set() {
// We will use an exported function for the `one` global
// and the Global API for `some`.
getOne, err := instance.Exports.GetFunction("get_one")

if err != nil {
panic(fmt.Sprintln("Failed to retrieve the `get_one` function:", err))
}

oneValue, err := getOne()

if err != nil {
panic(fmt.Sprintln("Failed to call the `get_one` function:", err))
}

someValue, err := some.Get()

if err != nil {
panic(fmt.Sprintln("Failed to get the `some` global value:", err))
}
Expand All @@ -121,7 +115,6 @@ func ExampleGlobal_Set() {
}

oneValue, err = getOne()

if err != nil {
panic(fmt.Sprintln("Failed to call the `get_one` function:", err))
}
Expand All @@ -134,33 +127,28 @@ func ExampleGlobal_Set() {
//
// We will use both for the `some` global.
setSome, err := instance.Exports.GetFunction("set_some")

if err != nil {
panic(fmt.Sprintln("Failed to retrieve the `set_some` function:", err))
}

_, err = setSome(float32(21.0))

if err != nil {
panic(fmt.Sprintln("Failed to call the `set_some` function:", err))
}

someValue, err = some.Get()

if err != nil {
panic(fmt.Sprintln("Failed to get the `some` global value:", err))
}

fmt.Printf("`some` value after `set_some`: %.1f\n", someValue)

err = some.Set(float32(42.0), wasmer.F32)

if err != nil {
panic(fmt.Sprintln("Failed to set the `some` global value:", err))
}

someValue, err = some.Get()

if err != nil {
panic(fmt.Sprintln("Failed to get the `some` global value:", err))
}
Expand Down
5 changes: 0 additions & 5 deletions examples/example_imports_exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func ExampleExtern() {

fmt.Println("Compiling module...")
module, err := wasmer.NewModule(store, wasmBytes)

if err != nil {
panic(fmt.Sprintln("Failed to compile module:", err))
}
Expand Down Expand Up @@ -114,7 +113,6 @@ func ExampleExtern() {
// Let's get them.
fmt.Println("Getting the exported function...")
function, err := instance.Exports.GetFunction("guest_function")

if err != nil {
panic(fmt.Sprintln("Failed to get the exported function:", err))
}
Expand All @@ -123,7 +121,6 @@ func ExampleExtern() {

fmt.Println("Getting the exported global...")
global, err := instance.Exports.GetGlobal("guest_global")

if err != nil {
panic(fmt.Sprintln("Failed to get the exported global:", err))
}
Expand All @@ -132,7 +129,6 @@ func ExampleExtern() {

fmt.Println("Getting the exported memory...")
memory, err := instance.Exports.GetMemory("guest_memory")

if err != nil {
panic(fmt.Sprintln("Failed to get the exported memory:", err))
}
Expand All @@ -141,7 +137,6 @@ func ExampleExtern() {

fmt.Println("Getting the exported table...")
table, err := instance.Exports.GetTable("guest_table")

if err != nil {
panic(fmt.Sprintln("Failed to get the exported table:", err))
}
Expand Down
Loading
Loading