beginning of haku2: a reimplementation of haku in Zig

the goal is to rewrite haku completely, starting with the VM---because it was the most obvious point of improvement
the reason is because Rust is kinda too verbose for low level stuff like this. compare the line numbers between haku1 and haku2's VM and how verbose those lines are, and it's kind of an insane difference
it also feels like Zig's compilation model can work better for small wasm binary sizes

and of course, I also just wanted an excuse to try out Zig :3
This commit is contained in:
りき萌 2025-06-01 23:13:34 +02:00
parent 598c0348f6
commit 01d4514a65
19 changed files with 1946 additions and 11 deletions

59
crates/haku2/build.zig Normal file
View file

@ -0,0 +1,59 @@
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Library
const mod = b.createModule(.{
.root_source_file = b.path("src/haku2.zig"),
.target = target,
.optimize = optimize,
.pic = true,
});
const lib = b.addStaticLibrary(.{
.name = "haku2",
.root_module = mod,
});
lib.pie = true;
b.installArtifact(lib);
const mod_wasm = b.createModule(.{
.root_source_file = b.path("src/haku2.zig"),
.target = b.resolveTargetQuery(.{
.cpu_arch = .wasm32,
.os_tag = .freestanding,
}),
.optimize = optimize,
});
const exe_wasm = b.addExecutable(.{
.linkage = .static,
.name = "haku2",
.root_module = mod_wasm,
});
exe_wasm.entry = .disabled;
exe_wasm.rdynamic = true;
b.installArtifact(exe_wasm);
// Tests
const lib_unit_tests = b.addTest(.{
.root_module = mod,
});
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
// Checks
const lib_check = b.addLibrary(.{
.linkage = .static,
.name = "haku2_check",
.root_module = mod,
});
const check_step = b.step("check", "Check if the project compiles");
check_step.dependOn(&lib_check.step);
}