diff options
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -36,6 +36,12 @@ //! (`@import("pardes").grammar_manifest.all`: each grammar's name, its //! extensions and what it needs), is `grammar_manifest`. //! +//! A browser's module, one call a language (`wasmModule`): +//! +//! const pardes = @import("pardes"); +//! b.installArtifact(pardes.wasmModule(b, .{ .language = "rust" })); +//! b.installArtifact(pardes.wasmModule(b, .{})); // the patch view alone +//! //! Every dependency but tree-sitter's runtime is lazy in the manifest, so //! such a package fetches what it asked for and nothing else. //! `pardes-editor` has `pardes-syntax` in it as `.syntax`: a file belongs @@ -403,6 +409,46 @@ pub fn build(b: *std.Build) void { } } +/// A browser's module, one call a language (the head comment): wasm32-wasi +/// as a reactor (no `main`; `_initialize`, then any export), with +/// `language`'s grammar and what it needs, tree-sitter's runtime and +/// pardes's highlighter; or, with no language, the patch view alone, with +/// no tree-sitter in it. Its exports are abi/wasm.zig's (`memory`, +/// `_initialize`, `reserve`, `release`, `patch`, and with a language +/// `highlight`), the same in every module; docs/typ/building.typ has their +/// layouts and the WASI imports a page stubs. The package's dependency on +/// pardes is named "pardes". A name the manifest does not have fails the +/// configure, as `.languages` does. +pub fn wasmModule(b: *std.Build, options: struct { + language: ?[]const u8 = null, + optimize: std.lang.Optimize = .ReleaseSmall, +}) *std.Build.Step.Compile { + const target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .wasi }); + const pardes = if (options.language) |name| + b.dependency("pardes", .{ .target = target, .optimize = options.optimize, .languages = name }) + else + b.dependency("pardes", .{ .target = target, .optimize = options.optimize, .grammars = .none }); + const exports = b.addOptions(); + exports.addOption(bool, "highlight", options.language != null); + const module = b.addExecutable(.{ + .name = b.fmt("pardes-{s}", .{options.language orelse "patch"}), + .root_module = b.createModule(.{ + .target = target, + .optimize = options.optimize, + .root_source_file = pardes.path("abi/wasm.zig"), + .imports = &.{ + .{ .name = "pardes-syntax", .module = pardes.module("pardes-syntax") }, + .{ .name = "wasm_options", .module = exports.createModule() }, + }, + }), + }); + module.entry = .disabled; + module.wasi_exec_model = .reactor; + // Its own functions alone: tree-sitter's and libc's stay inside. + module.root_module.export_symbol_names = if (options.language != null) &.{ "reserve", "release", "patch", "highlight" } else &.{ "reserve", "release", "patch" }; + return module; +} + /// Installs `artifact` in the prefix and, given `home_bin`, copies it there /// too (`install` unlinks first, so a running binary is replaced). fn installHome(b: *std.Build, artifact: *std.Build.Step.Compile, home_bin: ?[]const u8) void { |
