Skip to content
This repository was archived by the owner on Oct 3, 2025. It is now read-only.

Commit c5f45ff

Browse files
ci: improve no_std testing, add linux arm64
Signed-off-by: Henry Gressmann <[email protected]>
1 parent 0ed6acf commit c5f45ff

File tree

8 files changed

+111
-20
lines changed

8 files changed

+111
-20
lines changed

.github/workflows/test.yaml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
branches: ["**"]
66
pull_request:
77
branches: ["next", "main"]
8+
schedule:
9+
- cron: "0 0 * * 0"
810

911
jobs:
1012
build-wasm:
@@ -14,8 +16,13 @@ jobs:
1416
- uses: actions/checkout@v4
1517
with:
1618
submodules: true
17-
- name: Install Rust toolchain & Binaryen
18-
run: rustup update && rustup target add wasm32-unknown-unknown && sudo apt-get install -y binaryen wabt
19+
- name: Install Rust toolchain
20+
uses: actions-rust-lang/setup-rust-toolchain@v1
21+
with:
22+
toolchain: stable
23+
target: wasm32-unknown-unknown
24+
- name: Install Binaryen and WABT
25+
run: sudo apt-get install -y binaryen wabt
1926
- name: Build wasm
2027
run: ./examples/rust/build.sh
2128
- name: Save artifacts
@@ -31,27 +38,31 @@ jobs:
3138
include:
3239
- os: ubuntu-latest
3340
rust: stable
34-
name: "Linux (stable)"
41+
name: "Linux x86 (stable)"
3542
- os: ubuntu-latest
3643
rust: nightly
37-
name: "Linux (nightly)"
44+
name: "Linux x86 (nightly)"
3845
- os: ubuntu-latest
3946
rust: stable
40-
name: "Linux (stable, no default features)"
47+
name: "Linux x86 (stable, no default features)"
4148
args: "--no-default-features"
4249
- os: ubuntu-latest
4350
rust: nightly
44-
name: "Linux (nightly, no default features)"
51+
name: "Linux x86 (nightly, no default features)"
4552
args: "--no-default-features"
4653
- os: macos-14
4754
rust: stable
4855
name: "macOS arm64 (Apple M1)"
4956
- os: ubuntu-latest
5057
rust: stable
51-
name: "armv7 (32-Bit Raspberry Pi)"
58+
name: "Linux arm64"
59+
target: aarch64-unknown-linux-gnu
60+
- os: ubuntu-latest
61+
rust: stable
62+
name: "Linux armv7"
5263
target: armv7-unknown-linux-gnueabihf
5364

54-
name: Run tests on ${{ matrix.os }}, ${{ matrix.name }})
65+
name: Run tests on ${{ matrix.name }})
5566
runs-on: ${{ matrix.os }}
5667
steps:
5768
- name: Checkout code
@@ -74,11 +85,11 @@ jobs:
7485
path: examples/rust/out
7586

7687
- name: Run tests
77-
run: cargo test --workspace ${{ matrix.args }} && cargo run --example wasm-rust all
88+
run: cargo test --workspace ${{ matrix.args }} && cargo test --workspace ${{ matrix.args }} --examples
7889
if: matrix.target == ''
7990

8091
- name: Run clippy
81-
run: cargo clippy --workspace --all-targets --all-features
92+
run: cargo clippy --workspace ${{ matrix.args }}
8293
if: matrix.target == ''
8394

8495
- name: Run tests (${{ matrix.target }})

