summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 05:38:26 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitd3742ddf2b3a85eb3935cb35e958fa27f1293a6b (patch)
treeb47dce7b82e72673432f6c8746517386c67ab742 /build.zig
parentb65048ac19f9f47b6faa21d1a9f3d06ba3ff1a95 (diff)
parent81c4157b6731ee64a7bf9194c5df0818e2977f5d (diff)
downloadpardes-d3742ddf2b3a85eb3935cb35e958fa27f1293a6b.tar.gz
pardes-d3742ddf2b3a85eb3935cb35e958fa27f1293a6b.zip
integration: the GPU move whole, with the terminal a module of its own, the plumber and the diff work
A merge of pardes-next (uoqyunnw) and gpu-s4b (zxswllzu). One conflict, build.zig: core-test's root is the core without a terminal AND the Cells and Atlas tests join the unit suite; gui.zig merged by itself and is formatted (two role casts spelled as zig fmt spells them, two blank lines). Gated against a baseline recorded from pardes-next with the gate's test hooks and the renderer still in gui.zig (.scratch/sketch/gpu/mbase): frame corpus 77/77 identical in Debug and in ReleaseFast, the gated window -0.032% instructions (threshold 0.5%), unit-test on gui 1583/1591 with no failure the baseline has not, every GPU counter 0; on tui core-test 810/949 (139 skipped), shell-test 989/992, behaviour-test 269/273 (the four addon ABI tests the base fails). Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig70
1 files changed, 50 insertions, 20 deletions
diff --git a/build.zig b/build.zig
index afc4e4f3..100f2026 100644
--- a/build.zig
+++ b/build.zig
@@ -161,19 +161,12 @@ pub fn build(b: *std.Build) void {
const tracy = b.option([]const u8, "tracy", "enable Tracy profiling; supply the path to a Tracy source checkout");
const macos_sdk = b.option([]const u8, "macos-sdk", "the macOS SDK a gui built for macOS from another system takes SDL's headers and frameworks from");
const macos_identity = b.option([]const u8, "macos-identity", "codesigning identity for pardes.app (default: ad-hoc)") orelse "-";
- const prebuilt_shaders = b.option(bool, "prebuilt-shaders", "embed the committed shaders/prebuilt/*.spv instead of running glslc (default: on for a bare `zig build`, off when -Dplatform names a shell)") orelse also_gui;
+ const prebuilt_shaders = b.option(bool, "prebuilt-shaders", "embed sketchbook's committed src/gpu/shaders/prebuilt/*.spv instead of running glslc over its GLSL (default: on for a bare `zig build`, off when -Dplatform names a shell)") orelse also_gui;
const mupdf_check = b.step("mupdf-check", "the pdf addon's check: MuPDF compiles, links, renders and searches docs/design.pdf, and its script runs");
const pdf_pointer_bench_step = b.step("pdf-pointer-bench", "time PDF hover and selection gestures and prove their pixels (-Doptimize=ReleaseFast -- [--label L] [--reps N] [--path FILE] [--cell WxH])");
const pdf_scroll_bench_step = b.step("pdf-scroll-bench", "benchmark fast continuous-strip PDF scrolling in ReleaseFast (-Doptimize=ReleaseFast -- [--json] [--reps N] [--warmup N] [--path FILE])");
- const shaders_step = b.step("shaders", "refresh the committed shaders/prebuilt/*.spv (glslc)");
- const update_shaders = b.addUpdateSourceFiles();
- for (gui_shaders) |name| {
- update_shaders.addCopyFileToSource(compileGlsl(b, name), b.fmt("shaders/prebuilt/{s}.spv", .{name}));
- }
- shaders_step.dependOn(&update_shaders.step);
-
// build-time IO: slurps the grammars' highlights.scm queries, and reads
// vendor/themes to find the theme sources
var threaded: std.Io.Threaded = .init(b.allocator, .{});
@@ -462,6 +455,7 @@ pub fn build(b: *std.Build) void {
const addon_mod = b.createModule(.{ .root_source_file = b.path("src/kinds/addon.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "pardes_addon", .module = kind_mod }} });
const snake_shader_step = b.step("snake-shader", "build the optional GPU snake addon into zig-out/lib");
var snake_shader_lib: ?*std.Build.Step.Compile = null;
+ const veil_step = b.step("veil", "build the frame corpus's translucent GPU test addon (test/veil.zig) into zig-out/lib");
if (b.lazyDependency("sketchbook", .{ .@"gpu-only" = true })) |sb| {
const files = b.addWriteFiles();
for ([_][]const u8{ "vert", "frag", "post.frag" }) |stage| {
@@ -476,6 +470,9 @@ pub fn build(b: *std.Build) void {
snake_shader_lib = lib;
snake_shader_step.dependOn(&b.addInstallArtifact(lib, .{}).step);
snake_shader_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = module })).step);
+ // The frame corpus's translucent addon (test/veil.zig), into lib/ beside the snake.
+ const veil = b.addLibrary(.{ .name = "veil", .linkage = .dynamic, .root_module = b.createModule(.{ .root_source_file = b.path("test/veil.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "addon", .module = addon_mod }, .{ .name = "gpu_scene", .module = sb.module("gpu_scene") } } }) });
+ veil_step.dependOn(&b.addInstallArtifact(veil, .{}).step);
}
// The PDF addon (addons/pdf/pdf.zig over MuPDF through pdf_bridge.c), built
// and installed as the image addon is: compiled only for a step that
@@ -927,7 +924,13 @@ pub fn build(b: *std.Build) void {
const gui_shell_mods: [2]?*std.Build.Module = .{ gui_shell_mod, if (platform == .gui) static_mod else null };
// SDL's headers, for the macOS trackpad adapter's test after the loop.
var sdl_include: ?std.Build.LazyPath = null;
+ // sketchbook's Cells.zig's own tests (the instance ABI), for unit-test.
+ var cells_test: ?*std.Build.Step.Compile = null;
+ // sketchbook's Atlas.zig's own tests, for unit-test.
+ var atlas_test: ?*std.Build.Step.Compile = null;
for (gui_shell_mods) |gui_shell_entry| if (gui_shell_entry) |gm| {
+ // This shell's `c`, for the Atlas's tests below.
+ var font_c: ?*std.Build.Module = null;
// SDL's build asks a cross build for macOS for the SDK's paths.
const sdk: ?std.Build.LazyPath = if (macos_sdk) |p| .{ .cwd_relative = p } else null;
const sdl_dep = b.lazyDependency("sdl", .{ .target = target, .optimize = optimize, .sanitize_c = .off, .preferred_linkage = .static, .system_include_path = if (sdk) |p| p.path(b, "usr/include") else null, .system_framework_path = if (sdk) |p| p.path(b, "System/Library/Frameworks") else null, .library_path = if (sdk) |p| p.path(b, "usr/lib") else null });
@@ -951,10 +954,31 @@ pub fn build(b: *std.Build) void {
gui_c.addIncludePath(dep.path("include"));
gui_c.addIncludePath(b.path("src/gui"));
const gui_c_mod = gui_c.createModule();
+ font_c = gui_c_mod;
gm.addImport("gui_c", gui_c_mod);
if (b.lazyDependency("sketchbook", .{ .@"gpu-only" = true })) |sb| {
const gpu = b.createModule(.{ .root_source_file = sb.path("src/gpu/Executor.zig"), .imports = &.{ .{ .name = "abi", .module = sb.module("abi") }, .{ .name = "c", .module = gui_c_mod } } });
gm.addImport("sketch_gpu", gpu);
+ // The glyph atlas (src/font/Atlas.zig) over the font shim
+ // (vendor/font.{c,h}), compiled below against pardes's
+ // FreeType and HarfBuzz.
+ const atlas_mod = b.createModule(.{ .root_source_file = sb.path("src/font/Atlas.zig"), .imports = &.{.{ .name = "c", .module = gui_c_mod }} });
+ gm.addImport("font_atlas", atlas_mod);
+ // pardes's renderer, moved to sketchbook (src/gpu/), compiled
+ // against pardes's SDL; its tests run with unit-test. Its
+ // SPIR-V is sketchbook's GLSL through glslc, or the prebuilt
+ // copies with -Dprebuilt-shaders.
+ const cells_mod = b.createModule(.{ .root_source_file = sb.path("src/gpu/Cells.zig"), .imports = &.{ .{ .name = "c", .module = gui_c_mod }, .{ .name = "font_atlas", .module = atlas_mod } } });
+ for (gui_shaders) |name| cells_mod.addAnonymousImport(b.fmt("{s}.spv", .{name}), .{
+ .root_source_file = if (prebuilt_shaders)
+ sb.path(b.fmt("src/gpu/shaders/prebuilt/{s}.spv", .{name}))
+ else
+ compileGlsl(b, sb.path(b.fmt("src/gpu/shaders/{s}.glsl", .{name})), name),
+ });
+ gm.addImport("gpu_cells", cells_mod);
+ gm.addImport("gpu_present", b.createModule(.{ .root_source_file = sb.path("src/gpu/Present.zig"), .imports = &.{ .{ .name = "c", .module = gui_c_mod }, .{ .name = "gpu_cells", .module = cells_mod } } }));
+ if (cells_test == null) cells_test = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = sb.path("src/gpu/Cells.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "c", .module = gui_c_mod }, .{ .name = "font_atlas", .module = atlas_mod } } }), .filters = test_filters });
+ gui_c.addIncludePath(sb.path("vendor"));
gm.addImport("gpu_scene", sb.module("gpu_scene"));
}
sdl_include = dep.path("include");
@@ -1011,22 +1035,26 @@ pub fn build(b: *std.Build) void {
});
gm.linkLibrary(harfbuzz);
gm.addIncludePath(upstream.path("src"));
+ // The Atlas's own tests, over the same FreeType, HarfBuzz and
+ // shim, the embedded face theirs to draw.
+ if (atlas_test == null) if (font_c) |fc| if (b.lazyDependency("sketchbook", .{ .@"gpu-only" = true })) |sb| {
+ const atlas_mod = b.createModule(.{ .root_source_file = sb.path("src/font/Atlas.zig"), .target = target, .optimize = optimize, .link_libc = true, .imports = &.{.{ .name = "c", .module = fc }} });
+ atlas_mod.linkLibrary(ft);
+ atlas_mod.linkLibrary(harfbuzz);
+ atlas_mod.addIncludePath(upstream.path("src"));
+ atlas_mod.addCSourceFile(.{ .file = sb.path("vendor/font.c") });
+ atlas_mod.addAnonymousImport("AdwaitaMono-Regular.ttf", .{ .root_source_file = b.path("assets/AdwaitaMono-Regular.ttf") });
+ atlas_test = b.addTest(.{ .root_module = atlas_mod, .filters = test_filters });
+ };
}
if (target.result.os.tag.isDarwin())
gm.addRPath(.{ .cwd_relative = "/usr/local/lib" });
- gm.addIncludePath(b.path("src/gui"));
- gm.addCSourceFile(.{ .file = b.path("src/gui/font.c") });
+ if (b.lazyDependency("sketchbook", .{ .@"gpu-only" = true })) |sb| gm.addCSourceFile(.{ .file = sb.path("vendor/font.c") });
// the embedded UI font: provided as a build import since assets/ lives
// outside the src/ module root (@embedFile can't escape it)
gm.addAnonymousImport("AdwaitaMono-Regular.ttf", .{
.root_source_file = b.path("assets/AdwaitaMono-Regular.ttf"),
});
- for (gui_shaders) |name| gm.addAnonymousImport(b.fmt("{s}.spv", .{name}), .{
- .root_source_file = if (prebuilt_shaders)
- b.path(b.fmt("shaders/prebuilt/{s}.spv", .{name}))
- else
- compileGlsl(b, name),
- });
};
if (target.result.os.tag == .macos) if (sdl_include) |include| {
const adapter_test = b.addSystemCommand(&.{ "xcrun", "clang", "-fobjc-arc", "-O1", "-framework", "Cocoa", "-I" });
@@ -1617,6 +1645,8 @@ pub fn build(b: *std.Build) void {
// The perf and fs bench programs' own tests: they compile no editor.
_ = units.add(b, perf_tests, null);
_ = units.add(b, fs_bench_test, null);
+ if (cells_test) |t| _ = units.add(b, t, null);
+ if (atlas_test) |t| _ = units.add(b, t, null);
const core_test = b.addTest(.{ .root_module = core_lean, .filters = test_filters });
const run_core_test = b.addRunArtifact(core_test);
run_core_test.has_side_effects = true;
@@ -2068,12 +2098,12 @@ fn reindexed(b: *std.Build, archive: std.Build.LazyPath, index: usize) std.Build
return run.addOutputFileArg(b.fmt("{d}.a", .{index}));
}
-/// glslc shaders/<name>.glsl -fshader-stage=<vertex|fragment> -o <name>.spv,
-/// returned as a LazyPath for @embedFile. The stage is the name's own suffix.
-fn compileGlsl(b: *std.Build, name: []const u8) std.Build.LazyPath {
+/// glslc <glsl> -fshader-stage=<vertex|fragment> -o <name>.spv, returned as
+/// a LazyPath for @embedFile. The stage is the name's own suffix.
+fn compileGlsl(b: *std.Build, glsl: std.Build.LazyPath, name: []const u8) std.Build.LazyPath {
const stage = if (std.mem.endsWith(u8, name, ".vert")) "vertex" else "fragment";
const cmd = b.addSystemCommand(&.{ "glslc", b.fmt("-fshader-stage={s}", .{stage}) });
- cmd.addFileArg(b.path(b.fmt("shaders/{s}.glsl", .{name})));
+ cmd.addFileArg(glsl);
cmd.addArg("-o");
return cmd.addOutputFileArg(b.fmt("{s}.spv", .{name}));
}