summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig46
1 files changed, 37 insertions, 9 deletions
diff --git a/build.zig b/build.zig
index 8fc5ef56..0e67b61e 100644
--- a/build.zig
+++ b/build.zig
@@ -68,10 +68,17 @@ pub fn build(b: *std.Build) void {
// A bare `zig build` also copies the binaries into ~/.local/bin. Zig
// 0.17 keeps the prefix in the maker process, out of this script's
// reach, so `--prefix` no longer turns it off: -Dhome-install=false does.
- const home_bin: ?[]const u8 = if (also_gui and (b.option(bool, "home-install", "a bare `zig build` also copies the binaries into ~/.local/bin (default: true)") orelse true))
+ const home_enabled = b.option(bool, "home-install", "install binaries and addons into the user directories (default: true)") orelse true;
+ const home_bin: ?[]const u8 = if (also_gui and home_enabled)
if (b.graph.environ_map.get("HOME")) |home| b.pathJoin(&.{ home, ".local", "bin" }) else null
else
null;
+ const home_addons: ?[]const u8 = if (!home_enabled) null else if (b.graph.environ_map.get("XDG_DATA_HOME")) |data|
+ b.pathJoin(&.{ data, "pardes", "addons" })
+ else if (b.graph.environ_map.get("HOME")) |home|
+ b.pathJoin(&.{ home, ".local", "share", "pardes", "addons" })
+ else
+ null;
const home_install = home_bin != null;
const target = b.standardTargetOptions(.{
.default_target = switch (platform) {
@@ -438,6 +445,23 @@ pub fn build(b: *std.Build) void {
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_step = b.step("snake-shader", "build the optional GPU snake addon into zig-out/lib");
+ var snake_shader_lib: ?*std.Build.Step.Compile = null;
+ if (b.lazyDependency("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 PDF addon (addons/pdf/pdf.zig over MuPDF through pdf_bridge.c), built
// and installed as the image addon is: compiled only for a step that
// needs it (`pdf`, the tests). MuPDF is compiled against the build's
@@ -894,7 +918,13 @@ pub fn build(b: *std.Build) void {
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"));
- gm.addImport("gui_c", gui_c.createModule());
+ const gui_c_mod = gui_c.createModule();
+ gm.addImport("gui_c", gui_c_mod);
+ if (b.lazyDependency("sketchbook", .{ .@"gpu-only" = true })) |sb| {
+ const gpu = b.createModule(.{ .root_source_file = sb.path("src/gpu/Executor.zig"), .imports = &.{ .{ .name = "abi", .module = sb.module("abi") }, .{ .name = "c", .module = gui_c_mod } } });
+ gm.addImport("sketch_gpu", gpu);
+ gm.addImport("gpu_scene", sb.module("gpu_scene"));
+ }
sdl_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);
@@ -1151,7 +1181,7 @@ pub fn build(b: *std.Build) void {
// The addons, a step each: the default install is the binaries
// alone, and `zig build image pdf` (or `addons`) puts the libraries
// where the start scan finds them, <prefix>/lib/pardes/addons (and
- // ~/.local/lib/pardes/addons with the home install).
+ // $XDG_DATA_HOME/pardes/addons unless -Dhome-install=false).
const addons_step = b.step("addons", "install the image and pdf addons");
for ([_]?*std.Build.Step.Compile{ image_addon, pdf_addon }, [_][]const u8{ "image", "pdf" }) |lib, name| {
const step = b.step(name, b.fmt("install the {s} addon, <prefix>/lib/pardes/addons/{s}.so", .{ name, name }));
@@ -1161,11 +1191,9 @@ pub fn build(b: *std.Build) void {
continue;
};
step.dependOn(&b.addInstallFileWithDir(l.getEmittedBin(), .lib, b.fmt("pardes/addons/{s}.so", .{name})).step);
- if (home_bin) |dir| {
- const copy = b.addSystemCommand(&.{ "install", "-Dm755" });
- copy.addFileArg(l.getEmittedBin());
- copy.addArg(b.pathJoin(&.{ dir, "..", "lib", "pardes", "addons", b.fmt("{s}.so", .{name}) }));
- copy.has_side_effects = true;
+ if (home_addons) |dir| {
+ const copy = b.addUpdateSourceFiles();
+ copy.addCopyFileToSource(l.getEmittedBin(), b.pathJoin(&.{ dir, b.fmt("{s}.so", .{name}) }));
step.dependOn(&copy.step);
}
}
@@ -1645,7 +1673,7 @@ pub fn build(b: *std.Build) void {
for ([_]*std.Build.Module{ snake_mod, life_mod, image_mod }) |m| addon_test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = m })).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" }, .{ life_lib, "addons/life/life" }, .{ pdf_addon, "addons/pdf/pdf" } };
+ const libs = [_]struct { ?*std.Build.Step.Compile, []const u8 }{ .{ fake_addon_lib.?, "addons/fake/fake" }, .{ snake_lib, "addons/snake/snake" }, .{ snake_shader_lib, "addons/snake_shader/snake_shader" }, .{ life_lib, "addons/life/life" }, .{ pdf_addon, "addons/pdf/pdf" } };
for (libs) |t| if (t[0]) |lib| {
const run_addon_test = b.addRunArtifact(exe);
run_addon_test.setCwd(b.path("."));