diff options
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 141 |
1 files changed, 124 insertions, 17 deletions
@@ -13,6 +13,18 @@ const display_version = if (std.mem.endsWith(u8, zon.version, ".0") and std.mem. else zon.version; +/// Every dependency the manifest pins, by its content hash: a grammar, +/// ghostty or the Unicode tables steps a core differently, so they are part +/// of a replica's semantics hash (src/detached/wire.zig `semantics`). +const deps_text = blk: { + var text: []const u8 = ""; + for (@typeInfo(@TypeOf(zon.dependencies)).@"struct".field_names) |name| { + const dep = @field(zon.dependencies, name); + text = text ++ name ++ " " ++ (if (@hasField(@TypeOf(dep), "hash")) dep.hash else "path") ++ "\n"; + } + break :blk text; +}; + pub const Platform = enum { tty, gui, web, macos, esp32p4 }; const PerfBuild = struct { @@ -96,7 +108,7 @@ pub fn build(b: *std.Build) void { const target = if (platform == .esp32p4) b.resolveTargetQuery(esp32p4_target) else requested_target; const requested_optimize = b.standardOptimizeOption(.{}); const static = b.option(bool, "static", "statically link") orelse false; - const dump_path = b.option([]const u8, "dump", "dump .zon embedded into the web shell (-Dplatform=web)"); + const dump_path = b.option([]const u8, "dump", "a Dump (a .dump file) embedded into the web shell (-Dplatform=web)"); // one substring, because that is what a dev loop needs: see the unit-test // step for why the whole-binary run is worth narrowing const test_filters: []const []const u8 = if (b.option([]const u8, "test-filter", "run only tests whose name contains this")) |f| @@ -184,7 +196,7 @@ pub fn build(b: *std.Build) void { // The browser shell is a freestanding wasm core plus ordinary web files. // JavaScript owns the loop and IO; HTML/CSS own rendering. - const web_step = b.step("web", "build the DOM browser shell into zig-out/web (-Dplatform=web -Dtarget=wasm32-freestanding -Ddump=<dump.zon>)"); + const web_step = b.step("web", "build the DOM browser shell into zig-out/web (-Dplatform=web -Dtarget=wasm32-freestanding -Ddump=<file.dump>)"); const mupdf_check = b.step("mupdf-check", "compile, link, render, and search docs/design.pdf with MuPDF"); const pdf_bench_step = b.step("pdf-bench", "benchmark real MuPDF page rendering (-- [--json] [--reps N] [--warmup N] [--path FILE] [--page N] [--pages N])"); const pdf_sections_bench_step = b.step("pdf-sections-bench", "benchmark PDF outline/sections paths in ReleaseFast (-Doptimize=ReleaseFast -- [--json] [--reps N] [--warmup N])"); @@ -212,7 +224,7 @@ pub fn build(b: *std.Build) void { if (is_web and !is_web_target) return failBuild(b, web_step, "-Dplatform=web requires -Dtarget=wasm32-freestanding"); if (!is_web and (is_web_target or target.result.os.tag == .emscripten)) return failBuild(b, web_step, "wasm browser targets require -Dplatform=web"); - if (platform == .web and dump_path == null) return failBuild(b, web_step, "-Dplatform=web requires -Ddump=<dump.zon> (the browser has no ptys; state replays from an embedded dump)"); + if (platform == .web and dump_path == null) return failBuild(b, web_step, "-Dplatform=web requires -Ddump=<file.dump> (the browser has no ptys; state replays from an embedded dump)"); if (enable_mupdf and is_web) return failBuild(b, web_step, "-Dmupdf=true is supported only by the native tty/Kitty and gui/SDL backends"); // The board's target is pinned (`target` above), so what is asked of // -Dtarget is checked, not what was resolved: another arch is refused, @@ -888,13 +900,25 @@ pub fn build(b: *std.Build) void { \\} \\ ; + // And its event queue: a pop that makes room woke one blocked + // writer, and only on the pop from full. The tty has two writers + // (a pane's pty reader, and the input reader posting the frame + // ack's wake), so when the loop emptied a full queue in one batch + // the writer not woken waited on for good: under `yes` the pane + // stopped being read, its program blocked on the pty, while keys + // went on working. Every blocked writer is woken now. + var queue_src = configureRead(b, io, vaxis_dep.builder.root, "src/queue.zig", 1 << 20) catch @panic("read vaxis queue.zig"); + const wake_one = "self.not_full.signal(self.io);"; + if (std.mem.count(u8, queue_src, wake_one) != 2) std.debug.panic("vaxis's queue.zig changed at `{s}`: redo its patch in build.zig", .{wake_one}); + queue_src = std.mem.replaceOwned(u8, b.allocator, queue_src, wake_one, "self.not_full.broadcast(self.io); // pardes's patch (its build.zig)") catch @panic("OOM"); const files = b.addWriteFiles(); _ = files.add("Parser.zig", b.fmt("{s}{s}", .{ src, cursor_report })); _ = files.add("Vaxis.zig", b.fmt("{s}{s}", .{ render_src, blank_ink })); + _ = files.add("queue.zig", queue_src); _ = files.addCopyFile(vaxis_dep.path("src/widgets/terminal/Parser.zig"), "widgets/terminal/Parser.zig"); - // Suffixes: this leaves out both Parser.zig files and Vaxis.zig, - // written above. - _ = files.addCopyDirectory(vaxis_dep.path("src"), "", .{ .exclude_extensions = &.{ "Parser.zig", "Vaxis.zig" } }); + // Suffixes: this leaves out both Parser.zig files, Vaxis.zig and + // queue.zig, written above. + _ = files.addCopyDirectory(vaxis_dep.path("src"), "", .{ .exclude_extensions = &.{ "Parser.zig", "Vaxis.zig", "queue.zig" } }); vaxis_mod.root_source_file = files.getDirectory().path(b, "main.zig"); } @@ -940,6 +964,44 @@ pub fn build(b: *std.Build) void { if (sources != 1) @panic("zstbi's build no longer compiles one C file: redo its patch in build.zig"); }; + // One zstd (docs/shared-libs.md): a far replica's stream, compressed by + // its session and read by its client (src/replica.zig). The library's + // compressor and decompressor alone, single-threaded and without its + // x86 assembly, each context made with ZSTD_customMem over c_heap; of + // its block compressors only those of levels 3 (dfast) and 6 (lazy), + // the two replica.zig asks for, and its unused functions dropped at + // link. Zig's std has a decompressor, but no compressor. + if (!freestanding_core) { + const dep = b.dependency("zstd", .{}); + const zstd = b.addLibrary(.{ + .name = "zstd", + .root_module = b.createModule(.{ .target = target, .optimize = c_optimize, .link_libc = true }), + .linkage = .static, + }); + zstd.root_module.addCSourceFiles(.{ + .root = dep.path("lib"), + .files = &.{ + "common/debug.c", "common/entropy_common.c", "common/error_private.c", + "common/fse_decompress.c", "common/pool.c", "common/threading.c", + "common/xxhash.c", "common/zstd_common.c", "compress/fse_compress.c", + "compress/hist.c", "compress/huf_compress.c", "compress/zstd_compress.c", + "compress/zstd_compress_literals.c", "compress/zstd_compress_sequences.c", "compress/zstd_compress_superblock.c", + "compress/zstd_double_fast.c", "compress/zstd_fast.c", "compress/zstd_lazy.c", + "compress/zstd_ldm.c", "compress/zstd_opt.c", "compress/zstd_preSplit.c", + "decompress/huf_decompress.c", "decompress/zstd_ddict.c", "decompress/zstd_decompress.c", + "decompress/zstd_decompress_block.c", + }, + .flags = &.{ + "-DXXH_NAMESPACE=ZSTD_", "-DZSTD_DISABLE_ASM", "-DZSTD_LEGACY_SUPPORT=0", + "-DDEBUGLEVEL=0", "-DZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR", "-DZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR", + "-DZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR", "-DZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR", "-DZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR", + }, + }); + zstd.link_function_sections = true; + zstd.link_data_sections = true; + for (core_mods) |m| m.linkLibrary(zstd); + } + // One call per module instead of one line per module per dependency, and // BEFORE the fold below, which reads what these imports put in the table. for (core_mods) |m| wireCore(m, .{ @@ -1087,7 +1149,7 @@ pub fn build(b: *std.Build) void { if (is_web) { const dp = dump_path.?; - root_mod.addAnonymousImport("embedded.dump.zon", .{ + root_mod.addAnonymousImport("embedded.dump", .{ .root_source_file = if (std.fs.path.isAbsolute(dp)) .{ .cwd_relative = dp } else b.path(dp), }); } @@ -1116,7 +1178,7 @@ pub fn build(b: *std.Build) void { const obj = b.addObject(.{ .name = "pardes-esp32p4", .root_module = root_mod }); b.getInstallStep().dependOn(&b.addInstallFile(obj.getEmittedBin(), "pardes-esp32p4.o").step); - web_step.dependOn(&b.addFail("web needs -Dplatform=web -Dtarget=wasm32-freestanding -Ddump=<dump.zon>").step); + web_step.dependOn(&b.addFail("web needs -Dplatform=web -Dtarget=wasm32-freestanding -Ddump=<file.dump>").step); } else if (platform == .macos) { const header = b.addTranslateC(.{ .root_source_file = b.path("src/macos/pardes.h"), @@ -1284,7 +1346,7 @@ pub fn build(b: *std.Build) void { run_unit.has_side_effects = true; unit_step.dependOn(&run_unit.step); if (testMatch(b, unit_profile, test_filters, unit_step)) |check| check.addArtifactArg(unit_tests); - web_step.dependOn(&b.addFail("web needs -Dplatform=web -Dtarget=wasm32-freestanding -Ddump=<dump.zon>").step); + web_step.dependOn(&b.addFail("web needs -Dplatform=web -Dtarget=wasm32-freestanding -Ddump=<file.dump>").step); } else { var exe_name: []const u8 = if (platform == .gui) "pardes-gui" else "pardes"; if (target.result.os.tag != .linux or target.result.cpu.arch != .x86_64) @@ -1320,7 +1382,7 @@ pub fn build(b: *std.Build) void { const iso_step = b.step("run-isolated", "descend to a pardes with no host but the terminal"); iso_step.dependOn(&run_iso.step); } - web_step.dependOn(&b.addFail("web needs -Dplatform=web -Dtarget=wasm32-freestanding -Ddump=<dump.zon>").step); + web_step.dependOn(&b.addFail("web needs -Dplatform=web -Dtarget=wasm32-freestanding -Ddump=<file.dump>").step); snap_build.addTty(b, .{ .exe = exe, @@ -1471,6 +1533,25 @@ pub fn build(b: *std.Build) void { const lspbench_check_step = b.step("lspbench-check", "require every configured language probe to complete correctly"); lspbench_check_step.dependOn(&run_lspbench_check.step); + const rollback_bench = b.addExecutable(.{ + .name = "pardes-rollback-bench", + .root_module = b.createModule(.{ .target = target, .optimize = optimize, .root_source_file = b.path("test/rollback_bench.zig"), .link_libc = true }), + }); + rollback_bench.root_module.addImport("pardes", core_module); + const run_rollback_bench = b.addRunArtifact(rollback_bench); + run_rollback_bench.has_side_effects = true; + b.step("rollback-bench", "a replica's rollback copy (walked state, pinned blobs, walk time) for a typical and a big session, and a fork of the big one (-Doptimize=ReleaseFast)").dependOn(&run_rollback_bench.step); + + const replicas = b.addExecutable(.{ + .name = "pardes-replicas", + .root_module = b.createModule(.{ .target = target, .optimize = optimize, .root_source_file = b.path("test/replicas.zig"), .link_libc = true }), + }); + replicas.root_module.addImport("pardes", core_module); + const run_replicas = b.addRunArtifact(replicas); + run_replicas.addPassthruArgs(); + run_replicas.has_side_effects = true; + b.step("replicas", "one authority and several replicas in process, each client typing over a delayed link: digests at quiescence, rollback rate and costs per RTT (-- [--seeds N] [--steps M] [--clients C] [--rtt 30,80,207])").dependOn(&run_replicas.step); + const locations_bench_step = b.step("locations-bench", "measure cold/warm result formatting (-Doptimize=ReleaseFast; CSV on stderr)"); if (optimize != .fast) { locations_bench_step.dependOn(&b.addFail("locations-bench requires -Doptimize=ReleaseFast").step); @@ -1519,6 +1600,8 @@ pub fn build(b: *std.Build) void { }), }); perf.root_module.addImport("pardes", core_module); + // --live drives the real binary through a pty (test/e2e_harness.zig). + if (ghostty_vt_for_snap) |vt| perf.root_module.addImport("ghostty-vt", vt); perf.root_module.addOptions("perf_options", perf_options); const run_perf = b.addRunArtifact(perf); run_perf.has_side_effects = true; @@ -1845,18 +1928,20 @@ pub fn build(b: *std.Build) void { const history_step = b.step("history-test", "test historical comparisons and regression gates"); const protocol_match = testMatch(b, unit_profile, test_filters, protocol_step); const history_match = testMatch(b, unit_profile, test_filters, history_step); - for ([_]struct { path: []const u8, libc: bool }{ + for ([_]struct { path: []const u8, libc: bool, optimize: ?std.builtin.OptimizeMode = null }{ .{ .path = "test/history.zig", .libc = false }, .{ .path = "src/9p.zig", .libc = false }, .{ .path = "src/esp32p4_gpio.zig", .libc = false }, .{ .path = "src/esp32p4/input_rescue.zig", .libc = false }, .{ .path = "src/fonts.zig", .libc = true }, .{ .path = "src/c_heap.zig", .libc = false }, + // Its lookup goes wrong only where the optimizer folds it. + .{ .path = "src/c_heap.zig", .libc = false, .optimize = .ReleaseSafe }, }) |entry| { const tests = b.addTest(.{ .root_module = b.createModule(.{ .target = target, - .optimize = optimize, + .optimize = entry.optimize orelse optimize, .root_source_file = b.path(entry.path), .link_libc = entry.libc, }), @@ -1905,6 +1990,9 @@ pub fn build(b: *std.Build) void { run_shell_test.has_side_effects = true; unit_step.dependOn(&run_shell_test.step); if (unit_match) |check| check.addArtifactArg(shell_test); + // The native shell's tests alone, without the perf gate's + // ReleaseFast build: what a -Dtest-filter iteration wants. + b.step("shell-test", "run the native shell's unit tests (src/main.zig's)").dependOn(&run_shell_test.step); const run_profile = b.addRunArtifact(unit_profile); run_profile.addArtifactArg(shell_test); run_profile.addPassthruArgs(); @@ -1929,6 +2017,19 @@ pub fn build(b: *std.Build) void { } } } + + // The test-build programs installed rather than run, for a machine the + // build cannot run them on (`-Dtarget=x86_64-freebsd.15.0`): each into + // <prefix>/test, named for its root file. + const test_install = b.step("test-install", "install the test-build programs into <prefix>/test, to run elsewhere"); + for (test_build.dependencies.items) |dep| { + const t = dep.cast(std.Build.Step.Compile) orelse continue; + const name = switch (t.root_module.root_source_file orelse continue) { + .src_path => |p| std.fs.path.stem(p.sub_path), + else => t.name, + }; + test_install.dependOn(&b.addInstallArtifact(t, .{ .dest_dir = .{ .override = .{ .custom = "test" } }, .dest_sub_path = name }).step); + } } fn testMatch(b: *std.Build, profiler: *std.Build.Step.Compile, filters: []const []const u8, step: *std.Build.Step) ?*std.Build.Step.Run { @@ -1964,7 +2065,8 @@ fn installHome(b: *std.Build, artifact: *std.Build.Step.Compile, home_bin: ?[]co /// file: ghostty opens first and checks after, and the open of a FIFO /// waits for a writer (pardes hung) while a device's open may do /// something. On Linux an O_PATH probe looks, which opens nothing, and -/// the same inode is reopened through /proc/self/fd. +/// the same inode is reopened through /proc/self/fd; elsewhere a stat by +/// path looks first. /// - shared memory is opened non-blocking and must be a regular file, so /// a FIFO in /dev/shm (or a symlink there to one) neither hangs nor maps. /// - an image may be no larger than a screen's storage @@ -1990,14 +2092,15 @@ fn patchGhosttyKitty(b: *std.Build, io: std.Io, dep: *std.Build.Dependency, vt: .{ " const fd = std.c.shm_open(pathz, @as(c_int, @bitCast(std.c.O{ .ACCMODE = .RDONLY })), @as(u16, 0));", \\ // pardes (build.zig): a FIFO there must not hang the open, and - \\ // on Linux nothing but a regular file is opened at all. + \\ // on Linux nothing but a regular file is opened at all. FreeBSD's + \\ // names are no files, and its shm_open refuses O_NONBLOCK. \\ if (comptime builtin.target.os.tag == .linux) if (path.len > 0 and path[0] == '/') { \\ var dev: [std.Io.Dir.max_path_bytes]u8 = undefined; \\ const full = std.fmt.bufPrint(&dev, "/dev/shm{s}", .{path}) catch return error.InvalidData; \\ const shm_stat = std.Io.Dir.cwd().statFile(io, full, .{}) catch return error.InvalidData; \\ if (shm_stat.kind != .file) return error.InvalidData; \\ }; - \\ const fd = std.c.shm_open(pathz, @as(c_int, @bitCast(std.c.O{ .ACCMODE = .RDONLY, .NONBLOCK = true })), @as(u16, 0)); + \\ const fd = std.c.shm_open(pathz, @as(c_int, @bitCast(std.c.O{ .ACCMODE = .RDONLY, .NONBLOCK = builtin.target.os.tag != .freebsd })), @as(u16, 0)); }, .{ " if (stat.size <= 0) return error.InvalidData;", @@ -2011,9 +2114,12 @@ fn patchGhosttyKitty(b: *std.Build, io: std.Io, dep: *std.Build.Dependency, vt: const helper = \\ \\/// pardes (build.zig): `path`, opened for reading only once it is known - \\/// to be a regular file. Elsewhere than Linux, ghostty's open as it was. + \\/// to be a regular file. Elsewhere than Linux, a stat by path first. \\fn pardesOpenRegular(io: std.Io, path: []const u8) !std.Io.File { - \\ if (comptime builtin.target.os.tag != .linux) return std.Io.Dir.cwd().openFile(io, path, .{}); + \\ if (comptime builtin.target.os.tag != .linux) { + \\ if ((try std.Io.Dir.cwd().statFile(io, path, .{})).kind != .file) return error.NotRegularFile; + \\ return std.Io.Dir.cwd().openFile(io, path, .{}); + \\ } \\ const probe = try std.Io.Dir.cwd().openFile(io, path, .{ .path_only = true }); \\ defer probe.close(io); \\ const stat = try probe.stat(io); @@ -2088,6 +2194,7 @@ fn shellOptions(b: *std.Build, cfg: ShellConfig, platform: Platform) *std.Build. // ...and the commit it was built from, when there is one and the build // is stamped at all (see `stamp_commit`). Read at configure time. o.addOption(?[]const u8, "commit", cfg.commit); + o.addOption([]const u8, "deps", deps_text); return o; } |
