diff --git a/wasm01/build.zig b/wasm01/build.zig new file mode 100644 index 0000000..a7d40cb --- /dev/null +++ b/wasm01/build.zig @@ -0,0 +1,17 @@ +const std = @import("std"); + +pub fn build(b: *std.build.Builder) void { + // Standard release options allow the person running `zig build` to select + // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. + const mode = b.standardReleaseOptions(); + + const lib = b.addStaticLibrary("wasm01", "src/main.zig"); + lib.setBuildMode(mode); + lib.install(); + + const main_tests = b.addTest("src/main.zig"); + main_tests.setBuildMode(mode); + + const test_step = b.step("test", "Run library tests"); + test_step.dependOn(&main_tests.step); +} diff --git a/wasm01/justfile b/wasm01/justfile new file mode 100644 index 0000000..17e4dc4 --- /dev/null +++ b/wasm01/justfile @@ -0,0 +1,7 @@ +_: + @just --list + + +build: + zig build-lib src/main.zig -target wasm32-freestanding-musl -dynamic -O ReleaseSmall --export=add + diff --git a/wasm01/src/main.zig b/wasm01/src/main.zig new file mode 100644 index 0000000..ecfeade --- /dev/null +++ b/wasm01/src/main.zig @@ -0,0 +1,10 @@ +const std = @import("std"); +const testing = std.testing; + +export fn add(a: i32, b: i32) i32 { + return a + b; +} + +test "basic add functionality" { + try testing.expect(add(3, 7) == 10); +}