Skip to content
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
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

- uses: mlugg/setup-zig@v2
with:
version: 0.15.2
version: 0.16.0

- name: Check C code formatting
run: find . \( -name "*.c" -o -name "*.h" \) -print0 | xargs -0 clang-format --dry-run --Werror
Expand All @@ -28,7 +28,7 @@ jobs:

- uses: mlugg/setup-zig@v2
with:
version: 0.15.2
version: 0.16.0

- name: Run tests (data)
run: zig build test-data --summary all
Expand All @@ -50,14 +50,14 @@ jobs:

- uses: mlugg/setup-zig@v2
with:
version: 0.15.2
version: 0.16.0

- uses: oven-sh/setup-bun@v2
- uses: actions/setup-node@v6
with:
bun-version: 1.3.5
node-version: 26.x

- name: Build wasm
run: zig build wasm

- name: Run tests (wasm)
run: bun test
run: node --test
6 changes: 3 additions & 3 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn build(b: *std.Build) void {
.link_libc = true,
}),
});
test_data.addCSourceFiles(.{ .files = c_sources, .flags = c_flags });
test_data.root_module.addCSourceFiles(.{ .files = c_sources, .flags = c_flags });
test_data.root_module.addIncludePath(b.path("src"));

const run_test_data = b.addRunArtifact(test_data);
Expand All @@ -44,7 +44,7 @@ pub fn build(b: *std.Build) void {
.link_libc = true,
}),
});
test_lib.addCSourceFiles(.{ .files = c_sources, .flags = c_flags });
test_lib.root_module.addCSourceFiles(.{ .files = c_sources, .flags = c_flags });
test_lib.root_module.addIncludePath(b.path("src"));

const run_test_lib = b.addRunArtifact(test_lib);
Expand All @@ -69,7 +69,7 @@ pub fn build(b: *std.Build) void {
.optimize = .ReleaseSmall,
}),
});
wasm.addCSourceFiles(.{ .files = c_sources, .flags = c_flags });
wasm.root_module.addCSourceFiles(.{ .files = c_sources, .flags = c_flags });
wasm.root_module.addIncludePath(b.path("src"));
wasm.entry = .disabled;
wasm.rdynamic = true;
Expand Down
20 changes: 0 additions & 20 deletions bun.lock

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"devDependencies": {
"@types/bun": "^1.3.5"
"@types/node": "^25.8.0"
}
}
29 changes: 29 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions wasm.test.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect, test } from "bun:test";
import wasmUrl from "./zig-out/calcHashAB.wasm";
import testData from "./test-data.json";
import test from "node:test";
import assert from "node:assert/strict";
import source wasmModule from "./zig-out/calcHashAB.wasm";
import testData from "./test-data.json" with { type: "json" };

function hexToBytes(hex: string): Uint8Array {
const bytes = new Uint8Array(hex.length / 2);
Expand All @@ -16,9 +17,7 @@ function bytesToHex(bytes: Uint8Array): string {
.join("");
}

const wasmBuffer = await Bun.file(wasmUrl).arrayBuffer();

const { instance } = await WebAssembly.instantiate(wasmBuffer, {});
const instance = await WebAssembly.instantiate(wasmModule, {});

const { getInputSha1, getInputUuid, getOutput, calculateHash, memory } =
instance.exports as {
Expand Down Expand Up @@ -48,6 +47,6 @@ for (const testCase of testData) {
const result = mem.slice(outputPtr, outputPtr + 57);
const resultHex = bytesToHex(result);

expect(resultHex).toBe(testCase.target);
assert.strictEqual(resultHex, testCase.target);
});
}
Loading