11// SPDX-License-Identifier: PMPL-1.0-or-later
22// Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
33//
4- // Session Sentinel FFI — Zig Build Configuration
4+ // Session Sentinel FFI — Zig Build Configuration (Zig 0.15+)
55//
66// Builds the native system tray binary (session-sentinel-tray) which provides
77// KDE/Wayland StatusNotifierItem integration via DBus. Links against libdbus-1
1414// zig build test — run unit tests (no DBus required)
1515// zig build test-integration — run integration tests (DBus session bus required)
1616// zig build install — install to ~/.local/bin/
17- // zig build docs — generate documentation
1817//
1918// Dependencies:
2019// - libdbus-1 (system library, typically from dbus-devel / libdbus-1-dev)
21- // - sd-daemon (optional, for systemd watchdog integration)
20+ // - libsystemd ( for sd_notify watchdog integration)
2221
2322const std = @import ("std" );
2423
2524/// Build configuration for session-sentinel-tray.
2625///
2726/// This produces a single native executable that implements the DBus
2827/// StatusNotifierItem protocol for KDE/Wayland system tray integration.
29- /// The binary communicates with the ReScript monitoring core via DBus IPC.
28+ /// The binary communicates with the monitoring core via DBus IPC.
3029pub fn build (b : * std.Build ) void {
3130 // -------------------------------------------------------------------------
3231 // Target and optimisation
3332 // -------------------------------------------------------------------------
3433
35- const target = b .standardTargetOptions (.{
36- .default_target = .{
37- .cpu_arch = .x86_64 ,
38- .os_tag = .linux ,
39- },
40- });
34+ const target = b .standardTargetOptions (.{});
4135
4236 const optimize = b .standardOptimizeOption (.{});
4337
4438 // -------------------------------------------------------------------------
45- // Main executable: session-sentinel-tray
39+ // Shared module for main source (reused across exe, libs, tests)
4640 // -------------------------------------------------------------------------
4741
48- const exe = b .addExecutable (.{
49- .name = "session-sentinel-tray" ,
42+ const main_mod = b .createModule (.{
5043 .root_source_file = b .path ("src/main.zig" ),
5144 .target = target ,
5245 .optimize = optimize ,
46+ .link_libc = true ,
47+ .pic = true ,
5348 });
49+ main_mod .linkSystemLibrary ("dbus-1" , .{});
50+ main_mod .linkSystemLibrary ("libsystemd" , .{});
5451
55- // Link libdbus-1 (system library for DBus communication)
56- exe .linkSystemLibrary ("dbus-1" );
57-
58- // Link libsystemd for sd_notify watchdog integration (optional at runtime)
59- exe .linkSystemLibrary ("systemd" );
52+ // -------------------------------------------------------------------------
53+ // Main executable: session-sentinel-tray
54+ // -------------------------------------------------------------------------
6055
61- // Link libc (required for libdbus-1 interop)
62- exe .linkLibC ();
56+ const exe = b .addExecutable (.{
57+ .name = "session-sentinel-tray" ,
58+ .root_module = main_mod ,
59+ });
6360
64- // Install the executable
6561 b .installArtifact (exe );
6662
6763 // -------------------------------------------------------------------------
6864 // Shared library (for FFI consumers — Idris2, ReScript via Deno FFI)
6965 // -------------------------------------------------------------------------
7066
71- const lib = b .addSharedLibrary (.{
72- .name = "session_sentinel_tray" ,
67+ const lib_mod = b .createModule (.{
7368 .root_source_file = b .path ("src/main.zig" ),
7469 .target = target ,
7570 .optimize = optimize ,
71+ .link_libc = true ,
7672 });
73+ lib_mod .linkSystemLibrary ("dbus-1" , .{});
74+ lib_mod .linkSystemLibrary ("libsystemd" , .{});
7775
78- lib .version = .{ .major = 0 , .minor = 1 , .patch = 0 };
79- lib .linkSystemLibrary ("dbus-1" );
80- lib .linkSystemLibrary ("systemd" );
81- lib .linkLibC ();
82-
83- b .installArtifact (lib );
84-
85- // -------------------------------------------------------------------------
86- // Static library
87- // -------------------------------------------------------------------------
88-
89- const lib_static = b .addStaticLibrary (.{
76+ const lib = b .addLibrary (.{
77+ .linkage = .dynamic ,
9078 .name = "session_sentinel_tray" ,
91- .root_source_file = b .path ("src/main.zig" ),
92- .target = target ,
93- .optimize = optimize ,
79+ .root_module = lib_mod ,
80+ .version = .{ .major = 0 , .minor = 1 , .patch = 0 },
9481 });
9582
96- lib_static .linkSystemLibrary ("dbus-1" );
97- lib_static .linkSystemLibrary ("systemd" );
98- lib_static .linkLibC ();
99-
100- b .installArtifact (lib_static );
83+ b .installArtifact (lib );
10184
10285 // -------------------------------------------------------------------------
10386 // Unit tests (no DBus session bus required)
10487 // -------------------------------------------------------------------------
10588
106- const unit_tests = b .addTest (.{
89+ const test_mod = b .createModule (.{
10790 .root_source_file = b .path ("src/main.zig" ),
10891 .target = target ,
10992 .optimize = optimize ,
93+ .link_libc = true ,
11094 });
95+ test_mod .linkSystemLibrary ("dbus-1" , .{});
96+ test_mod .linkSystemLibrary ("systemd" , .{});
11197
112- unit_tests . linkSystemLibrary ( "dbus-1" );
113- unit_tests . linkSystemLibrary ( "systemd" );
114- unit_tests . linkLibC ( );
98+ const unit_tests = b . addTest (.{
99+ . root_module = test_mod ,
100+ } );
115101
116102 const run_unit_tests = b .addRunArtifact (unit_tests );
117103
@@ -122,15 +108,18 @@ pub fn build(b: *std.Build) void {
122108 // Integration tests (require DBus session bus)
123109 // -------------------------------------------------------------------------
124110
125- const integration_tests = b .addTest (.{
111+ const integ_mod = b .createModule (.{
126112 .root_source_file = b .path ("test/integration_test.zig" ),
127113 .target = target ,
128114 .optimize = optimize ,
115+ .link_libc = true ,
129116 });
117+ integ_mod .linkSystemLibrary ("dbus-1" , .{});
118+ integ_mod .linkSystemLibrary ("systemd" , .{});
130119
131- integration_tests . linkSystemLibrary ( "dbus-1" );
132- integration_tests . linkSystemLibrary ( "systemd" );
133- integration_tests . linkLibC ( );
120+ const integration_tests = b . addTest (.{
121+ . root_module = integ_mod ,
122+ } );
134123
135124 const run_integration_tests = b .addRunArtifact (integration_tests );
136125
@@ -141,10 +130,6 @@ pub fn build(b: *std.Build) void {
141130 // Install to ~/.local/bin/ (user-local install)
142131 // -------------------------------------------------------------------------
143132
144- const install_local = b .addInstallArtifact (exe , .{
145- .dest_dir = .{ .override = .{ .custom = "" } },
146- });
147-
148133 const home = std .posix .getenv ("HOME" ) orelse "/home/hyper" ;
149134 const local_bin = std .fmt .allocPrint (b .allocator , "{s}/.local/bin" , .{home }) catch @panic ("OOM" );
150135
@@ -155,27 +140,5 @@ pub fn build(b: *std.Build) void {
155140 });
156141 copy_cmd .addArtifactArg (exe );
157142 copy_cmd .addArg (local_bin );
158- copy_cmd .step .dependOn (& install_local .step );
159143 install_step .dependOn (& copy_cmd .step );
160-
161- // -------------------------------------------------------------------------
162- // Documentation generation
163- // -------------------------------------------------------------------------
164-
165- const docs = b .addTest (.{
166- .root_source_file = b .path ("src/main.zig" ),
167- .target = target ,
168- .optimize = .Debug ,
169- });
170-
171- docs .linkSystemLibrary ("dbus-1" );
172- docs .linkSystemLibrary ("systemd" );
173- docs .linkLibC ();
174-
175- const docs_step = b .step ("docs" , "Generate documentation from source" );
176- docs_step .dependOn (& b .addInstallDirectory (.{
177- .source_dir = docs .getEmittedDocs (),
178- .install_dir = .prefix ,
179- .install_subdir = "docs" ,
180- }).step );
181144}
0 commit comments