Skip to content

Commit cb43236

Browse files
committed
Build/test wasm32-wasip2 in CI
This is a follow-up from mlua-rs/lua-src-rs#13 which verifies/tests that mlua/lua all work when compiled for a WASI target. While this doesn't have formal documentation yet it also codifies in CI configuration how to build for WASI and get tests passing (notably C compiler configuration and some misc Rust flags). This moves some `dev-dependencies` that don't compile for `wasm32-wasip2` to a different section of the manifest. This additionally annotates panicking tests with `#[cfg(not(panic = "abort"))]` to skip those tests on WASI. This does not test either the `send` or `async` feature at this time. Testing `send` requires threads which WASI does not yet support, and testing `async` requires more support in Tokio which is not currently there yet.
1 parent 247208e commit cb43236

File tree

5 files changed

+45
-6
lines changed

5 files changed

+45
-6
lines changed

.github/workflows/main.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,41 @@ jobs:
256256
cargo test --tests --features "${{ matrix.lua }},vendored"
257257
cargo test --tests --features "${{ matrix.lua }},vendored,async,serde,macros,anyhow,userdata-wrappers"
258258
259+
test_wasm32_wasip2:
260+
name: Test on wasm32-wasip2
261+
runs-on: ubuntu-latest
262+
needs: build
263+
strategy:
264+
matrix:
265+
lua: [lua54, lua53, lua52, lua51]
266+
steps:
267+
- uses: actions/checkout@main
268+
- uses: dtolnay/rust-toolchain@stable
269+
with:
270+
toolchain: nightly-2025-10-02
271+
target: wasm32-wasip2
272+
- name: Install wasi-sdk/Wasmtime
273+
working-directory: ${{ runner.tool_cache }}
274+
run: |
275+
wasi_sdk=27
276+
wasmtime=v37.0.1
277+
278+
curl -LO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$wasi_sdk/wasi-sdk-$wasi_sdk.0-x86_64-linux.tar.gz
279+
tar xf wasi-sdk-$wasi_sdk.0-x86_64-linux.tar.gz
280+
WASI_SDK_PATH=`pwd`/wasi-sdk-$wasi_sdk.0-x86_64-linux
281+
echo "WASI_SDK_PATH=$WASI_SDK_PATH" >> $GITHUB_ENV
282+
echo "CC_wasm32_wasip2=$WASI_SDK_PATH/bin/clang" >> $GITHUB_ENV
283+
echo "CARGO_TARGET_WASM32_WASIP2_LINKER=$WASI_SDK_PATH/bin/clang" >> $GITHUB_ENV
284+
echo "CARGO_TARGET_WASM32_WASIP2_RUSTFLAGS=-Clink-arg=-Wl,--export=cabi_realloc" >> $GITHUB_ENV
285+
286+
curl -LO https://github.com/bytecodealliance/wasmtime/releases/download/$wasmtime/wasmtime-$wasmtime-x86_64-linux.tar.xz
287+
tar xf wasmtime-$wasmtime-x86_64-linux.tar.xz
288+
echo "CARGO_TARGET_WASM32_WASIP2_RUNNER=`pwd`/wasmtime-$wasmtime-x86_64-linux/wasmtime -W exceptions" >> $GITHUB_ENV
289+
- name: Run ${{ matrix.lua }} tests
290+
run: |
291+
cargo test --tests --features "${{ matrix.lua }},vendored"
292+
cargo test --tests --features "${{ matrix.lua }},vendored,serde,macros,anyhow,userdata-wrappers"
293+
259294
rustfmt:
260295
name: Rustfmt
261296
runs-on: ubuntu-latest

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,18 @@ ffi = { package = "mlua-sys", version = "0.8.3", path = "mlua-sys" }
6666

6767
[dev-dependencies]
6868
trybuild = "1.0"
69-
hyper = { version = "1.2", features = ["full"] }
70-
hyper-util = { version = "0.1.3", features = ["full"] }
71-
http-body-util = "0.1.1"
72-
reqwest = { version = "0.12", features = ["json"] }
7369
tokio = { version = "1.0", features = ["macros", "rt", "time"] }
7470
serde = { version = "1.0", features = ["derive"] }
7571
serde_json = { version = "1.0", features = ["arbitrary_precision"] }
7672
maplit = "1.0"
77-
tempfile = "3"
7873
static_assertions = "1.0"
7974

80-
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
75+
[target.'cfg(not(target_family = "wasm"))'.dev-dependencies]
76+
hyper = { version = "1.2", features = ["full"] }
77+
hyper-util = { version = "0.1.3", features = ["full"] }
78+
http-body-util = "0.1.1"
79+
reqwest = { version = "0.12", features = ["json"] }
80+
tempfile = "3"
8181
criterion = { version = "0.7", features = ["async_tokio"] }
8282
rustyline = "17.0"
8383
tokio = { version = "1.0", features = ["full"] }

tests/chunk.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ fn test_chunk_methods() -> Result<()> {
2121
}
2222

2323
#[test]
24+
#[cfg(not(target_os = "wasi"))]
2425
fn test_chunk_path() -> Result<()> {
2526
let lua = Lua::new();
2627

tests/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ fn test_error() -> Result<()> {
394394
}
395395

396396
#[test]
397+
#[cfg(not(panic = "abort"))]
397398
fn test_panic() -> Result<()> {
398399
fn make_lua(options: LuaOptions) -> Result<Lua> {
399400
let lua = Lua::new_with(StdLib::ALL_SAFE, options)?;
@@ -897,6 +898,7 @@ fn test_registry_value_reuse() -> Result<()> {
897898
}
898899

899900
#[test]
901+
#[cfg(not(panic = "abort"))]
900902
fn test_application_data() -> Result<()> {
901903
let lua = Lua::new();
902904

tests/thread.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ fn test_coroutine_from_closure() -> Result<()> {
199199
}
200200

201201
#[test]
202+
#[cfg(not(panic = "abort"))]
202203
fn test_coroutine_panic() {
203204
match catch_unwind(|| -> Result<()> {
204205
// check that coroutines propagate panics correctly

0 commit comments

Comments
 (0)