tony / oxwm

Branch: 9de572d
Switch branches/tags
master
tonybanters added use_lld = false to zig tests to be consistent with main build, for known linker issueon legacy distros f64308d 2026-02-19
154 lines · 5.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.root_module.addAnonymousImport("templates/config.lua", .{
17 .root_source_file = b.path("templates/config.lua"),
18 });
19
20 exe.use_lld = false;
21
22 exe.linkSystemLibrary("lua5.4");
23 exe.linkSystemLibrary("X11");
24 exe.linkSystemLibrary("Xinerama");
25 exe.linkSystemLibrary("Xft");
26 exe.linkSystemLibrary("fontconfig");
27 exe.linkLibC();
28
29 b.installArtifact(exe);
30
31 const run_step = b.step("run", "Run oxwm");
32 const run_cmd = b.addRunArtifact(exe);
33 run_step.dependOn(&run_cmd.step);
34 run_cmd.step.dependOn(b.getInstallStep());
35 if (b.args) |args| {
36 run_cmd.addArgs(args);
37 }
38
39 const test_step = b.step("test", "Run unit tests");
40 const unit_tests = b.addTest(.{
41 .root_module = b.createModule(.{
42 .root_source_file = b.path("tests/main_tests.zig"),
43 .target = target,
44 .optimize = optimize,
45 }),
46 });
47 unit_tests.use_lld = false;
48 test_step.dependOn(&b.addRunArtifact(unit_tests).step);
49
50 const src_main_unit_tests = b.addTest(.{
51 .root_module = b.createModule(.{
52 .root_source_file = b.path("src/main.zig"),
53 .target = target,
54 .optimize = optimize,
55 }),
56 });
57 src_main_unit_tests.use_lld = false;
58 src_main_unit_tests.linkSystemLibrary("lua5.4");
59 src_main_unit_tests.linkSystemLibrary("X11");
60 src_main_unit_tests.linkSystemLibrary("Xinerama");
61 src_main_unit_tests.linkSystemLibrary("Xft");
62 src_main_unit_tests.linkSystemLibrary("fontconfig");
63 src_main_unit_tests.linkLibC();
64 test_step.dependOn(&b.addRunArtifact(src_main_unit_tests).step);
65
66 const lua_config_tests = b.addTest(.{
67 .root_module = b.createModule(.{
68 .root_source_file = b.path("tests/lua_config_tests.zig"),
69 .target = target,
70 .optimize = optimize,
71 }),
72 });
73 lua_config_tests.use_lld = false;
74 lua_config_tests.root_module.addImport("lua", b.createModule(.{
75 .root_source_file = b.path("src/config/lua.zig"),
76 .target = target,
77 .optimize = optimize,
78 }));
79 lua_config_tests.linkSystemLibrary("lua5.4");
80 lua_config_tests.linkLibC();
81 test_step.dependOn(&b.addRunArtifact(lua_config_tests).step);
82
83 const xephyr_step = b.step("xephyr", "Run in Xephyr (1280x800 on :2)");
84 xephyr_step.dependOn(&add_xephyr_run(b, exe, false).step);
85
86 const xephyr_multi_step = b.step("xephyr-multi", "Run in Xephyr multi-monitor on :2");
87 xephyr_multi_step.dependOn(&add_xephyr_run(b, exe, true).step);
88
89 const multimon_step = b.step("multimon", "Alias for xephyr-multi");
90 multimon_step.dependOn(&add_xephyr_run(b, exe, true).step);
91
92 const xwayland_step = b.step("xwayland", "Run in Xwayland on :2");
93 xwayland_step.dependOn(&add_xwayland_run(b, exe).step);
94
95 const kill_step = b.step("kill", "Kill Xephyr and oxwm");
96 kill_step.dependOn(&b.addSystemCommand(&.{ "sh", "-c", "pkill -9 Xephyr || true; pkill -9 oxwm || true" }).step);
97
98 const fmt_step = b.step("fmt", "Format source files");
99 fmt_step.dependOn(&b.addFmt(.{ .paths = &.{"src/"} }).step);
100
101 const clean_step = b.step("clean", "Remove build artifacts");
102 clean_step.dependOn(&b.addSystemCommand(&.{ "rm", "-rf", "zig-out", ".zig-cache" }).step);
103
104 const install_step = b.step("install-system", "Install oxwm system-wide (requires sudo)");
105 install_step.dependOn(b.getInstallStep());
106 install_step.dependOn(&b.addSystemCommand(&.{
107 "sudo", "sh", "-c",
108 "cp zig-out/bin/oxwm /usr/bin/oxwm && " ++
109 "chmod +x /usr/bin/oxwm && " ++
110 "mkdir -p /usr/share/xsessions && " ++
111 "cp resources/oxwm.desktop /usr/share/xsessions/oxwm.desktop && " ++
112 "mkdir -p /usr/share/man/man1 && " ++
113 "cp resources/oxwm.1 /usr/share/man/man1/oxwm.1 && " ++
114 "mkdir -p /usr/share/oxwm && " ++
115 "cp templates/oxwm.lua /usr/share/oxwm/oxwm.lua && " ++
116 "echo 'oxwm installed to /usr/bin/oxwm'",
117 }).step);
118
119 const uninstall_step = b.step("uninstall-system", "Uninstall oxwm from system");
120 uninstall_step.dependOn(&b.addSystemCommand(&.{
121 "sudo", "sh", "-c",
122 "rm -f /usr/bin/oxwm /usr/share/xsessions/oxwm.desktop /usr/share/man/man1/oxwm.1 && " ++
123 "rm -rf /usr/share/oxwm && " ++
124 "echo 'oxwm uninstalled (config at ~/.config/oxwm preserved)'",
125 }).step);
126 }
127
128 fn add_xephyr_run(b: *std.Build, exe: *std.Build.Step.Compile, multimon: bool) *std.Build.Step.Run {
129 const kill_cmd = if (multimon)
130 "pkill -9 Xephyr || true; Xephyr +xinerama -glamor -screen 640x480 -screen 640x480 :2 & sleep 1"
131 else
132 "pkill -9 Xephyr || true; Xephyr -screen 1280x800 :2 & sleep 1";
133
134 const setup = b.addSystemCommand(&.{ "sh", "-c", kill_cmd });
135
136 const run_wm = b.addRunArtifact(exe);
137 run_wm.step.dependOn(&setup.step);
138 run_wm.setEnvironmentVariable("DISPLAY", ":2");
139 run_wm.addArgs(&.{ "-c", "resources/test-config.lua" });
140
141 return run_wm;
142 }
143
144 fn add_xwayland_run(b: *std.Build, exe: *std.Build.Step.Compile) *std.Build.Step.Run {
145 const cmd = "Xwayland -retro -noreset :2 & sleep 1";
146
147 const setup = b.addSystemCommand(&.{ "sh", "-c", cmd });
148
149 const run_wm = b.addRunArtifact(exe);
150 run_wm.step.dependOn(&setup.step);
151 run_wm.setEnvironmentVariable("DISPLAY", ":2");
152
153 return run_wm;
154 }