tony / oxwm

refactor: remove `VERSION` constant from main and get it from `build_options` Browse files
- Add `build.zig.zon` with package metadata
- Add `build_options` module that exports `version` from `build.zig.zon`
emzywastaken committed 2026-02-23 parent 69e7de0 commit d70d713eb8b04554fe306485124008f82c124b66
Showing 3 changed files with 20 additions and 3 deletions. UnifiedSplit
+5 −0 build.zig
@@ -1,4 +1,5 @@
1 const std = @import("std"); 1 const std = @import("std");
2 +const zon = @import("build.zig.zon");
2 3
3 pub fn build(b: *std.Build) void { 4 pub fn build(b: *std.Build) void {
4 const target = b.standardTargetOptions(.{}); 5 const target = b.standardTargetOptions(.{});
@@ -13,6 +14,10 @@ pub fn build(b: *std.Build) void {
13 }), 14 }),
14 }); 15 });
15 16
17 + const exe_options = b.addOptions();
18 + exe_options.addOption([]const u8, "version", zon.version);
19 + exe.root_module.addOptions("build_options", exe_options);
20 +
16 exe.root_module.addAnonymousImport("templates/config.lua", .{ 21 exe.root_module.addAnonymousImport("templates/config.lua", .{
17 .root_source_file = b.path("templates/config.lua"), 22 .root_source_file = b.path("templates/config.lua"),
18 }); 23 });
+13 −0 build.zig.zon new file mode 100644
@@ -0,0 +1,13 @@
1 +.{
2 + .name = .oxwm,
3 + .version = "0.11.2",
4 + .fingerprint = 0x4b9ef3753914924d, // Changing this has security and trust implications.
5 + .minimum_zig_version = "0.15.2",
6 + .paths = .{
7 + "build.zig",
8 + "build.zig.zon",
9 + "src",
10 + "LICENSE",
11 + "README.md",
12 + },
13 +}
+2 −3 src/main.zig
@@ -1,4 +1,5 @@
1 const std = @import("std"); 1 const std = @import("std");
2 +const build_options = @import("build_options");
2 3
3 const actions = @import("wm/actions.zig"); 4 const actions = @import("wm/actions.zig");
4 const handlers = @import("wm/handlers.zig"); 5 const handlers = @import("wm/handlers.zig");
@@ -8,8 +9,6 @@ const lua = @import("config/lua.zig");
8 9
9 const WindowManager = window_manager.WindowManager; 10 const WindowManager = window_manager.WindowManager;
10 11
11 -const VERSION = "v0.11.2";
12 -
13 fn print_help() void { 12 fn print_help() void {
14 std.debug.print( 13 std.debug.print(
15 \\oxwm - A window manager 14 \\oxwm - A window manager
@@ -128,7 +127,7 @@ pub fn main() !void {
128 print_help(); 127 print_help();
129 return; 128 return;
130 } else if (std.mem.eql(u8, arg, "-v") or std.mem.eql(u8, arg, "--version")) { 129 } else if (std.mem.eql(u8, arg, "-v") or std.mem.eql(u8, arg, "--version")) {
131 - std.debug.print("{s}\n", .{VERSION}); 130 + std.debug.print("{s}\n", .{build_options.version});
132 return; 131 return;
133 } else if (std.mem.eql(u8, arg, "--init")) { 132 } else if (std.mem.eql(u8, arg, "--init")) {
134 init_config(allocator); 133 init_config(allocator);