diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-05 11:40:11 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 12:41:36 -0300 |
| commit | 3f1533813b6692a736251e4d467a7f108229ddee (patch) | |
| tree | 37a32c5ebbf9d3af08923856fd6fa516f3b33a39 /build.zig | |
| parent | cfd2b993feda1b3f7474225bb32db8cac8edc5ae (diff) | |
| download | pardes-3f1533813b6692a736251e4d467a7f108229ddee.tar.gz pardes-3f1533813b6692a736251e4d467a7f108229ddee.zip | |
targets: the DOM web shell goes (src/web.zig and src/web/, its harnesses web_harness, web_snapshot, web_driver_test and web-snapshots/, tools/web_fixture.py, -Dplatform=web, -Ddump, and the web, web-harness, web-snap, web-e2e and web-driver-test steps), and with it what only a freestanding build needed: `hosted` and every guard on it (every build has a host now), memory's stack-fallback arenas and reduced_target sizes, the emscripten main, the tree-sitter libc shim and the stb stub, lsp's has_client, the web arms of the platform switches (-Dplatform is tui, gui or macos); the macOS files pass zig ast-check; docs/web.md is a paragraph on what it was
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 129 |
1 files changed, 25 insertions, 104 deletions
@@ -25,7 +25,7 @@ const deps_text = blk: { break :blk text; }; -pub const Platform = enum { tui, gui, web, macos }; +pub const Platform = enum { tui, gui, macos }; const PerfBuild = struct { compiler: []const u8, @@ -70,7 +70,7 @@ const gui_shaders = [_][]const u8{ }; pub fn build(b: *std.Build) void { - const requested_platform = b.option(Platform, "platform", "which shell to build (tui, gui, web, macos); absent builds the tui cli and the SDL gui together"); + const requested_platform = b.option(Platform, "platform", "which shell to build (tui, gui, macos); absent builds the tui cli and the SDL gui together"); const platform = requested_platform orelse .tui; const also_gui = requested_platform == null; // A bare `zig build` also copies the binaries into ~/.local/bin. Zig @@ -88,7 +88,7 @@ pub fn build(b: *std.Build) void { .os_tag = .macos, .os_version_min = .{ .semver = macos_min_version }, } else .{}, - .tui, .gui, .web => .{ + .tui, .gui => .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .gnu, @@ -96,22 +96,17 @@ pub fn build(b: *std.Build) void { }, }, }); - const requested_optimize = b.standardOptimizeOption(.{}); + const optimize = b.standardOptimizeOption(.{}); const static = b.option(bool, "static", "statically link") orelse false; - 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| &.{f} else &.{}; - const is_web = platform == .web; - const freestanding_core = is_web; - const enable_mupdf = b.option(bool, "mupdf", "native PDF rendering with MuPDF (AGPL/commercial; native default on, web off; -Dmupdf=false disables)") orelse !freestanding_core; + const enable_mupdf = b.option(bool, "mupdf", "PDF rendering with MuPDF (AGPL/commercial; default on; -Dmupdf=false disables)") orelse true; const enable_jpx = b.option(bool, "jpx", "JPEG 2000 in PDFs, for scanned documents (default on; -Djpx=false drops openjpeg)") orelse true; const embed_sources = b.option(bool, "embed-sources", "serve the editor's own sources under /src of its 9P tree (default off)") orelse false; - const is_web_target = target.result.cpu.arch == .wasm32 and target.result.os.tag == .freestanding; - const optimize = if (is_web) .small else requested_optimize; const test_build = b.step("test-build", "compile unit-test programs without running them"); const doc_typ_opts = b.addOptions(); doc_typ_opts.addOptionPathUntracked("dir", b.path("docs/typ")); @@ -154,7 +149,6 @@ pub fn build(b: *std.Build) void { const source = files.add("test_nonce.zig", b.fmt("pub const nonce = {d};\n", .{std.Io.Clock.awake.now(b.graph.io).nanoseconds})); break :blk b.createModule(.{ .root_source_file = source, .target = target, .optimize = optimize }); } else null; - if (freestanding_core) test_build.dependOn(&b.addFail("test-build needs a native platform").step); const unit_profile = b.addExecutable(.{ .name = "pardes-unit-profile", .root_module = b.createModule(.{ @@ -164,16 +158,11 @@ pub fn build(b: *std.Build) void { }), }); const c_optimize: std.lang.Optimize = if (optimize == .debug) .fast else optimize; - const default_grammars: TreeSitterGrammars = if (is_web) .zig else .full; - const requested_grammars = b.option(TreeSitterGrammars, "tree-sitter", "tree-sitter grammar set: disabled, zig, minimal (c/c++/zig), full"); - const tree_sitter_grammars = requested_grammars orelse default_grammars; + const tree_sitter_grammars = b.option(TreeSitterGrammars, "tree-sitter", "tree-sitter grammar set: disabled, zig, minimal (c/c++/zig), full") orelse .full; const tracy = b.option([]const u8, "tracy", "enable Tracy profiling; supply the path to a Tracy source checkout"); 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; - // 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=<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])"); @@ -197,13 +186,6 @@ pub fn build(b: *std.Build) void { } shaders_step.dependOn(&update_shaders.step); - snap_build.addWeb(b); - - 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=<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 tui/Kitty and gui/SDL backends"); - // 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, .{}); @@ -213,14 +195,13 @@ pub fn build(b: *std.Build) void { const root_mod = b.createModule(.{ .target = target, .optimize = optimize, - // The browser and macOS shells are libraries whose host owns main(): - // each roots at its own flat C ABI instead of src/main.zig. + // The macOS shell is a library whose host owns main(): it roots at + // its own flat C ABI instead of src/main.zig. .root_source_file = b.path(switch (platform) { - .web => "src/web.zig", .macos => "src/macos.zig", .tui, .gui => "src/main.zig", }), - .link_libc = !freestanding_core, + .link_libc = true, }); const core_module = b.createModule(.{ .target = target, @@ -342,22 +323,6 @@ pub fn build(b: *std.Build) void { if (tree_sitter_grammars != .disabled) { const tree_sitter_mod = b.dependency("tree_sitter", .{ .target = target, .optimize = c_optimize }).module("tree_sitter"); - if (is_web) { - const web_libc_include = b.path("src/web/libc/include"); - for (tree_sitter_mod.link_objects.items) |link_object| switch (link_object) { - .other_step => |lib| { - lib.root_module.link_libc = false; - lib.root_module.addIncludePath(web_libc_include); - lib.root_module.addCMacro("NDEBUG", "1"); - }, - else => {}, - }; - root_mod.addIncludePath(b.path("src/web/libc/include")); - root_mod.addCSourceFile(.{ - .file = b.path("src/web/libc.c"), - .flags = &.{ "-std=c11", "-DNDEBUG=1" }, - }); - } ts_mod = tree_sitter_mod; const ts_queries = b.addOptions(); @@ -376,7 +341,7 @@ pub fn build(b: *std.Build) void { const lib = b.addLibrary(.{ .name = "tree-sitter-" ++ g.name, - .root_module = b.createModule(.{ .target = target, .optimize = c_optimize, .link_libc = !is_web }), + .root_module = b.createModule(.{ .target = target, .optimize = c_optimize, .link_libc = true }), .linkage = .static, }); // Every allocation a grammar's external scanner makes goes to the @@ -394,19 +359,14 @@ pub fn build(b: *std.Build) void { lib.root_module.addCSourceFile(.{ .file = dep.path(g.src ++ "/parser.c"), .flags = &ts_cflags }); if (g.scanner) lib.root_module.addCSourceFile(.{ .file = dep.path(g.src ++ "/scanner.c"), .flags = &ts_cflags }); lib.root_module.addIncludePath(dep.path(g.src)); - if (is_web) lib.root_module.addIncludePath(b.path("src/web/libc/include")); ts_libs.append(b.allocator, lib) catch @panic("OOM"); } } ts_queries_opts = ts_queries; } - const zstbi_dep = if (!freestanding_core) b.dependency("zstbi", .{ .target = target, .optimize = c_optimize }) else null; - const zstbi_mod = if (zstbi_dep) |dep| dep.module("root") else b.createModule(.{ - .target = target, - .optimize = optimize, - .root_source_file = b.path("src/web/zstbi.zig"), - }); + const zstbi_dep = b.dependency("zstbi", .{ .target = target, .optimize = c_optimize }); + const zstbi_mod = zstbi_dep.module("root"); // mvzr backtracks with no bound on its work (its own test "do not make // this test any longer": `a?` n times is 2^n steps), and pardes searches @@ -511,19 +471,16 @@ pub fn build(b: *std.Build) void { // One FreeType in a binary: the gui's glyph atlas links it and MuPDF is // built against it (see mupdf.zig). At c_optimize with the rest of the // vendored C, since MuPDF rasterizes a PDF's text through it. - const freetype_dep: ?*std.Build.Dependency = if (freestanding_core) null else b.dependency("freetype", .{ + const freetype_dep = b.dependency("freetype", .{ .target = target, .optimize = c_optimize, .@"enable-libpng" = false, }); - const freetype: ?*std.Build.Step.Compile = if (freetype_dep) |dep| dep.artifact("freetype") else null; + const freetype = freetype_dep.artifact("freetype"); // ...and one zlib, the one FreeType links for its gzip module. Asked of // FreeType's build with the options it asks with, the dependency cache // hands back that same artifact rather than a second copy. - const zlib: ?*std.Build.Step.Compile = if (freetype_dep) |dep| - dep.builder.dependency("zlib", .{ .target = target, .optimize = c_optimize }).artifact("z") - else - null; + const zlib = freetype_dep.builder.dependency("zlib", .{ .target = target, .optimize = c_optimize }).artifact("z"); if (enable_mupdf) { if (b.lazyDependency("mupdf", .{})) |mupdf_dep| { @@ -531,8 +488,8 @@ pub fn build(b: *std.Build) void { .target = target, .optimize = c_optimize, .jpx = enable_jpx, - .freetype = freetype.?, - .zlib = zlib.?, + .freetype = freetype, + .zlib = zlib, }); // src/pdf.zig over this MuPDF: the core's, and pdf-bench's at // ReleaseFast. @@ -794,7 +751,7 @@ pub fn build(b: *std.Build) void { } var ghostty_vt_for_snap: ?*std.Build.Module = null; - const ghostty_simd = !freestanding_core and (!target.result.os.tag.isDarwin() or b.graph.host.result.os.tag.isDarwin()); + const ghostty_simd = !target.result.os.tag.isDarwin() or b.graph.host.result.os.tag.isDarwin(); const ghostty_optimize: std.lang.Optimize = if (optimize == .debug) .safe else optimize; const ghostty_dep = b.lazyDependency("ghostty", .{ .target = target, .optimize = ghostty_optimize, .simd = ghostty_simd, .@"app-runtime" = .none, .@"emit-xcframework" = false }); if (ghostty_dep) |dep| { @@ -817,12 +774,12 @@ pub fn build(b: *std.Build) void { // applied here, at build time. const wuffs_mod: ?*std.Build.Module = if (ghostty_core_vt) |vt| vt.import_table.get("wuffs") else null; for ([_]?*std.Build.Step.Options{ opts, gui_opts }) |o| if (o) |x| x.addOption(bool, "wuffs_images", wuffs_mod != null); - if (wuffs_mod != null) if (zstbi_dep) |dep| { + if (wuffs_mod != null) { var sources: usize = 0; for (zstbi_mod.link_objects.items) |obj| switch (obj) { .c_source_file => |csf| { sources += 1; - const src = configureRead(b, io, dep.builder.root, "src/zstbi.c", 1 << 20) catch @panic("read zstbi.c"); + const src = configureRead(b, io, zstbi_dep.builder.root, "src/zstbi.c", 1 << 20) catch @panic("read zstbi.c"); const writer = "#define STB_IMAGE_WRITE_IMPLEMENTATION\n#include \"stb_image_write.h\"\n"; if (std.mem.count(u8, src, writer) != 1) std.debug.panic("zstbi.c changed at `{s}`: redo its patch in build.zig", .{writer}); // zstbi.deinit still resets the writer's flip flag. @@ -833,7 +790,7 @@ pub fn build(b: *std.Build) void { else => {}, }; 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 @@ -842,7 +799,7 @@ pub fn build(b: *std.Build) void { // 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", @@ -954,7 +911,7 @@ pub fn build(b: *std.Build) void { gui_c.addIncludePath(b.path("src/gui")); gm.addImport("gui_c", gui_c.createModule()); } - gm.linkLibrary(freetype.?); + gm.linkLibrary(freetype); // HarfBuzz from source, like FreeType: its FreeType integration // (HAVE_FREETYPE, hb-ft) links the freetype artifact above, so the two // share one FreeType. The flags are the ones Ghostty builds it with, @@ -971,7 +928,7 @@ pub fn build(b: *std.Build) void { .link_libcpp = true, }), }); - harfbuzz.root_module.linkLibrary(freetype.?); + harfbuzz.root_module.linkLibrary(freetype); harfbuzz.root_module.addIncludePath(upstream.path("src")); harfbuzz.root_module.addCSourceFile(.{ .file = upstream.path("src/harfbuzz.cc"), @@ -1018,34 +975,7 @@ pub fn build(b: *std.Build) void { if (gui_shell_mod != root_mod) root_mod.addAnonymousImport("post-prefix.glsl", .{ .root_source_file = b.path("shaders/post/prefix.glsl") }); - if (is_web) { - const dp = dump_path.?; - root_mod.addAnonymousImport("embedded.dump", .{ - .root_source_file = if (std.fs.path.isAbsolute(dp)) .{ .cwd_relative = dp } else b.path(dp), - }); - } - - if (platform == .web) { - const wasm = b.addExecutable(.{ .name = "pardes", .root_module = root_mod }); - wasm.entry = .disabled; - wasm.rdynamic = true; - wasm.export_memory = true; - wasm.initial_memory = @as(u64, if (tree_sitter_grammars == .full) 64 else 32) * 1024 * 1024; - wasm.max_memory = 512 * 1024 * 1024; - web_step.dependOn(&b.addInstallFileWithDir(wasm.getEmittedBin(), .{ .custom = "web" }, "pardes.wasm").step); - inline for (.{ - .{ "src/web/index.html", "index.html" }, - .{ "src/web/app.mjs", "app.mjs" }, - .{ "src/web/pardes.css", "pardes.css" }, - .{ "assets/AdwaitaMono-Regular.ttf", "AdwaitaMono-Regular.ttf" }, - }) |file| web_step.dependOn(&b.addInstallFileWithDir(b.path(file[0]), .{ .custom = "web" }, file[1]).step); - - const run_web_harness = b.addSystemCommand(&.{ "node", "test/web_harness.mjs" }); - run_web_harness.addDirectoryArg(installed("web")); - run_web_harness.step.dependOn(web_step); - b.step("web-harness", "run the dependency-free JS/WASM DOM harness").dependOn(&run_web_harness.step); - b.getInstallStep().dependOn(web_step); - } else if (platform == .macos) { + if (platform == .macos) { const header = b.addTranslateC(.{ .root_source_file = b.path("src/macos/pardes.h"), .target = target, @@ -1204,7 +1134,6 @@ 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=<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) @@ -1240,7 +1169,6 @@ 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=<file.dump>").step); snap_build.addTty(b, .{ .exe = exe, @@ -1950,13 +1878,6 @@ fn shellOptions(b: *std.Build, cfg: ShellConfig, platform: Platform) *std.Build. return o; } -// a bad -D combination: fail both `zig build` and `zig build web` with the why -fn failBuild(b: *std.Build, web_step: *std.Build.Step, msg: []const u8) void { - const fail = &b.addFail(msg).step; - web_step.dependOn(fail); - b.getInstallStep().dependOn(fail); -} - fn fatArchive(b: *std.Build, lib: *std.Build.Step.Compile) std.Build.LazyPath { const run = std.Build.Step.Run.create(b, "libtool libpardes.a"); run.addArgs(&.{ "libtool", "-static", "-o" }); |
