summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig25
1 files changed, 25 insertions, 0 deletions
diff --git a/build.zig b/build.zig
index f85ce1f..c168407 100644
--- a/build.zig
+++ b/build.zig
@@ -292,6 +292,31 @@ pub fn build(b: *std.Build) void {
// renderer stays next to the vaxis it needs, and the boundary is bytes in / bytes out.
const obj = b.option([]const u8, "pardes-obj", "path to pardes's p4 object (default ../02-pardes-code/zig-out/pardes-p4.o)") orelse
"../02-pardes-code/zig-out/pardes-p4.o";
+
+ // THE GRID, set from here, because the object is where it is baked and the object is built
+ // by the other repository. Without this, changing the geometry is two commands in two
+ // directories and the second one silently links whatever the first one left behind - which is
+ // exactly the shape of mistake that ends with a firmware whose grid does not match the
+ // firmware you think you flashed.
+ //
+ // Implemented as a nested `zig build`, not a package dependency, for the reasons above: the
+ // seam between these repositories is a file, and it stays a file. This only reaches across it
+ // to ask for the file to be made a particular way. Skipped entirely when `-Dpardes-obj` names
+ // an object explicitly, because then the caller has said which one they want.
+ const cols = b.option(u16, "cols", "board grid width in cells; rebuilds pardes's object");
+ const rows = b.option(u16, "rows", "board grid height in cells; rebuilds pardes's object");
+ if ((cols != null or rows != null) and b.user_input_options.get("pardes-obj") == null) {
+ const editor_dir = std.fs.path.dirname(std.fs.path.dirname(obj) orelse ".") orelse "..";
+ const build_editor = b.addSystemCommand(&.{ b.graph.zig_exe, "build", "-Dplatform=p4" });
+ build_editor.setCwd(.{ .cwd_relative = editor_dir });
+ if (cols) |c| build_editor.addArg(b.fmt("-Dp4-cols={d}", .{c}));
+ if (rows) |v| build_editor.addArg(b.fmt("-Dp4-rows={d}", .{v}));
+ // Its output is a file this build then links, and the linker has no idea it is generated,
+ // so the ordering has to be said out loud.
+ build_editor.has_side_effects = true;
+ app.step.dependOn(&build_editor.step);
+ }
+
app.root_module.addObjectFile(if (std.fs.path.isAbsolute(obj))
.{ .cwd_relative = obj }
else