From 7482ff17e80edbb91896f9afe21b49da99710a5e Mon Sep 17 00:00:00 2001 From: jinzhongjia Date: Thu, 4 Jul 2024 08:42:59 +0800 Subject: [PATCH] 12 compatible --- build.zig | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/build.zig b/build.zig index b02d2c0..69ea404 100644 --- a/build.zig +++ b/build.zig @@ -1,10 +1,24 @@ const std = @import("std"); +const builtin = @import("builtin"); + +const min_zig_string = "0.12.0"; +const current_zig = builtin.zig_version; + +// Implementing zig version detection through compile time +comptime { + const min_zig = std.SemanticVersion.parse(min_zig_string) catch unreachable; + if (current_zig.order(min_zig) == .lt) { + @compileError(std.fmt.comptimePrint("Your Zig version v{} does not meet the minimum build requirement of v{}", .{ current_zig, min_zig })); + } +} const ly_version = std.SemanticVersion{ .major = 1, .minor = 1, .patch = 0 }; var dest_directory: []const u8 = undefined; var data_directory: []const u8 = undefined; var exe_name: []const u8 = undefined; +const ProgressNode = if (current_zig.minor == 12) *std.Progress.Node else std.Progress.Node; + pub fn build(b: *std.Build) !void { dest_directory = b.option([]const u8, "dest_directory", "Specify a destination directory for installation") orelse ""; data_directory = b.option([]const u8, "data_directory", "Specify a default data directory (default is /etc/ly). This path gets embedded into the binary") orelse "/etc/ly"; @@ -94,7 +108,7 @@ pub fn build(b: *std.Build) !void { pub fn ExeInstaller(install_conf: bool) type { return struct { - pub fn make(step: *std.Build.Step, _: std.Progress.Node) anyerror!void { + pub fn make(step: *std.Build.Step, _: ProgressNode) !void { try install_ly(step.owner.allocator, install_conf); } }; @@ -107,7 +121,7 @@ const InitSystem = enum { }; pub fn ServiceInstaller(comptime init_system: InitSystem) type { return struct { - pub fn make(step: *std.Build.Step, _: std.Progress.Node) !void { + pub fn make(step: *std.Build.Step, _: ProgressNode) !void { const allocator = step.owner.allocator; switch (init_system) { .Openrc => { @@ -215,7 +229,7 @@ fn install_ly(allocator: std.mem.Allocator, install_config: bool) !void { } } -pub fn uninstallall(step: *std.Build.Step, _: std.Progress.Node) !void { +pub fn uninstallall(step: *std.Build.Step, _: ProgressNode) !void { try std.fs.cwd().deleteTree(data_directory); const allocator = step.owner.allocator;