summaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
Diffstat (limited to 'build')
-rw-r--r--build/addons.zig52
-rw-r--r--build/core.zig3
-rw-r--r--build/gui.zig98
-rw-r--r--build/tests.zig4
4 files changed, 47 insertions, 110 deletions
diff --git a/build/addons.zig b/build/addons.zig
index 195255fd..38b02dff 100644
--- a/build/addons.zig
+++ b/build/addons.zig
@@ -1,37 +1,37 @@
const std = @import("std");
const mupdf_build = @import("mupdf.zig");
-/// The GPU addons over sketchbook's `gpu_scene`: the snake (addons/snake_shader)
-/// and the frame corpus's translucent veil (test/veil.zig). They are the
-/// window build's, as sketchbook is: the terminal's configures without
-/// sketchbook beside the checkout, and there their steps say so.
-pub fn gpu(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.lang.Optimize, addon_mod: *std.Build.Module, window: bool) ?*std.Build.Step.Compile {
+/// The GPU addons over sketchbook's scene format (`gpu_scene`): the snake
+/// (addons/snake_shader) and the frame corpus's translucent veil
+/// (test/veil.zig). They are the window build's, from the sketchbook it
+/// takes (`gui.Window.sketchbook`, null off the window): the terminal's
+/// configures without sketchbook beside the checkout, and there their steps
+/// say so.
+pub fn gpu(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.lang.Optimize, addon_mod: *std.Build.Module, sketchbook: ?*std.Build.Dependency) ?*std.Build.Step.Compile {
const snake_shader_step = b.step("snake-shader", "build the optional GPU snake addon into zig-out/lib");
- var snake_shader_lib: ?*std.Build.Step.Compile = null;
const veil_step = b.step("veil", "build the frame corpus's translucent GPU test addon (test/veil.zig) into zig-out/lib");
- if (!window) {
+ const sb = sketchbook orelse {
const fail = b.addFail("the GPU addons are the window's: -Dplatform=gui (sketchbook beside this checkout)");
snake_shader_step.dependOn(&fail.step);
veil_step.dependOn(&fail.step);
- } else if (b.dependencyLazy("sketchbook", .{ .@"gpu-only" = true })) |sb| {
- const files = b.addWriteFiles();
- for ([_][]const u8{ "vert", "frag", "post.frag" }) |stage| {
- const compile = b.addSystemCommand(&.{ "glslc", "-O" });
- compile.addFileArg(b.path(b.fmt("addons/snake_shader/snake.{s}", .{stage})));
- compile.addArg("-o");
- _ = files.addCopyFile(compile.addOutputFileArg(b.fmt("snake.{s}.spv", .{stage})), b.fmt("{s}.spv", .{stage}));
- }
- const shader_module = b.createModule(.{ .root_source_file = files.add("shaders.zig", "const v align(4) = @embedFile(\"vert.spv\").*;\npub const vert: []const u8 = &v;\nconst f align(4) = @embedFile(\"frag.spv\").*;\npub const frag: []const u8 = &f;\nconst p align(4) = @embedFile(\"post.frag.spv\").*;\npub const post: []const u8 = &p;\n") });
- const module = b.createModule(.{ .root_source_file = b.path("addons/snake_shader/snake_shader.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "addon", .module = addon_mod }, .{ .name = "gpu_scene", .module = sb.module("gpu_scene") }, .{ .name = "shaders", .module = shader_module } } });
- const lib = b.addLibrary(.{ .name = "snake_shader", .linkage = .dynamic, .root_module = module });
- snake_shader_lib = lib;
- snake_shader_step.dependOn(&b.addInstallArtifact(lib, .{}).step);
- snake_shader_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = module })).step);
- // The frame corpus's translucent addon (test/veil.zig), into lib/ beside the snake.
- const veil = b.addLibrary(.{ .name = "veil", .linkage = .dynamic, .root_module = b.createModule(.{ .root_source_file = b.path("test/veil.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "addon", .module = addon_mod }, .{ .name = "gpu_scene", .module = sb.module("gpu_scene") } } }) });
- veil_step.dependOn(&b.addInstallArtifact(veil, .{}).step);
- } else |_| {}
- return snake_shader_lib;
+ return null;
+ };
+ const files = b.addWriteFiles();
+ for ([_][]const u8{ "vert", "frag", "post.frag" }) |stage| {
+ const compile = b.addSystemCommand(&.{ "glslc", "-O" });
+ compile.addFileArg(b.path(b.fmt("addons/snake_shader/snake.{s}", .{stage})));
+ compile.addArg("-o");
+ _ = files.addCopyFile(compile.addOutputFileArg(b.fmt("snake.{s}.spv", .{stage})), b.fmt("{s}.spv", .{stage}));
+ }
+ const shader_module = b.createModule(.{ .root_source_file = files.add("shaders.zig", "const v align(4) = @embedFile(\"vert.spv\").*;\npub const vert: []const u8 = &v;\nconst f align(4) = @embedFile(\"frag.spv\").*;\npub const frag: []const u8 = &f;\nconst p align(4) = @embedFile(\"post.frag.spv\").*;\npub const post: []const u8 = &p;\n") });
+ const module = b.createModule(.{ .root_source_file = b.path("addons/snake_shader/snake_shader.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "addon", .module = addon_mod }, .{ .name = "gpu_scene", .module = sb.module("gpu_scene") }, .{ .name = "shaders", .module = shader_module } } });
+ const lib = b.addLibrary(.{ .name = "snake_shader", .linkage = .dynamic, .root_module = module });
+ snake_shader_step.dependOn(&b.addInstallArtifact(lib, .{}).step);
+ snake_shader_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = module })).step);
+ // The frame corpus's translucent addon (test/veil.zig), into lib/ beside the snake.
+ const veil = b.addLibrary(.{ .name = "veil", .linkage = .dynamic, .root_module = b.createModule(.{ .root_source_file = b.path("test/veil.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "addon", .module = addon_mod }, .{ .name = "gpu_scene", .module = sb.module("gpu_scene") } } }) });
+ veil_step.dependOn(&b.addInstallArtifact(veil, .{}).step);
+ return lib;
}
pub const Pdf = struct {
diff --git a/build/core.zig b/build/core.zig
index 1e2801cf..6c255b2f 100644
--- a/build/core.zig
+++ b/build/core.zig
@@ -371,7 +371,6 @@ pub const Assembly = struct {
gui_opts: ?*std.Build.Step.Options,
/// What an addon in Zig imports (src/kinds/addon.zig).
addon_mod: *std.Build.Module,
- snake_shader_lib: ?*std.Build.Step.Compile,
pdf: addons.Pdf,
image_addon: *std.Build.Step.Compile,
/// The window's FreeType, which MuPDF is built against too.
@@ -464,7 +463,6 @@ pub fn assemble(b: *std.Build, c: struct {
const kind_mod = b.addTranslateC(.{ .root_source_file = b.path("src/kinds/pardes_addon.h"), .target = target, .optimize = optimize }).createModule();
// ...and what an addon in Zig imports over it (src/kinds/addon.zig).
const addon_mod = b.createModule(.{ .root_source_file = b.path("src/kinds/addon.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "pardes_addon", .module = kind_mod }} });
- const snake_shader_lib = addons.gpu(b, target, optimize, addon_mod, c.also_gui or c.platform == .gui);
const pdf_built = addons.pdf(b, .{
.addon_mod = addon_mod,
.c_optimize = c_optimize,
@@ -609,7 +607,6 @@ pub fn assemble(b: *std.Build, c: struct {
.opts = opts,
.gui_opts = gui_opts,
.addon_mod = addon_mod,
- .snake_shader_lib = snake_shader_lib,
.pdf = pdf_built,
.image_addon = image_addon,
.freetype = freetype,
diff --git a/build/gui.zig b/build/gui.zig
index 24aa6277..cc90bd0a 100644
--- a/build/gui.zig
+++ b/build/gui.zig
@@ -1,38 +1,22 @@
const std = @import("std");
-const gui_shaders = [_][]const u8{
- "ui.vert",
- "ui.frag",
- "decor.frag",
- "overlay.vert",
- "overlay.frag",
- "image.vert",
- "image.frag",
-};
-
/// The window's pieces, made once and wired into each of its shells (the
/// bare build's pardes-gui; -Dplatform=gui's pardes-gui and its static):
-/// SDL, gui.zig's `c`, sketchbook's renderer and glyph atlas, FreeType and
-/// HarfBuzz; and the renderer's and atlas's own tests, for unit-test. A
-/// piece whose lazy package is not fetched yet is null.
+/// SDL, gui.zig's `c`, sketchbook's devices (`dev`: the renderer and the
+/// glyph atlas), FreeType and HarfBuzz. A piece whose lazy package is not
+/// fetched yet is null.
pub const Window = struct {
sdl: ?Sdl = null,
- sketchbook: ?*std.Build.Dependency,
+ /// sketchbook as the window takes it: the devices over gui.zig's `c`
+ /// (the GPU addons take its scene format from the same).
+ sketchbook: ?*std.Build.Dependency = null,
freetype: ?*std.Build.Step.Compile,
harfbuzz: ?HarfBuzz = null,
darwin: bool,
- /// sketchbook's Cells.zig's own tests (the instance ABI).
- cells_test: ?*std.Build.Step.Compile = null,
- /// sketchbook's Atlas.zig's own tests.
- atlas_test: ?*std.Build.Step.Compile = null,
const Sdl = struct {
lib: *std.Build.Step.Compile,
include: std.Build.LazyPath,
- gui_c: *std.Build.Module,
- /// sketchbook's renderer by file, over gui_c: sketch_gpu,
- /// font_atlas, gpu_cells, gpu_present, gpu_scene.
- renderer: ?[5]std.Build.Module.Import = null,
/// The macOS trackpad adapter, compiled apart.
trackpad: ?std.Build.LazyPath = null,
};
@@ -44,8 +28,10 @@ pub const Window = struct {
if (w.sdl) |sdl| {
gm.linkLibrary(sdl.lib);
gm.addIncludePath(sdl.include);
- gm.addImport("gui_c", sdl.gui_c);
- if (sdl.renderer) |imports| for (imports) |i| gm.addImport(i.name, i.module);
+ if (w.sketchbook) |sb| {
+ gm.addImport("gui_c", sb.module("c"));
+ gm.addImport("dev", sb.module("dev"));
+ }
if (sdl.trackpad) |object| {
gm.addObjectFile(object);
gm.linkFramework("Cocoa", .{});
@@ -59,7 +45,7 @@ pub const Window = struct {
}
if (w.darwin)
gm.addRPath(.{ .cwd_relative = "/usr/local/lib" });
- if (w.sketchbook) |sb| gm.addCSourceFile(.{ .file = sb.path("vendor/font.c") });
+ if (w.sketchbook) |sb| gm.addCSourceFile(.{ .file = sb.namedLazyPath("font.c") });
// the embedded UI font: provided as a build import since assets/ lives
// outside the src/ module root (@embedFile can't escape it)
gm.addAnonymousImport("AdwaitaMono-Regular.ttf", .{
@@ -68,9 +54,8 @@ pub const Window = struct {
}
};
-pub fn make(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.lang.Optimize, macos_sdk: ?[]const u8, prebuilt_shaders: bool, freetype: ?*std.Build.Step.Compile, test_filters: []const []const u8) Window {
- const sketchbook = b.lazyDependency("sketchbook", .{ .@"gpu-only" = true });
- var w: Window = .{ .sketchbook = sketchbook, .freetype = freetype, .darwin = target.result.os.tag.isDarwin() };
+pub fn make(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.lang.Optimize, macos_sdk: ?[]const u8, prebuilt_shaders: bool, freetype: ?*std.Build.Step.Compile) Window {
+ var w: Window = .{ .freetype = freetype, .darwin = target.result.os.tag.isDarwin() };
// SDL's build asks a cross build for macOS for the SDK's paths.
const sdk: ?std.Build.LazyPath = if (macos_sdk) |p| .{ .cwd_relative = p } else null;
const sdl_dep = b.lazyDependency("sdl", .{ .target = target, .optimize = optimize, .sanitize_c = .off, .preferred_linkage = .static, .system_include_path = if (sdk) |p| p.path(b, "usr/include") else null, .system_framework_path = if (sdk) |p| p.path(b, "System/Library/Frameworks") else null, .library_path = if (sdk) |p| p.path(b, "usr/lib") else null });
@@ -80,7 +65,11 @@ pub fn make(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.lang.
// MJPEG, neither of which pardes calls) is a second PNG and JPEG
// decoder beside the build's: off (docs/shared-libs.md).
sdl_lib.root_module.addCMacro("SDL_DISABLE_STB", "1");
- // gui.zig's `c`: SDL and the font shim, which @cImport gave it before Zig 0.17.
+ // gui.zig's `c`: SDL and the font shim, which @cImport gave it
+ // before Zig 0.17, translated by sketchbook with the devices it
+ // compiles against it (its `c` and `dev`); their SPIR-V is
+ // sketchbook's GLSL through glslc, or its prebuilt copies with
+ // -Dprebuilt-shaders.
const header = b.addWriteFiles().add("gui_c.h",
\\#define SDL_DISABLE_OLD_NAMES 1
\\#include <SDL3/SDL.h>
@@ -88,33 +77,9 @@ pub fn make(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.lang.
\\#include "macos_trackpad.h"
\\
);
- const gui_c = b.addTranslateC(.{ .root_source_file = header, .target = target, .optimize = optimize });
- gui_c.addIncludePath(dep.path("include"));
- gui_c.addIncludePath(b.path("src/gui"));
- const gui_c_mod = gui_c.createModule();
- var sdl: Window.Sdl = .{ .lib = sdl_lib, .include = dep.path("include"), .gui_c = gui_c_mod };
- if (sketchbook) |sb| {
- const gpu = b.createModule(.{ .root_source_file = sb.path("dev/draw/Executor.zig"), .imports = &.{ .{ .name = "abi", .module = sb.module("abi") }, .{ .name = "c", .module = gui_c_mod } } });
- // The glyph atlas (dev/text/Atlas.zig) over the font shim
- // (vendor/font.{c,h}), compiled below against pardes's
- // FreeType and HarfBuzz.
- const atlas_mod = b.createModule(.{ .root_source_file = sb.path("dev/text/Atlas.zig"), .imports = &.{.{ .name = "c", .module = gui_c_mod }} });
- // pardes's renderer, moved to sketchbook (dev/draw/), compiled
- // against pardes's SDL; its tests run with unit-test. Its
- // SPIR-V is sketchbook's GLSL through glslc, or the prebuilt
- // copies with -Dprebuilt-shaders.
- const cells_mod = b.createModule(.{ .root_source_file = sb.path("dev/draw/Cells.zig"), .imports = &.{ .{ .name = "c", .module = gui_c_mod }, .{ .name = "font_atlas", .module = atlas_mod } } });
- for (gui_shaders) |name| cells_mod.addAnonymousImport(b.fmt("{s}.spv", .{name}), .{
- .root_source_file = if (prebuilt_shaders)
- sb.path(b.fmt("dev/draw/shaders/prebuilt/{s}.spv", .{name}))
- else
- compileGlsl(b, sb.path(b.fmt("dev/draw/shaders/{s}.glsl", .{name})), name),
- });
- const present = b.createModule(.{ .root_source_file = sb.path("dev/draw/Present.zig"), .imports = &.{ .{ .name = "c", .module = gui_c_mod }, .{ .name = "gpu_cells", .module = cells_mod } } });
- sdl.renderer = .{ .{ .name = "sketch_gpu", .module = gpu }, .{ .name = "font_atlas", .module = atlas_mod }, .{ .name = "gpu_cells", .module = cells_mod }, .{ .name = "gpu_present", .module = present }, .{ .name = "gpu_scene", .module = sb.module("gpu_scene") } };
- w.cells_test = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = sb.path("dev/draw/Cells.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "c", .module = gui_c_mod }, .{ .name = "font_atlas", .module = atlas_mod } } }), .filters = test_filters });
- gui_c.addIncludePath(sb.path("vendor"));
- }
+ const include: []const std.Build.LazyPath = &.{ dep.path("include"), b.path("src/gui") };
+ w.sketchbook = b.lazyDependency("sketchbook", .{ .target = target, .optimize = optimize, .@"c-header" = header, .@"c-include" = include, .@"prebuilt-shaders" = prebuilt_shaders });
+ var sdl: Window.Sdl = .{ .lib = sdl_lib, .include = dep.path("include") };
if (target.result.os.tag == .macos) {
const arch = if (target.result.cpu.arch == .aarch64) "arm64" else @tagName(target.result.cpu.arch);
const shim = b.addSystemCommand(&.{ "xcrun", "clang", "-fobjc-arc", "-O2", "-target", b.fmt("{s}-apple-macos13.0", .{arch}), "-I" });
@@ -166,17 +131,6 @@ pub fn make(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.lang.
},
});
w.harfbuzz = .{ .lib = harfbuzz, .include = upstream.path("src") };
- // The Atlas's own tests, over the same FreeType, HarfBuzz and
- // shim, the embedded face theirs to draw.
- if (w.sdl) |sdl| if (sketchbook) |sb| {
- const atlas_mod = b.createModule(.{ .root_source_file = sb.path("dev/text/Atlas.zig"), .target = target, .optimize = optimize, .link_libc = true, .imports = &.{.{ .name = "c", .module = sdl.gui_c }} });
- atlas_mod.linkLibrary(ft);
- atlas_mod.linkLibrary(harfbuzz);
- atlas_mod.addIncludePath(upstream.path("src"));
- atlas_mod.addCSourceFile(.{ .file = sb.path("vendor/font.c") });
- atlas_mod.addAnonymousImport("AdwaitaMono-Regular.ttf", .{ .root_source_file = b.path("assets/AdwaitaMono-Regular.ttf") });
- w.atlas_test = b.addTest(.{ .root_module = atlas_mod, .filters = test_filters });
- };
}
if (target.result.os.tag == .macos) if (w.sdl) |sdl| {
const adapter_test = b.addSystemCommand(&.{ "xcrun", "clang", "-fobjc-arc", "-O1", "-framework", "Cocoa", "-I" });
@@ -193,13 +147,3 @@ pub fn make(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.lang.
};
return w;
}
-
-/// glslc <glsl> -fshader-stage=<vertex|fragment> -o <name>.spv, returned as
-/// a LazyPath for @embedFile. The stage is the name's own suffix.
-fn compileGlsl(b: *std.Build, glsl: std.Build.LazyPath, name: []const u8) std.Build.LazyPath {
- const stage = if (std.mem.endsWith(u8, name, ".vert")) "vertex" else "fragment";
- const cmd = b.addSystemCommand(&.{ "glslc", b.fmt("-fshader-stage={s}", .{stage}) });
- cmd.addFileArg(glsl);
- cmd.addArg("-o");
- return cmd.addOutputFileArg(b.fmt("{s}.spv", .{name}));
-}
diff --git a/build/tests.zig b/build/tests.zig
index d8bce18d..d88655e3 100644
--- a/build/tests.zig
+++ b/build/tests.zig
@@ -9,8 +9,6 @@ const program = tools.program;
/// addon-test (and the addons it loads), kitty-test, the 9P roots.
pub fn add(b: *std.Build, c: struct {
addon_mod: *std.Build.Module,
- atlas_test: ?*std.Build.Step.Compile,
- cells_test: ?*std.Build.Step.Compile,
core_lean: *std.Build.Module,
core_module: *std.Build.Module,
/// core_module's configuration, for the test roots that run on its imports.
@@ -62,8 +60,6 @@ pub fn add(b: *std.Build, c: struct {
// The perf and fs bench programs' own tests: they compile no editor.
_ = units.add(b, units.root(b, "test/perf.zig", true, &.{.{ .name = "perf_options", .module = c.tools.perf_options.createModule() }}), null);
_ = units.add(b, units.root(b, "test/fs_bench.zig", null, &.{}), null);
- if (c.cells_test) |t| _ = units.add(b, t, null);
- if (c.atlas_test) |t| _ = units.add(b, t, null);
const core_test = b.addTest(.{ .root_module = c.core_lean, .filters = c.test_filters });
const run_core_test = b.addRunArtifact(core_test);
run_core_test.has_side_effects = true;