crates/parser/src/module.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ impl ModuleReader {
168168
validator.end(offset)?;
169169
self.end_reached = true;
170170
}
171-
CustomSection(reader) => {
171+
CustomSection(_reader) => {
172172
debug!("Found custom section");
173-
debug!("Skipping custom section: {:?}", reader.name());
173+
debug!("Skipping custom section: {:?}", _reader.name());
174174
}
175175
UnknownSection { .. } => return Err(ParseError::UnsupportedSection("Unknown section".into())),
176176
section => return Err(ParseError::UnsupportedSection(format!("Unsupported section: {section:?}"))),

crates/tinywasm/src/func.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ impl FuncHandle {
3737
}
3838

3939
// 5. For each value type and the corresponding value, check if types match
40-
if !(func_ty.params.iter().zip(params).enumerate().all(|(i, (ty, param))| {
40+
if !(func_ty.params.iter().zip(params).enumerate().all(|(_i, (ty, param))| {
4141
if ty != &param.val_type() {
42-
log::error!("param type mismatch at index {}: expected {:?}, got {:?}", i, ty, param);
42+
log::error!("param type mismatch at index {}: expected {:?}, got {:?}", _i, ty, param);
4343
false
4444
} else {
4545
true

examples/rust/Cargo.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ forced-target="wasm32-unknown-unknown"
1010
edition="2021"
1111

1212
[dependencies]
13-
tinywasm={path="../../crates/tinywasm", features=["parser", "std"]}
13+
tinywasm={path="../../crates/tinywasm", default-features=false, features=["parser", "archive"]}
1414
argon2={version="0.5"}
15+
lol_alloc="0.4.1"
16+
17+
[features]
18+
default=["std"]
19+
std=["tinywasm/std"]
1520

1621
[[bin]]
1722
name="hello"
@@ -25,6 +30,10 @@ path="src/print.rs"
2530
name="tinywasm"
2631
path="src/tinywasm.rs"
2732

33+
[[bin]]
34+
name="tinywasm_no_std"
35+
path="src/tinywasm_no_std.rs"
36+
2837
[[bin]]
2938
name="fibonacci"
3039
path="src/fibonacci.rs"

examples/rust/build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ wasmopt_features="--enable-reference-types --enable-bulk-memory --enable-mutable
1212
# ensure out dir exists
1313
mkdir -p "$dest_dir"
1414

15+
# build no_std
16+
cargo build --target wasm32-unknown-unknown --package rust-wasm-examples --profile=wasm --bin tinywasm_no_std --no-default-features
17+
1518
for bin in "${bins[@]}"; do
1619
RUSTFLAGS="-C target-feature=$rust_features -C panic=abort" cargo build --target wasm32-unknown-unknown --package rust-wasm-examples --profile=wasm --bin "$bin"
1720

examples/rust/src/tinywasm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub extern "C" fn hello() {
1212
}
1313

1414
fn run() -> tinywasm::Result<()> {
15-
let module = tinywasm::Module::parse_bytes(include_bytes!("../out/print.wasm"))?;
15+
let module = tinywasm::Module::parse_stream(&include_bytes!("../out/print.wasm")[..])?;
1616
let mut store = tinywasm::Store::default();
1717
let mut imports = tinywasm::Imports::new();
1818

examples/rust/src/tinywasm_no_std.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
#![no_main]
22
#![no_std]
3+
use lol_alloc::{AssumeSingleThreaded, FreeListAllocator};
34
use tinywasm::{Extern, FuncContext};
45

6+
extern crate alloc;
7+
8+
#[panic_handler]
9+
fn panic(_info: &core::panic::PanicInfo) -> ! {
10+
loop {}
11+
}
12+
13+
#[global_allocator]
14+
static ALLOCATOR: AssumeSingleThreaded<FreeListAllocator> =
15+
unsafe { AssumeSingleThreaded::new(FreeListAllocator::new()) };
16+
517
#[link(wasm_import_module = "env")]
618
extern "C" {
719
fn printi32(x: i32);
@@ -13,10 +25,13 @@ pub extern "C" fn hello() {
1325
}
1426

1527
fn run() -> tinywasm::Result<()> {
16-
let module = tinywasm::Module::parse_bytes(include_bytes!("../out/print.wasm"))?;
1728
let mut store = tinywasm::Store::default();
1829
let mut imports = tinywasm::Imports::new();
1930

31+
let res = tinywasm::parser::Parser::new().parse_module_bytes(include_bytes!("../out/print.wasm"))?;
32+
let twasm = res.serialize_twasm();
33+
let module = tinywasm::Module::parse_bytes(&twasm)?;
34+
2035
imports.define(
2136
"env",
2237
"printi32",

examples/wasm-rust.rs

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ fn main() -> Result<()> {
4343
"printi32" => printi32()?,
4444
"fibonacci" => fibonacci()?,
4545
"tinywasm" => tinywasm()?,
46+
"tinywasm_no_std" => tinywasm_no_std()?,
4647
"argon2id" => argon2id()?,
4748
"all" => {
4849
println!("Running all examples");
@@ -54,6 +55,8 @@ fn main() -> Result<()> {
5455
fibonacci()?;
5556
println!("\ntinywasm.wasm:");
5657
tinywasm()?;
58+
println!("\ntinywasm_no_std.wasm:");
59+
tinywasm_no_std()?;
5760
println!("argon2id.wasm:");
5861
argon2id()?;
5962
}
@@ -64,7 +67,22 @@ fn main() -> Result<()> {
6467
}
6568

6669
fn tinywasm() -> Result<()> {
67-
let module = Module::parse_file("./examples/rust/out/tinywasm.wasm")?;
70+
let module = Module::parse_file("./examples/rust/out/tinywasm.opt.wasm")?;
71+
let mut store = Store::default();
72+
73+
let mut imports = Imports::new();
74+
imports.define("env", "printi32", Extern::typed_func(|_: FuncContext<'_>, _x: i32| Ok(())))?;
75+
let instance = module.instantiate(&mut store, Some(black_box(imports)))?;
76+
77+
let hello = instance.exported_func::<(), ()>(&store, "hello")?;
78+
hello.call(&mut store, black_box(()))?;
79+
hello.call(&mut store, black_box(()))?;
80+
hello.call(&mut store, black_box(()))?;
81+
Ok(())
82+
}
83+
84+
fn tinywasm_no_std() -> Result<()> {
85+
let module = Module::parse_file("./examples/rust/out/tinywasm_no_std.opt.wasm")?;
6886
let mut store = Store::default();
6987

7088
let mut imports = Imports::new();
@@ -79,7 +97,7 @@ fn tinywasm() -> Result<()> {
7997
}
8098

8199
fn hello() -> Result<()> {
82-
let module = Module::parse_file("./examples/rust/out/hello.wasm")?;
100+
let module = Module::parse_file("./examples/rust/out/hello.opt.wasm")?;
83101
let mut store = Store::default();
84102

85103
let mut imports = Imports::new();
@@ -108,7 +126,7 @@ fn hello() -> Result<()> {
108126
}
109127

110128
fn printi32() -> Result<()> {
111-
let module = Module::parse_file("./examples/rust/out/print.wasm")?;
129+
let module = Module::parse_file("./examples/rust/out/print.opt.wasm")?;
112130
let mut store = Store::default();
113131

114132
let mut imports = Imports::new();
@@ -151,3 +169,38 @@ fn argon2id() -> Result<()> {
151169

152170
Ok(())
153171
}
172+
173+
#[cfg(test)]
174+
mod tests {
175+
use super::*;
176+
177+
#[test]
178+
fn test_hello() {
179+
hello().unwrap();
180+
}
181+
182+
#[test]
183+
fn test_printi32() {
184+
printi32().unwrap();
185+
}
186+
187+
#[test]
188+
fn test_fibonacci() {
189+
fibonacci().unwrap();
190+
}
191+
192+
#[test]
193+
fn test_tinywasm() {
194+
tinywasm().unwrap();
195+
}
196+
197+
#[test]
198+
fn test_tinywasm_no_std() {
199+
tinywasm_no_std().unwrap();
200+
}
201+
202+
#[test]
203+
fn test_argon2id() {
204+
argon2id().unwrap();
205+
}
206+
}

0 commit comments

Comments
 (0)