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

ci: rework #13

Merged
merged 19 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 145 additions & 29 deletions .github/workflows/west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,52 +20,170 @@ concurrency:
cancel-in-progress: true

jobs:
build:
build-ffi:
strategy:
matrix:
target:
- aarch64-unknown-linux-musl
- aarch64-linux-android
- riscv64gc-unknown-linux-gnu
- x86_64-pc-windows-gnu
- x86_64-unknown-linux-musl
# TODO: figure out what's different in Mac libraries built this way
#- aarch64-apple-darwin
#- x86_64-apple-darwin

name: west-${{ matrix.target }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: ./.github/actions/install-nix
with:
cachixAuthToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- uses: ./.github/actions/build-nix
with:
package: west-${{ matrix.target }}

build-ffi-darwin:
strategy:
matrix:
config:
- os: macos-13
lib: x86_64-darwin
target: x86_64-apple-darwin

- os: macos-14
lib: aarch64-darwin
target: aarch64-apple-darwin

name: west-${{ matrix.config.target }}
runs-on: ${{ matrix.config.os }}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: ./.github/actions/install-nix
with:
cachixAuthToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix build -L
- run: nix run -L --inputs-from . 'nixpkgs#coreutils' -- --coreutils-prog=cp -RLv ./result artifact
- uses: actions/upload-artifact@v4
with:
name: west-${{ matrix.config.target }}
path: artifact

build-wasm:
name: passthrough.wasm
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: ./.github/actions/install-nix
with:
cachixAuthToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix profile install --inputs-from . '.#rust' 'nixpkgs#wasm-tools'
- run: cargo build -p west-passthrough --target wasm32-unknown-unknown --release
- run: wasm-tools component new target/wasm32-unknown-unknown/release/west_passthrough.wasm -o lib/passthrough.wasm
- uses: actions/upload-artifact@v4
with:
name: passthrough
path: lib/passthrough.wasm

test-release:
strategy:
matrix:
config:
#- os: ubuntu-latest
# lib: x86_64-linux
# target: x86_64-unknown-linux-musl
- os: ubuntu-latest
lib: x86_64-linux
target: x86_64-unknown-linux-musl

#- os: windows-latest
# lib: x86_64-windows
# target: x86_64-pc-windows-msvc
- os: windows-latest
lib: x86_64-windows
target: x86_64-pc-windows-gnu

- os: macos-13
lib: x86_64-darwin
target: x86_64-apple-darwin
- os: macos-13
lib: x86_64-darwin
target: x86_64-apple-darwin

- os: macos-14
lib: aarch64-darwin
target: aarch64-apple-darwin
- os: macos-14
lib: aarch64-darwin
target: aarch64-apple-darwin

name: test-release-${{ matrix.config.target }}
needs:
- build-ffi
- build-ffi-darwin
- build-wasm
runs-on: ${{ matrix.config.os }}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: passthrough
path: lib
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: west-${{ matrix.config.target }}
- run: mv lib/libwest_sys.a "lib/${{ matrix.config.lib }}/libwest.a"
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- uses: cargo-bins/[email protected]
- run: rustup show
#- run: cargo test --workspace --all-targets
- uses: Swatinem/[email protected]
- uses: cargo-bins/[email protected]
- run: cargo binstall -y [email protected]
- run: go generate ./...
- run: go generate ./tests/go/...
- run: go test ./...
- uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
env:
GOGC: 1
WEST_LOG: trace
continue-on-error: ${{ matrix.config.os == 'ubuntu-latest' || matrix.config.os == 'windows-latest' }} # TODO: remove
- run: git diff --exit-code

test-dev:
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-13
- macos-14

name: test-dev-${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@v5
with:
name: west-${{ matrix.config.target }}
path: lib/${{ matrix.config.lib }}/libwest.a
if-no-files-found: error
go-version-file: 'go.mod'
- run: rustup show
- uses: Swatinem/[email protected]
- uses: cargo-bins/[email protected]
- run: cargo binstall -y [email protected]
- run: cargo test --workspace --all-targets
- run: go generate -tags=dev ./...
- run: go test -tags=dev ./...
env:
GOGC: 1
WEST_LOG: trace
continue-on-error: ${{ matrix.os == 'ubuntu-latest' || matrix.os == 'windows-latest' }} # TODO: remove
- run: git diff --exit-code

gofmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- run: gofmt -w -s **/*.go
- run: git diff --exit-code

cargo:
strategy:
matrix:
check:
- audit
- fmt
#- nextest
#- clippy
- nextest
- clippy

name: cargo ${{ matrix.check }}
runs-on: ubuntu-latest
Expand All @@ -84,7 +202,8 @@ jobs:
strategy:
matrix:
include:
#- crate: passthrough
- crate: passthrough
workspace-dependencies: false

- crate: sys
workspace-dependencies: true
Expand Down Expand Up @@ -167,7 +286,7 @@ jobs:
release:
if: startsWith(github.ref, 'refs/tags/v')
needs:
- build
- test-release
- cargo
- crates
runs-on: ubuntu-latest
Expand Down Expand Up @@ -202,13 +321,10 @@ jobs:
path: artifacts

- run: |
mkdir -p ./libwest
for dir in ./artifacts/west-*; do
target=${dir#./artifacts/west-}
for lib_path in $(find ${dir}/lib -type f); do
lib=$(basename ${lib_path})
mkdir -p ./${lib}
mv ${lib_path} ./${lib}/${lib}-${target}.a
done
mv ${dir}/lib/libwest_sys.a ./libwest/libwest-${target}.a
done

- uses: softprops/action-gh-release@c062e08bd532815e2082a85e87e3ef29c3e6d191 # v2.0.8
Expand Down
16 changes: 10 additions & 6 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

package west

// #cgo darwin,amd64 LDFLAGS: -L${SRCDIR}/lib/x86_64-darwin -lwest
// #cgo darwin,arm64 LDFLAGS: -L${SRCDIR}/lib/aarch64-darwin -lwest
// #cgo linux,amd64 LDFLAGS: -L${SRCDIR}/lib/x86_64-linux -lwest
// #cgo linux,arm64 LDFLAGS: -L${SRCDIR}/lib/aarch64-linux -lwest
// #cgo windows,amd64 LDFLAGS: -L${SRCDIR}/lib/x86_64-windows -lwest
// #cgo windows,arm64 LDFLAGS: -L${SRCDIR}/lib/aarch64-windows -lwest
// #cgo LDFLAGS: -lwest
// #cgo linux LDFLAGS: -lm
// #cgo android,arm64 LDFLAGS: -L${SRCDIR}/lib/aarch64-android
// #cgo darwin,amd64 LDFLAGS: -L${SRCDIR}/lib/x86_64-darwin
// #cgo darwin,arm64 LDFLAGS: -L${SRCDIR}/lib/aarch64-darwin
// #cgo linux,amd64 LDFLAGS: -L${SRCDIR}/lib/x86_64-linux
// #cgo linux,arm64 LDFLAGS: -L${SRCDIR}/lib/aarch64-linux
// #cgo linux,riscv64 LDFLAGS: -L${SRCDIR}/lib/riscv64-linux
// #cgo windows,amd64 LDFLAGS: -L${SRCDIR}/lib/x86_64-windows
// #cgo windows,arm64 LDFLAGS: -L${SRCDIR}/lib/aarch64-windows
import "C"
3 changes: 2 additions & 1 deletion build_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@

package west

// #cgo LDFLAGS: -L${SRCDIR}/target/debug -lwest_sys
// #cgo LDFLAGS: -L${SRCDIR}/target/debug -lwest_sys
// #cgo linux LDFLAGS: -lm
import "C"
3 changes: 3 additions & 0 deletions cmd/west-bindgen-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ func generate(path string) error {
pos := pkg.Fset.Position(dir.Pos())
return fmt.Errorf("%s:%d: unexpected `go:wasmimport` directive format: %s", pos.Filename, pos.Line, dir.Text)
}
if instance == "gojs" {
continue
}

var callArgs []ast.Expr
appendArg := func(arg *ast.Field) error {
Expand Down
4 changes: 2 additions & 2 deletions crates/sys/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::ptr::{self, null_mut};
use std::ffi::CString;
use std::sync::{LazyLock, Mutex};

use crate::{call, instantiate, Config};
use crate::{call, instantiate, Config, Instance};

static ERROR: LazyLock<Mutex<Option<CString>>> = LazyLock::new(Mutex::default);

Expand Down Expand Up @@ -48,7 +48,7 @@ pub extern "C" fn instance_new(config: Config) -> *mut c_void {

#[no_mangle]
pub extern "C" fn instance_free(instance: *mut c_void) {
unsafe { drop(Box::from_raw(instance)) }
unsafe { drop(Box::from_raw(instance.cast::<Instance>())) }
}

#[no_mangle]
Expand Down
25 changes: 0 additions & 25 deletions crates/sys/west.h

This file was deleted.

1 change: 1 addition & 0 deletions lib/aarch64-android/lib_android_arm64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package lib
1 change: 1 addition & 0 deletions lib/riscv64-linux/lib_linux_riscv64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package lib
18 changes: 10 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use wasi_preview1_component_adapter_provider::{
WASI_SNAPSHOT_PREVIEW1_ADAPTER_NAME, WASI_SNAPSHOT_PREVIEW1_REACTOR_ADAPTER,
};
use wasmtime::component::{Component, Linker, Resource, ResourceTable, Type, TypedFunc, Val};
use wasmtime::{Engine, Store};
use wasmtime::{AsContext as _, AsContextMut as _, Engine, Store};
use wasmtime_wasi::{WasiCtx, WasiCtxBuilder, WasiView};
use wasmtime_wasi_http::types::HostIncomingRequest;
use wasmtime_wasi_http::{WasiHttpCtx, WasiHttpView};
Expand Down Expand Up @@ -182,25 +182,27 @@ pub struct Func<'a> {
}

impl Func<'_> {
#[must_use]
pub fn params(&self) -> Box<[Type]> {
self.func.params(&self.store)
self.func.params(self.store.as_context())
}

#[must_use]
pub fn results(&self) -> Box<[Type]> {
self.func.results(&self.store)
self.func.results(self.store.as_context())
}

pub fn call(&mut self, params: &[Val], results: &mut [Val]) -> anyhow::Result<()> {
self.func
.call(&mut self.store, params, results)
.call(self.store.as_context_mut(), params, results)
.context("failed to call function")?;
self.func
.post_return(&mut self.store)
.post_return(self.store.as_context_mut())
.context("failed to invoke `post-return`")
}

pub fn store(&mut self) -> &mut Store<impl WasiView + WasiHttpView> {
&mut self.store
self.store
}
}

Expand Down Expand Up @@ -265,9 +267,9 @@ impl Instance {
}

pub fn instantiate(Config { engine, wasm }: Config) -> anyhow::Result<Instance> {
let wasm = if wasmparser::Parser::is_core_wasm(&wasm) {
let wasm = if wasmparser::Parser::is_core_wasm(wasm) {
let wasm = wit_component::ComponentEncoder::default()
.module(&wasm)
.module(wasm)
.context("failed to set core component module")?
.adapter(
WASI_SNAPSHOT_PREVIEW1_ADAPTER_NAME,
Expand Down
13 changes: 6 additions & 7 deletions tests/components/wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,20 @@ impl bindings::exports::west_test::leftpad::leftpad::Guest for Handler {
let rx: InputStream = in_.into_inner();
let tx: &OutputStream = out.get();

let mut cs = zip(0..len, iter::repeat(c)).map(|(_, c)| c);
let mut cs = zip(0..len, iter::repeat(c)).flat_map(|(_, c)| String::from(c).into_bytes());
let mut buf = Vec::default();
loop {
let mut n = tx.check_write()?;
if n == 0 {
tx.subscribe().block();
n = tx.check_write()?;
}
let s: Box<str> = cs
.by_ref()
.take(n.try_into().unwrap_or(usize::MAX) / c.len_utf8())
.collect();
if s.is_empty() {
buf.extend(cs.by_ref().take(n.try_into().unwrap_or(usize::MAX)));
if buf.is_empty() {
break;
}
tx.write(s.as_bytes())?;
tx.write(&buf)?;
buf.clear();
}
loop {
let n = tx.splice(&rx, 4096)?;
Expand Down
Loading
Loading