tony / oxwm

Branch: a8a8323
Switch branches/tags
master
tonybanters Added a couple of functions to lua parser for zig. a8a8323 2026-02-02
76 lines · 2.7 KB Raw Blame History
1 const std = @import("std");
2
3 pub fn build(b: *std.Build) void {
4 const target = b.standardTargetOptions(.{});
5 const optimize = b.standardOptimizeOption(.{});
6
7 const exe = b.addExecutable(.{
8 .name = "oxwm",
9 .root_module = b.createModule(.{
10 .root_source_file = b.path("src/main.zig"),
11 .target = target,
12 .optimize = optimize,
13 }),
14 });
15
16 exe.linkSystemLibrary("lua");
17 exe.linkSystemLibrary("X11");
18 exe.linkSystemLibrary("Xinerama");
19 exe.linkSystemLibrary("Xft");
20 exe.linkSystemLibrary("fontconfig");
21 exe.linkLibC();
22
23 b.installArtifact(exe);
24
25 const run_step = b.step("run", "Run oxwm");
26 const run_cmd = b.addRunArtifact(exe);
27 run_step.dependOn(&run_cmd.step);
28 run_cmd.step.dependOn(b.getInstallStep());
29 if (b.args) |args| {
30 run_cmd.addArgs(args);
31 }
32
33 const test_step = b.step("test", "Run unit tests");
34 const unit_tests = b.addTest(.{
35 .root_module = b.createModule(.{
36 .root_source_file = b.path("tests/main_tests.zig"),
37 .target = target,
38 .optimize = optimize,
39 }),
40 });
41 test_step.dependOn(&b.addRunArtifact(unit_tests).step);
42
43 const xephyr_step = b.step("xephyr", "Run in Xephyr (1280x800 on :2)");
44 xephyr_step.dependOn(&add_xephyr_run(b, exe, false).step);
45
46 const xephyr_multi_step = b.step("xephyr-multi", "Run in Xephyr multi-monitor on :2");
47 xephyr_multi_step.dependOn(&add_xephyr_run(b, exe, true).step);
48
49 const multimon_step = b.step("multimon", "Alias for xephyr-multi");
50 multimon_step.dependOn(&add_xephyr_run(b, exe, true).step);
51
52 const kill_step = b.step("kill", "Kill Xephyr and oxwm");
53 kill_step.dependOn(&b.addSystemCommand(&.{ "sh", "-c", "pkill -9 Xephyr || true; pkill -9 oxwm || true" }).step);
54
55 const fmt_step = b.step("fmt", "Format source files");
56 fmt_step.dependOn(&b.addFmt(.{ .paths = &.{"src/"} }).step);
57
58 const clean_step = b.step("clean", "Remove build artifacts");
59 clean_step.dependOn(&b.addSystemCommand(&.{ "rm", "-rf", "zig-out", ".zig-cache" }).step);
60 }
61
62 fn add_xephyr_run(b: *std.Build, exe: *std.Build.Step.Compile, multimon: bool) *std.Build.Step.Run {
63 const kill_cmd = if (multimon)
64 "pkill -9 Xephyr || true; Xephyr +xinerama -glamor -screen 640x480 -screen 640x480 :2 & sleep 1"
65 else
66 "pkill -9 Xephyr || true; Xephyr -screen 1280x800 :2 & sleep 1";
67
68 const setup = b.addSystemCommand(&.{ "sh", "-c", kill_cmd });
69
70 const run_wm = b.addRunArtifact(exe);
71 run_wm.step.dependOn(&setup.step);
72 run_wm.setEnvironmentVariable("DISPLAY", ":2");
73 run_wm.addArgs(&.{ "-c", "resources/test-config.lua" });
74
75 return run_wm;
76 }