From 6b101c22930673b781f351936664cc1e7f59d392 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 30 Nov 2022 15:04:45 -0800 Subject: [PATCH] support unit testing wasm via wasmtime --- build.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/build.zig b/build.zig index d74933803..7232f1d88 100644 --- a/build.zig +++ b/build.zig @@ -73,6 +73,9 @@ pub fn build(b: *std.build.Builder) !void { "Build and install test executables with 'build'", ) orelse false; + // We can use wasmtime to test wasm + b.enable_wasmtime = true; + // Add our benchmarks try benchSteps(b, target, mode); @@ -124,6 +127,15 @@ pub fn build(b: *std.build.Builder) !void { const step = b.step("wasm", "Build the wasm library"); step.dependOn(&wasm.step); + + // We support tests via wasmtime. wasmtime uses WASI so this + // isn't an exact match to our freestanding target above but + // it lets us test some basic functionality. + const test_step = b.step("test-wasm", "Run all tests for wasm"); + const main_test = b.addTest("src/main_wasm.zig"); + main_test.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .wasi }); + main_test.addOptions("build_options", exe_options); + test_step.dependOn(&main_test.step); } // Run