diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-21 02:30:14 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-21 02:52:47 -0300 |
| commit | dea2920233bbb64b20f7ccebd42ac5beab14033d (patch) | |
| tree | 4d1622bffae6fbf653764ea33cb038afd6f02754 /test/consumer/build.zig | |
| parent | ee5b6aa3ef0bf398c5381498af40fa93d20cf0b3 (diff) | |
| download | pardes-dea2920233bbb64b20f7ccebd42ac5beab14033d.tar.gz pardes-dea2920233bbb64b20f7ccebd42ac5beab14033d.zip | |
library: a browser's module is pardes's build's to make: build.zig exports `wasmModule(b, .{ .language = "rust" })` (the user's ruling: the self-contained module is exposed to the consumer's build.zig): wasm32-wasi, a reactor, one language's grammar and what it needs with tree-sitter's runtime and the highlighter, or with no language the patch view alone; its exports are abi/wasm.zig's (beside the other boundaries: a module of its own whose few globals are the page's, not a core's), the same in every module: `reserve`/`release` (toilet's, at least one byte so reserve(0) is a pointer), `highlight(path, path_len, text, len)` (toilet's without its diff flag: diffs go to the patch view now), `patch(text, len)` (a 20-byte header: the rows' text, a style byte a byte, and nine-u32 records: kind, old, new (0 for none), code_start, the row's text and its path as offsets, flags bit 0 no newline), `memory`, `_initialize`; only those are exported (export_symbol_names, not rdynamic: tree-sitter's and libc's symbols stay inside), and a panic is one `fd_write` to stderr and a trap (std's handler writes through std.Io and imported 26 more WASI functions): a language's module imports fd_write, fd_seek, fd_close (libc's streams, tree-sitter's debug output), the patch view's none, 24,533 bytes (11,108 gzip; with tree-sitter's runtime in it, 139,337); rust's is 1,290,182 (183,568 gzip; its parser object alone 1,134,394); test/consumer makes both through `wasmModule` and runs them under node (wasm.mjs: a page with every WASI import a stub reads the header and records back: rows, numbers, paths, the changed `*`, a no-newline flag, reserve(0), a highlight), saying so when there is no node; `sizes` installs one module a language of the manifest
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/consumer/build.zig')
| -rw-r--r-- | test/consumer/build.zig | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/test/consumer/build.zig b/test/consumer/build.zig index f8f63712..45e1e2e5 100644 --- a/test/consumer/build.zig +++ b/test/consumer/build.zig @@ -3,9 +3,10 @@ //! runs `zig build test` here. `pardes-syntax` with the minimal grammars, //! as a program that draws source text itself takes it; with one language //! named, for each language of pardes's manifest, read here at configure -//! time; and `pardes-editor` with no grammar of pardes's and one of its own, +//! time; `pardes-editor` with no grammar of pardes's and one of its own, //! C's, compiled here from the package pardes pins and handed in at run -//! time, as sketchbook's `examples/live` takes it. +//! time, as sketchbook's `examples/live` takes it; and the browser's modules +//! pardes's build makes (`wasmModule`), run under node when it is there. const std = @import("std"); const pardes = @import("pardes"); @@ -23,7 +24,7 @@ pub fn build(b: *std.Build) void { // The grammar of its own: C's, from the package pardes's manifest pins // (so `--pkg-dir` at pardes's zig-pkg has it), as that package builds it. const grammar = b.dependency("ts_c", .{ .target = target, .optimize = .ReleaseFast, .@"build-shared" = false }).artifact("tree-sitter-c"); - const step = b.step("test", "colour, outline and walk a C and a Zig source through pardes's syntax, build it with one language named, and edit a text with its editor and a grammar of this package's"); + const step = b.step("test", "colour, outline and walk a C and a Zig source through pardes's syntax, build it with one language named, edit a text with its editor and a grammar of this package's, and run a browser's modules"); // A file belongs to one module: the syntax alone, and the editor (which // has it as `.syntax`), each a test of its own. // The patch view with no grammar at all: the editor's package has @@ -43,7 +44,16 @@ pub fn build(b: *std.Build) void { // with it alone (and what it needs). `test` runs two: rust, alone, and // markdown, which brings its inline grammar. const each = b.step("each-language", "build and test pardes-syntax with each language of its manifest named alone"); + // A browser's module a language, and the patch view's: `sizes` + // installs every one; `test` runs the patch view's and rust's. + const sizes = b.step("sizes", "install a browser's module for each language, and the patch view's, into <prefix>/bin"); + const patch = pardes.wasmModule(b, .{}); + sizes.dependOn(&b.addInstallArtifact(patch, .{}).step); + var rust: ?*std.Build.Step.Compile = null; for (pardes.grammar_manifest.all) |g| if (g.exts.len > 0) { + const module = pardes.wasmModule(b, .{ .language = g.name }); + sizes.dependOn(&b.addInstallArtifact(module, .{}).step); + if (std.mem.eql(u8, g.name, "rust")) rust = module; const name = b.addOptions(); name.addOption([]const u8, "name", g.name); const one = b.addRunArtifact(b.addTest(.{ .name = b.fmt("one-{s}", .{g.name}), .root_module = b.createModule(.{ @@ -58,6 +68,20 @@ pub fn build(b: *std.Build) void { each.dependOn(&one.step); if (std.mem.eql(u8, g.name, "rust") or std.mem.eql(u8, g.name, "markdown")) step.dependOn(&one.step); }; + // Each run as a page runs it, its WASI imports stubs. + if (b.findProgram(.{ .names = &.{"node"} })) |node| { + const run = b.addSystemCommand(&.{node}); + run.setName("node: the patch view's module and rust's"); + run.addFileArg(b.path("wasm.mjs")); + run.addArtifactArg(patch); + run.addArtifactArg(rust.?); + run.expectExitCode(0); + step.dependOn(&run.step); + } else { + std.debug.print("consumer-test: no node on PATH: the browser's modules are built, not run\n", .{}); + step.dependOn(&patch.step); + step.dependOn(&rust.?.step); + } // ...and a name it does not have: the configure fails, saying so. const bad = b.addSystemCommand(&.{ b.graph.zig_exe, "build", "-Dlanguage=klingon", "--pkg-dir", "../../zig-pkg" }); bad.setName("a language pardes does not have fails the configure"); |
