For future strangers:
Inside build.zig
const zobrist = b.addExecutable(.{
.name = "zobrist",
.root_source_file = b.path("src/zobrist.zig"),
.target = b.graph.host,
.optimize = .Debug,
});
const zobrist_step = b.addRunArtifact(zobrist);
const output = zobrist_step.addOutputFileArg("zobrist.bin");
main_module.addAnonymousImport("zobrist_stack_change", .{
.root_source_file = output,
});
the main function from zobrist.zig
pub fn main() !void {
var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena_state.deinit();
const args = try std.process.argsAlloc(arena_state.allocator());
std.debug.assert(args.len == 2);
var output_file = try std.fs.cwd().createFile(args[1], .{});
defer output_file.close();
const lut = makeStackChange();
try output_file.writeAll(@ptrCast(&lut));
}
Elsewhere in my code:
const StackChangeType = [optimized_stack_max_height][1 << (max_amount + 1)][max_board_size]HashType;
pub const stack_change: *const StackChangeType = @ptrCast(@alignCast(@embedFile("zobrist_stack_change")));