A while ago, Zig had an experimental port to Haiku c. version 0.8.0. Unfortunately, this support has bit-rotted over time due to the mass amounts of internal changes since then. Right now I’m trying to get the port going again, but I’m running into some roadblocks that are halting my progress.
Right now I’m following these [1][2] two guides that explain how to build LLVM (currently 16.x) and Zig from source. At a high level, Zig is built by:
- Compiling a simple WASM vm to convert a stripped-down WASM version of the Zig compiler to C (stage 1).
- Compile the C conversion as a native binary (stage 2).
- Use the native binary to compile Zig again (stage 3).
The problem I’m facing is in step 3. To build any Zig project, Zig will compile a build runner program and use that to compile any source files. When building stage 3, this build runner fails due to an index oob error.
[9/9] Building stage3
FAILED: stage3/bin/zig /boot/home/gits/zig/build/stage3/bin/zig
cd /boot/home/gits/zig && /boot/home/gits/zig/build/zig2 build --prefix /boot/home/gits/zig/build/stage3 --zig-lib-dir /boot/home/gits/zig/lib -Dconfig_h=/boot/home/gits/zig/build/config.h -Denable-llvm -Doptimize=ReleaseFast -Dtarget=native -Dcpu=native -Dversion-string=0.11.0-dev.2893+e963793e3
thread 1067 panic: index out of bounds: index 43690, len 1024
Panicked during a panic. Aborting.
Abort
error: the following build command crashed:
/boot/home/gits/zig/zig-cache/o/990e1c20ca3201c45788a875af4f27b7/build /boot/home/gits/zig/build/zig2 /boot/home/gits/zig /boot/home/gits/zig/zig-cache /boot/home/config/cache/zig --prefix /boot/home/gits/zig/build/stage3 --zig-lib-dir /boot/home/gits/zig/lib -Dconfig_h=/boot/home/gits/zig/build/config.h -Denable-llvm -Doptimize=ReleaseFast -Dtarget=native -Dcpu=native -Dversion-string=0.11.0-dev.2893+e963793e3
ninja: build stopped: subcommand failed.
The index number is a tell, since it’s 0xaaaa
- the default for undefined variables in Debug mode Zig. Unfortunately I cannot find where in the code this is tripping, as the port doesn’t support backtraces and neither the native debugger nor GDB from haikuports can load the file with source file info.
So, I’m posting here to request the help of some Haiku experts to get this port going again. To start, compiling and file access is pretty slow in my QEMU/KVM vm and making this faster would go a long way in shortening my build+debug cycle.