| 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("lua5.4"); |
| 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 src_main_unit_tests = b.addTest(.{ |
| 44 | .root_module = b.createModule(.{ |
| 45 | .root_source_file = b.path("src/main.zig"), |
| 46 | .target = target, |
| 47 | .optimize = optimize, |
| 48 | }), |
| 49 | }); |
| 50 | src_main_unit_tests.linkLibC(); |
| 51 | test_step.dependOn(&b.addRunArtifact(src_main_unit_tests).step); |
| 52 | |
| 53 | const lua_config_tests = b.addTest(.{ |
| 54 | .root_module = b.createModule(.{ |
| 55 | .root_source_file = b.path("tests/lua_config_tests.zig"), |
| 56 | .target = target, |
| 57 | .optimize = optimize, |
| 58 | }), |
| 59 | }); |
| 60 | lua_config_tests.root_module.addImport("lua", b.createModule(.{ |
| 61 | .root_source_file = b.path("src/config/lua.zig"), |
| 62 | .target = target, |
| 63 | .optimize = optimize, |
| 64 | })); |
| 65 | lua_config_tests.linkSystemLibrary("lua5.4"); |
| 66 | lua_config_tests.linkLibC(); |
| 67 | test_step.dependOn(&b.addRunArtifact(lua_config_tests).step); |
| 68 | |
| 69 | const xephyr_step = b.step("xephyr", "Run in Xephyr (1280x800 on :2)"); |
| 70 | xephyr_step.dependOn(&add_xephyr_run(b, exe, false).step); |
| 71 | |
| 72 | const xephyr_multi_step = b.step("xephyr-multi", "Run in Xephyr multi-monitor on :2"); |
| 73 | xephyr_multi_step.dependOn(&add_xephyr_run(b, exe, true).step); |
| 74 | |
| 75 | const multimon_step = b.step("multimon", "Alias for xephyr-multi"); |
| 76 | multimon_step.dependOn(&add_xephyr_run(b, exe, true).step); |
| 77 | |
| 78 | const xwayland_step = b.step("xwayland", "Run in Xwayland on :2"); |
| 79 | xwayland_step.dependOn(&add_xwayland_run(b, exe).step); |
| 80 | |
| 81 | const kill_step = b.step("kill", "Kill Xephyr and oxwm"); |
| 82 | kill_step.dependOn(&b.addSystemCommand(&.{ "sh", "-c", "pkill -9 Xephyr || true; pkill -9 oxwm || true" }).step); |
| 83 | |
| 84 | const fmt_step = b.step("fmt", "Format source files"); |
| 85 | fmt_step.dependOn(&b.addFmt(.{ .paths = &.{"src/"} }).step); |
| 86 | |
| 87 | const clean_step = b.step("clean", "Remove build artifacts"); |
| 88 | clean_step.dependOn(&b.addSystemCommand(&.{ "rm", "-rf", "zig-out", ".zig-cache" }).step); |
| 89 | } |
| 90 | |
| 91 | fn add_xephyr_run(b: *std.Build, exe: *std.Build.Step.Compile, multimon: bool) *std.Build.Step.Run { |
| 92 | const kill_cmd = if (multimon) |
| 93 | "pkill -9 Xephyr || true; Xephyr +xinerama -glamor -screen 640x480 -screen 640x480 :2 & sleep 1" |
| 94 | else |
| 95 | "pkill -9 Xephyr || true; Xephyr -screen 1280x800 :2 & sleep 1"; |
| 96 | |
| 97 | const setup = b.addSystemCommand(&.{ "sh", "-c", kill_cmd }); |
| 98 | |
| 99 | const run_wm = b.addRunArtifact(exe); |
| 100 | run_wm.step.dependOn(&setup.step); |
| 101 | run_wm.setEnvironmentVariable("DISPLAY", ":2"); |
| 102 | run_wm.addArgs(&.{ "-c", "resources/test-config.lua" }); |
| 103 | |
| 104 | return run_wm; |
| 105 | } |
| 106 | |
| 107 | fn add_xwayland_run(b: *std.Build, exe: *std.Build.Step.Compile) *std.Build.Step.Run { |
| 108 | const cmd = "Xwayland -retro -noreset :2 & sleep 1"; |
| 109 | |
| 110 | const setup = b.addSystemCommand(&.{ "sh", "-c", cmd }); |
| 111 | |
| 112 | const run_wm = b.addRunArtifact(exe); |
| 113 | run_wm.step.dependOn(&setup.step); |
| 114 | run_wm.setEnvironmentVariable("DISPLAY", ":2"); |
| 115 | |
| 116 | return run_wm; |
| 117 | } |