summaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
Diffstat (limited to 'build')
-rw-r--r--build/addons.zig9
-rw-r--r--build/core.zig15
-rw-r--r--build/tests.zig1
3 files changed, 20 insertions, 5 deletions
diff --git a/build/addons.zig b/build/addons.zig
index 38b02dff..a1bdb43b 100644
--- a/build/addons.zig
+++ b/build/addons.zig
@@ -52,6 +52,9 @@ pub const Pdf = struct {
/// `pardes_addon` alone.
pub fn pdf(b: *std.Build, c: struct {
addon_mod: *std.Build.Module,
+ /// pdf.zig's and the bridge's (core.zig's `addon_optimize`); MuPDF's
+ /// and the rest of the C's `c_optimize`.
+ addon_optimize: std.lang.Optimize,
c_optimize: std.lang.Optimize,
enable_jpx: bool,
freetype: ?*std.Build.Step.Compile,
@@ -83,7 +86,7 @@ pub fn pdf(b: *std.Build, c: struct {
// The bridge's header translated here for pdf.zig (Zig 0.17 has no
// @cImport), as the kinds' header is for the core.
const bridge_mod = b.addTranslateC(.{ .root_source_file = b.path("addons/pdf/pdf_bridge.h"), .target = c.target, .optimize = c.c_optimize }).createModule();
- const pdf_mod = b.createModule(.{ .root_source_file = b.path("addons/pdf/pdf.zig"), .target = c.target, .optimize = c.c_optimize, .link_libc = true, .imports = &.{ .{ .name = "addon", .module = c.addon_mod }, .{ .name = "pdf_bridge", .module = bridge_mod } } });
+ const pdf_mod = b.createModule(.{ .root_source_file = b.path("addons/pdf/pdf.zig"), .target = c.target, .optimize = c.addon_optimize, .link_libc = true, .imports = &.{ .{ .name = "addon", .module = c.addon_mod }, .{ .name = "pdf_bridge", .module = bridge_mod } } });
mupdf.linkTo(pdf_mod);
pdf_mod.addIncludePath(b.path("addons/pdf"));
pdf_mod.addCSourceFile(.{ .file = b.path("addons/pdf/pdf_bridge.c"), .flags = &.{"-std=gnu11"} });
@@ -105,8 +108,8 @@ pub fn pdf(b: *std.Build, c: struct {
/// The image addon (addons/image/image.zig over stb_image, stb.c),
/// installed by its step and handed by path to every test that opens a
/// picture.
-pub fn image(b: *std.Build, target: std.Build.ResolvedTarget, c_optimize: std.lang.Optimize, addon_mod: *std.Build.Module, zstbi_dep: *std.Build.Dependency) *std.Build.Step.Compile {
- const image_mod = b.createModule(.{ .root_source_file = b.path("addons/image/image.zig"), .target = target, .optimize = c_optimize, .link_libc = true, .imports = &.{.{ .name = "addon", .module = addon_mod }} });
+pub fn image(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.lang.Optimize, addon_mod: *std.Build.Module, zstbi_dep: *std.Build.Dependency) *std.Build.Step.Compile {
+ const image_mod = b.createModule(.{ .root_source_file = b.path("addons/image/image.zig"), .target = target, .optimize = optimize, .link_libc = true, .imports = &.{.{ .name = "addon", .module = addon_mod }} });
image_mod.addIncludePath(zstbi_dep.path("libs/stbi"));
image_mod.addCSourceFile(.{ .file = b.path("addons/image/stb.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
const image_addon = b.addLibrary(.{ .name = "image", .linkage = .dynamic, .root_module = image_mod });
diff --git a/build/core.zig b/build/core.zig
index e8150843..f9cb450f 100644
--- a/build/core.zig
+++ b/build/core.zig
@@ -310,8 +310,10 @@ pub const Parts = struct {
pdf: ?*std.Build.Module,
term: *std.Build.Module,
plain: *std.Build.Module,
- /// The kinds' C ABI (abi/pardes_addon.h), translated.
+ /// The kinds' C ABI (abi/pardes_addon.h), translated, and what an addon
+ /// in Zig imports over it (abi/addon.zig: the core's `cSlice` too).
kind: *std.Build.Module,
+ addon: *std.Build.Module,
themes: *std.Build.Module,
ts: TreeSitter,
mvzr: *std.Build.Module,
@@ -401,6 +403,7 @@ pub fn module(b: *std.Build, p: Parts, c: Core) Modules {
if (c.terminal) x.addImport("term", p.term);
x.addImport("plain", p.plain);
x.addImport("pardes_addon", p.kind);
+ x.addImport("addon", p.addon);
x.addImport("generated_themes", p.themes);
x.addImport("tree-sitter", p.ts.mod);
x.addImport("ts_queries", ts_queries);
@@ -514,8 +517,15 @@ pub fn assemble(b: *std.Build, c: struct {
const kind_mod = b.addTranslateC(.{ .root_source_file = b.path("abi/pardes_addon.h"), .target = target, .optimize = optimize }).createModule();
// ...and what an addon in Zig imports over it (abi/addon.zig).
const addon_mod = b.createModule(.{ .root_source_file = b.path("abi/addon.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "pardes_addon", .module = kind_mod }} });
+ // The C-backed addons' own Zig and bridge at the C's speed, with the
+ // checks a release keeps: ReleaseSafe in a Debug build, as in the
+ // user's (a page's search without a hit sliced a NULL: only a release
+ // build aborted, Debug's addons ran ReleaseFast); MuPDF and stb stay
+ // at c_optimize.
+ const addon_optimize: std.lang.Optimize = if (optimize == .debug) .safe else c_optimize;
const pdf_built = addons.pdf(b, .{
.addon_mod = addon_mod,
+ .addon_optimize = addon_optimize,
.c_optimize = c_optimize,
.enable_jpx = c.enable_jpx,
.freetype = freetype,
@@ -602,7 +612,7 @@ pub fn assemble(b: *std.Build, c: struct {
// library and no allocator hook of its own (it takes Zig allocators).
const xitdb_mod = b.dependency("xitdb", .{ .target = target, .optimize = optimize }).module("xitdb");
- const image_addon = addons.image(b, target, c_optimize, addon_mod, zstbi_dep);
+ const image_addon = addons.image(b, target, addon_optimize, addon_mod, zstbi_dep);
// The records the core and the terminal both name (abi/plain.zig).
const plain_mod = b.createModule(.{ .root_source_file = b.path("abi/plain.zig"), .target = target, .optimize = optimize });
// The terminal, a module of its own (core/term/term.zig): the emulator and
@@ -625,6 +635,7 @@ pub fn assemble(b: *std.Build, c: struct {
.term = term_mod,
.plain = plain_mod,
.kind = kind_mod,
+ .addon = addon_mod,
.themes = themes_mod,
.ts = ts,
.mvzr = mvzr_mod,
diff --git a/build/tests.zig b/build/tests.zig
index e0b33911..5e913501 100644
--- a/build/tests.zig
+++ b/build/tests.zig
@@ -162,6 +162,7 @@ pub fn add(b: *std.Build, c: struct {
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);
for ([_]*std.Build.Module{ snake_mod, life_mod, liar_mod, c.parts.image }) |m| addon_test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = m })).step);
+ if (c.pdf_addon) |lib| addon_test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = lib.root_module })).step);
// ...and the pdf addon's, which mupdf-check runs too (its script
// opens docs/design.pdf, from the build root).
const libs = [_]struct { ?*std.Build.Step.Compile, []const u8 }{ .{ fake_addon_lib.?, "addons/fake/fake" }, .{ snake_lib, "addons/snake/snake" }, .{ c.snake_shader_lib, "addons/snake_shader/snake_shader" }, .{ life_lib, "addons/life/life" }, .{ c.pdf_addon, "addons/pdf/pdf" } };