git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commit074e6e2e2975e158fa2c1e77e11f37f6d96d0ee2
parent43ea6757b1
authorIsaac Freund <[email protected]>
date2020-04-12 13:54
Eliminate some code duplication

 build.zig | 36 ++++++++++++++----------------------
 1 file changed, 14 insertions(+), 22 deletions(-)

diff --git a/build.zig b/build.zig
index 4330349..6cd3f88 100644
--- a/build.zig
+++ b/build.zig
@@ -16,18 +16,7 @@ pub fn build(b: *std.build.Builder) !void {
     const exe = b.addExecutable("river", "src/main.zig");
     exe.setTarget(target);
     exe.setBuildMode(mode);
-
-    exe.step.dependOn(&scan_protocols.step);
-    exe.addIncludeDir("protocol");
-
-    exe.addCSourceFile("include/render.c", &[_][]const u8{"-std=c99"});
-    exe.addIncludeDir(".");
-
-    exe.linkLibC();
-    exe.linkSystemLibrary("wayland-server");
-    exe.linkSystemLibrary("wlroots");
-    exe.linkSystemLibrary("xkbcommon");
-
+    addDeps(exe, &scan_protocols.step);
     exe.install();
 
     const run_cmd = exe.run();
@@ -39,20 +28,23 @@ pub fn build(b: *std.build.Builder) !void {
     const test_exe = b.addTest("src/test_main.zig");
     test_exe.setTarget(target);
     test_exe.setBuildMode(mode);
+    addDeps(test_exe, &scan_protocols.step);
 
-    test_exe.step.dependOn(&scan_protocols.step);
-    test_exe.addIncludeDir("protocol");
+    const test_step = b.step("test", "Run the tests");
+    test_step.dependOn(&test_exe.step);
+}
 
-    test_exe.addCSourceFile("include/render.c", &[_][]const u8{"-std=c99"});
-    test_exe.addIncludeDir(".");
+fn addDeps(exe: *std.build.LibExeObjStep, protocol_step: *std.build.Step) void {
+    exe.step.dependOn(protocol_step);
+    exe.addIncludeDir("protocol");
 
-    test_exe.linkLibC();
-    test_exe.linkSystemLibrary("wayland-server");
-    test_exe.linkSystemLibrary("wlroots");
-    test_exe.linkSystemLibrary("xkbcommon");
+    exe.addCSourceFile("include/render.c", &[_][]const u8{"-std=c99"});
+    exe.addIncludeDir(".");
 
-    const test_step = b.step("test", "Run the tests");
-    test_step.dependOn(&test_exe.step);
+    exe.linkLibC();
+    exe.linkSystemLibrary("wayland-server");
+    exe.linkSystemLibrary("wlroots");
+    exe.linkSystemLibrary("xkbcommon");
 }
 
 const ScanProtocolsStep = struct {