Skip to content

Commit a5ea13d

Browse files
committed
build: replace tests/run_*.sh with native test-runner
1 parent 3587b89 commit a5ea13d

12 files changed

Lines changed: 933 additions & 347 deletions

build.zig

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,23 @@ pub fn build(b: *std.Build) void {
4343
const run_embedding = b.addSystemCommand(&.{ wasmtime_opt, "--dir", "/" });
4444
run_embedding.addArtifactArg(embedding_exe);
4545

46+
// ── Native test runner (replaces bash scripts) ────────────────────────────
47+
48+
const test_runner_mod = b.createModule(.{
49+
.root_source_file = b.path("src/test_runner.zig"),
50+
.target = b.graph.host,
51+
.optimize = .Debug,
52+
});
53+
test_runner_mod.link_libc = true;
54+
const test_runner_exe = b.addExecutable(.{ .name = "test-runner", .root_module = test_runner_mod });
55+
4656
// ── Conformance ───────────────────────────────────────────────────────────
4757

48-
const conformance = b.addSystemCommand(&.{ "bash", "./tests/run_conformance.sh" });
49-
conformance.step.dependOn(&install_debug.step);
50-
conformance.setEnvironmentVariable("WASMTIME_BIN", wasmtime_opt);
58+
const run_conformance = b.addRunArtifact(test_runner_exe);
59+
run_conformance.step.dependOn(&install_debug.step);
60+
run_conformance.addArg("conformance");
61+
run_conformance.addArg(wasmtime_opt);
62+
run_conformance.addArg("build/gengo-runtime.wasm");
5163

5264
// ── Named steps ───────────────────────────────────────────────────────────
5365

@@ -69,29 +81,51 @@ pub fn build(b: *std.Build) void {
6981
const test_step = b.step("test", "Run runtime safety, embedding API, and conformance tests");
7082
test_step.dependOn(&run_vm_safety.step);
7183
test_step.dependOn(&run_embedding.step);
72-
test_step.dependOn(&conformance.step);
84+
test_step.dependOn(&run_conformance.step);
7385

74-
const bench = scriptStep(b, "bash", "./tests/run_bench.sh", &install_debug.step, wasmtime_opt);
86+
const run_bench = b.addRunArtifact(test_runner_exe);
87+
run_bench.step.dependOn(&install_debug.step);
88+
run_bench.addArg("bench");
89+
run_bench.addArg(wasmtime_opt);
90+
run_bench.addArg("build/gengo-runtime.wasm");
7591
const bench_step = b.step("bench", "Run benchmark suite");
76-
bench_step.dependOn(&bench.step);
92+
bench_step.dependOn(&run_bench.step);
7793

78-
const bench_release = scriptStep(b, "bash", "./tests/run_bench.sh", &install_release.step, wasmtime_opt);
94+
const run_bench_release = b.addRunArtifact(test_runner_exe);
95+
run_bench_release.step.dependOn(&install_release.step);
96+
run_bench_release.addArg("bench");
97+
run_bench_release.addArg(wasmtime_opt);
98+
run_bench_release.addArg("build/gengo-runtime.wasm");
7999
const bench_release_step = b.step("bench-release", "Run benchmark suite (ReleaseFast)");
80-
bench_release_step.dependOn(&bench_release.step);
100+
bench_release_step.dependOn(&run_bench_release.step);
81101

82102
// bench-perf: perf-instrumented debug build; outputs PERF: lines to stderr
83103
const perf_opts = b.addOptions();
84104
perf_opts.addOption(bool, "perf", true);
85105
const perf_opts_mod = perf_opts.createModule();
86106
const gengo_perf = addWasmExe(b, "gengo-perf", "src/main.zig", wasm_target, .Debug, &preset.step, perf_opts_mod);
87107
const install_perf = installWasmAs(b, gengo_perf, "gengo-perf.wasm");
88-
const bench_perf = scriptStep(b, "bash", "./scripts/perf/run.sh", &install_perf.step, wasmtime_opt);
108+
109+
const bench_perf_runner_mod = b.createModule(.{
110+
.root_source_file = b.path("src/bench_perf_runner.zig"),
111+
.target = b.graph.host,
112+
.optimize = .Debug,
113+
});
114+
bench_perf_runner_mod.link_libc = true;
115+
const bench_perf_runner_exe = b.addExecutable(.{ .name = "bench-perf-runner", .root_module = bench_perf_runner_mod });
116+
const run_bench_perf = b.addRunArtifact(bench_perf_runner_exe);
117+
run_bench_perf.step.dependOn(&install_perf.step);
118+
run_bench_perf.addArg(wasmtime_opt);
89119
const bench_perf_step = b.step("bench-perf", "Run benchmarks with perf counters (PERF: lines on stderr)");
90-
bench_perf_step.dependOn(&bench_perf.step);
120+
bench_perf_step.dependOn(&run_bench_perf.step);
91121

92-
const parity = scriptStep(b, "bash", "./tests/run_host_parity.sh", &install_debug.step, wasmtime_opt);
122+
const run_parity = b.addRunArtifact(test_runner_exe);
123+
run_parity.step.dependOn(&install_debug.step);
124+
run_parity.addArg("parity");
125+
run_parity.addArg(wasmtime_opt);
126+
run_parity.addArg("build/gengo-runtime.wasm");
93127
const parity_step = b.step("parity", "Run host/embedded parity tests");
94-
parity_step.dependOn(&parity.step);
128+
parity_step.dependOn(&run_parity.step);
95129

96130
// ── Native CLI ────────────────────────────────────────────────────────────
97131

@@ -189,15 +223,4 @@ fn installWasmAs(
189223
return step;
190224
}
191225

192-
fn scriptStep(
193-
b: *std.Build,
194-
shell: []const u8,
195-
script: []const u8,
196-
depends_on: *std.Build.Step,
197-
wasmtime: []const u8,
198-
) *std.Build.Step.Run {
199-
const step = b.addSystemCommand(&.{ shell, script });
200-
step.step.dependOn(depends_on);
201-
step.setEnvironmentVariable("WASMTIME_BIN", wasmtime);
202-
return step;
203-
}
226+

docs/changelog.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22

33
This changelog tracks notable language/runtime changes by implementation date.
44

5+
## 2026-06-03
6+
7+
### Build — Native Zig Test/Bench Runners
8+
9+
Replaced all shell-script test/bench harnesses with native Zig executables built and run directly by `build.zig`:
10+
11+
- `src/test_runner.zig` — unified runner for conformance, benchmarks, and parity tests
12+
- `src/bench_perf_runner.zig` — perf-counter benchmark runner
13+
14+
Removed:
15+
- `tests/run_conformance.sh`
16+
- `tests/run_bench.sh`
17+
- `tests/run_host_parity.sh`
18+
- `scripts/perf/run.sh`
19+
20+
No `WASMTIME_BIN` environment variable is required. The `-Dwasmtime=` build option (default `wasmtime`) is passed directly to the native runners.
21+
522
## 2026-06-01
623

724
### Language — Zig-style `\\` Multiline Strings

docs/quickstart.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,34 +49,34 @@ wasmtime --dir . ./build/gengo-runtime.wasm -- --max-ops 100000 path/to/script.g
4949
`test` always resets to dev preset first.
5050

5151
```bash
52-
WASMTIME_BIN=/path/to/wasmtime zig build -Dpreset=dev test
52+
zig build -Dpreset=dev test
5353
```
5454

5555
## Host/Embedded Parity
5656

5757
```bash
58-
WASMTIME_BIN=/path/to/wasmtime zig build -Dpreset=dev parity
58+
zig build -Dpreset=dev parity
5959
```
6060

6161
## Benchmarks
6262

6363
Default:
6464

6565
```bash
66-
WASMTIME_BIN=/path/to/wasmtime zig build -Dpreset=dev bench
66+
zig build -Dpreset=dev bench
6767
```
6868

6969
Tiny and stress presets:
7070

7171
```bash
72-
WASMTIME_BIN=/path/to/wasmtime zig build -Dpreset=tiny bench
73-
WASMTIME_BIN=/path/to/wasmtime GENGO_BENCH_INCLUDE_STRESS=1 zig build -Dpreset=stress bench
72+
zig build -Dpreset=tiny bench
73+
zig build -Dpreset=stress bench
7474
```
7575

7676
With benchmark timing/throughput logs:
7777

7878
```bash
79-
WASMTIME_BIN=/path/to/wasmtime GENGO_BENCH_STATS=1 zig build -Dpreset=tiny bench
79+
GENGO_BENCH_STATS=1 zig build -Dpreset=tiny bench
8080
```
8181

8282
## Common Gotchas

docs/testing.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Run full conformance suite:
66

77
```bash
8-
WASMTIME_BIN=/path/to/wasmtime zig build -Dpreset=dev test
8+
zig build -Dpreset=dev test
99
```
1010

1111
Notes:
@@ -18,7 +18,7 @@ Notes:
1818
Run embedded vs host-backend parity checks:
1919

2020
```bash
21-
WASMTIME_BIN=/path/to/wasmtime zig build -Dpreset=dev parity
21+
zig build -Dpreset=dev parity
2222
```
2323

2424
Notes:
@@ -30,15 +30,15 @@ Notes:
3030
Run benchmarks:
3131

3232
```bash
33-
WASMTIME_BIN=/path/to/wasmtime zig build -Dpreset=dev bench
34-
WASMTIME_BIN=/path/to/wasmtime zig build -Dpreset=tiny bench
35-
WASMTIME_BIN=/path/to/wasmtime GENGO_BENCH_INCLUDE_STRESS=1 zig build -Dpreset=stress bench
33+
zig build -Dpreset=dev bench
34+
zig build -Dpreset=tiny bench
35+
zig build -Dpreset=stress bench
3636
```
3737

38-
Timing and throughput mode:
38+
Timing and throughput mode (set via `GENGO_BENCH_STATS=1`):
3939

4040
```bash
41-
WASMTIME_BIN=/path/to/wasmtime GENGO_BENCH_STATS=1 zig build -Dpreset=dev bench
41+
GENGO_BENCH_STATS=1 zig build -Dpreset=dev bench
4242
```
4343

4444
Bench files:

docs/tutorial-first-script.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,19 @@ Mikael M
8080
Run conformance:
8181

8282
```bash
83-
WASMTIME_BIN=/path/to/wasmtime zig build -Dpreset=dev test
83+
zig build -Dpreset=dev test
8484
```
8585

8686
Run backend parity checks:
8787

8888
```bash
89-
WASMTIME_BIN=/path/to/wasmtime zig build -Dpreset=dev parity
89+
zig build -Dpreset=dev parity
9090
```
9191

9292
Run tiny benchmark lane:
9393

9494
```bash
95-
WASMTIME_BIN=/path/to/wasmtime zig build -Dpreset=tiny bench
95+
zig build -Dpreset=tiny bench
9696
```
9797

9898
Notes:

examples/bench/008_runtime_call_overhead.gengo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
std := import("std")
22

3-
func inc(x int) {
3+
func inc(x int) int {
44
return x + 1
55
}
66

scripts/perf/run.sh

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)