mirror of
https://github.com/fairyglade/ly.git
synced 2026-05-06 07:10:36 +00:00
Update to Zig 0.16.0 (#962)
Signed-off-by: AnErrupTion <anerruption@disroot.org> ## What are the changes about? Ports the code base to Zig 0.16.0. ## What existing issue does this resolve? N/A ## Pre-requisites - [x] I have tested & confirmed the changes work locally - [x] I have run `zig fmt` throughout my changes Reviewed-on: https://codeberg.org/fairyglade/ly/pulls/962
This commit is contained in:
271
build.zig
271
build.zig
@@ -12,7 +12,7 @@ const InitSystem = enum {
|
||||
freebsd,
|
||||
};
|
||||
|
||||
const min_zig_string = "0.15.0";
|
||||
const min_zig_string = "0.16.0";
|
||||
const current_zig = builtin.zig_version;
|
||||
|
||||
// Implementing zig version detection through compile time
|
||||
@@ -67,8 +67,8 @@ pub fn build(b: *std.Build) !void {
|
||||
.root_source_file = b.path("src/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.link_libc = true,
|
||||
}),
|
||||
// Here until the native backend matures in terms of performance
|
||||
.use_llvm = true,
|
||||
});
|
||||
|
||||
@@ -80,9 +80,8 @@ pub fn build(b: *std.Build) !void {
|
||||
const clap = b.dependency("clap", .{ .target = target, .optimize = optimize });
|
||||
exe.root_module.addImport("clap", clap.module("clap"));
|
||||
|
||||
exe.linkSystemLibrary("pam");
|
||||
if (enable_x11_support) exe.linkSystemLibrary("xcb");
|
||||
exe.linkLibC();
|
||||
exe.root_module.linkSystemLibrary("pam", .{});
|
||||
if (enable_x11_support) exe.root_module.linkSystemLibrary("xcb", .{});
|
||||
|
||||
b.installArtifact(exe);
|
||||
|
||||
@@ -113,6 +112,8 @@ pub fn build(b: *std.Build) !void {
|
||||
pub fn Installer(install_config: bool) type {
|
||||
return struct {
|
||||
pub fn make(step: *std.Build.Step, _: std.Build.Step.MakeOptions) !void {
|
||||
var threaded: std.Io.Threaded = .init_single_threaded;
|
||||
const io = threaded.io();
|
||||
const allocator = step.owner.allocator;
|
||||
|
||||
var patch_map = PatchMap.init(allocator);
|
||||
@@ -127,75 +128,75 @@ pub fn Installer(install_config: bool) type {
|
||||
// instead to shutdown the system.
|
||||
try patch_map.put("$PLATFORM_SHUTDOWN_ARG", if (init_system == .freebsd) "-p" else "-a");
|
||||
|
||||
try install_ly(allocator, patch_map, install_config);
|
||||
try install_service(allocator, patch_map);
|
||||
try install_ly(allocator, io, patch_map, install_config);
|
||||
try install_service(allocator, io, patch_map);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fn install_ly(allocator: std.mem.Allocator, patch_map: PatchMap, install_config: bool) !void {
|
||||
const ly_config_directory = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/ly" });
|
||||
fn install_ly(allocator: std.mem.Allocator, io: std.Io, patch_map: PatchMap, install_config: bool) !void {
|
||||
const ly_config_directory = try std.Io.Dir.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/ly" });
|
||||
|
||||
std.fs.cwd().makePath(ly_config_directory) catch {
|
||||
std.Io.Dir.cwd().createDirPath(io, ly_config_directory) catch {
|
||||
std.debug.print("warn: {s} already exists as a directory.\n", .{ly_config_directory});
|
||||
};
|
||||
|
||||
const ly_custom_sessions_directory = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/ly/custom-sessions" });
|
||||
const ly_custom_sessions_directory = try std.Io.Dir.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/ly/custom-sessions" });
|
||||
|
||||
std.fs.cwd().makePath(ly_custom_sessions_directory) catch {
|
||||
std.Io.Dir.cwd().createDirPath(io, ly_custom_sessions_directory) catch {
|
||||
std.debug.print("warn: {s} already exists as a directory.\n", .{ly_custom_sessions_directory});
|
||||
};
|
||||
|
||||
const ly_lang_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/ly/lang" });
|
||||
std.fs.cwd().makePath(ly_lang_path) catch {
|
||||
const ly_lang_path = try std.Io.Dir.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/ly/lang" });
|
||||
std.Io.Dir.cwd().createDirPath(io, ly_lang_path) catch {
|
||||
std.debug.print("warn: {s} already exists as a directory.\n", .{ly_lang_path});
|
||||
};
|
||||
|
||||
{
|
||||
const exe_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, prefix_directory, "/bin" });
|
||||
std.fs.cwd().makePath(exe_path) catch {
|
||||
const exe_path = try std.Io.Dir.path.join(allocator, &[_][]const u8{ dest_directory, prefix_directory, "/bin" });
|
||||
std.Io.Dir.cwd().createDirPath(io, exe_path) catch {
|
||||
if (!std.mem.eql(u8, dest_directory, "")) {
|
||||
std.debug.print("warn: {s} already exists as a directory.\n", .{exe_path});
|
||||
}
|
||||
};
|
||||
|
||||
var executable_dir = std.fs.cwd().openDir(exe_path, .{}) catch unreachable;
|
||||
defer executable_dir.close();
|
||||
var executable_dir = std.Io.Dir.cwd().openDir(io, exe_path, .{}) catch unreachable;
|
||||
defer executable_dir.close(io);
|
||||
|
||||
try installFile("zig-out/bin/ly", executable_dir, exe_path, executable_name, .{});
|
||||
try installFile(io, "zig-out/bin/ly", executable_dir, exe_path, executable_name, .{});
|
||||
}
|
||||
|
||||
{
|
||||
var config_dir = std.fs.cwd().openDir(ly_config_directory, .{}) catch unreachable;
|
||||
defer config_dir.close();
|
||||
var config_dir = std.Io.Dir.cwd().openDir(io, ly_config_directory, .{}) catch unreachable;
|
||||
defer config_dir.close(io);
|
||||
|
||||
if (install_config) {
|
||||
const patched_config = try patchFile(allocator, "res/config.ini", patch_map);
|
||||
try installText(patched_config, config_dir, ly_config_directory, "config.ini", .{});
|
||||
const patched_config = try patchFile(allocator, io, "res/config.ini", patch_map);
|
||||
try installText(io, patched_config, config_dir, ly_config_directory, "config.ini", .{});
|
||||
|
||||
try installFile("res/startup.sh", config_dir, ly_config_directory, "startup.sh", .{ .override_mode = 0o755 });
|
||||
try installFile(io, "res/startup.sh", config_dir, ly_config_directory, "startup.sh", .{ .permissions = .fromMode(0o755) });
|
||||
}
|
||||
|
||||
const patched_example_config = try patchFile(allocator, "res/config.ini", patch_map);
|
||||
try installText(patched_example_config, config_dir, ly_config_directory, "config.ini.example", .{});
|
||||
const patched_example_config = try patchFile(allocator, io, "res/config.ini", patch_map);
|
||||
try installText(io, patched_example_config, config_dir, ly_config_directory, "config.ini.example", .{});
|
||||
|
||||
const patched_setup = try patchFile(allocator, "res/setup.sh", patch_map);
|
||||
try installText(patched_setup, config_dir, ly_config_directory, "setup.sh", .{ .mode = 0o755 });
|
||||
const patched_setup = try patchFile(allocator, io, "res/setup.sh", patch_map);
|
||||
try installText(io, patched_setup, config_dir, ly_config_directory, "setup.sh", .{ .permissions = .fromMode(0o755) });
|
||||
|
||||
try installFile("res/example.dur", config_dir, ly_config_directory, "example.dur", .{ .override_mode = 0o755 });
|
||||
try installFile(io, "res/example.dur", config_dir, ly_config_directory, "example.dur", .{ .permissions = .fromMode(0o755) });
|
||||
}
|
||||
|
||||
{
|
||||
var custom_sessions_dir = std.fs.cwd().openDir(ly_custom_sessions_directory, .{}) catch unreachable;
|
||||
defer custom_sessions_dir.close();
|
||||
var custom_sessions_dir = std.Io.Dir.cwd().openDir(io, ly_custom_sessions_directory, .{}) catch unreachable;
|
||||
defer custom_sessions_dir.close(io);
|
||||
|
||||
const patched_readme = try patchFile(allocator, "res/custom-sessions/README", patch_map);
|
||||
try installText(patched_readme, custom_sessions_dir, ly_custom_sessions_directory, "README", .{});
|
||||
const patched_readme = try patchFile(allocator, io, "res/custom-sessions/README", patch_map);
|
||||
try installText(io, patched_readme, custom_sessions_dir, ly_custom_sessions_directory, "README", .{});
|
||||
}
|
||||
|
||||
{
|
||||
var lang_dir = std.fs.cwd().openDir(ly_lang_path, .{}) catch unreachable;
|
||||
defer lang_dir.close();
|
||||
var lang_dir = std.Io.Dir.cwd().openDir(io, ly_lang_path, .{}) catch unreachable;
|
||||
defer lang_dir.close(io);
|
||||
|
||||
const languages = [_][]const u8{
|
||||
"ar.ini",
|
||||
@@ -221,66 +222,66 @@ fn install_ly(allocator: std.mem.Allocator, patch_map: PatchMap, install_config:
|
||||
};
|
||||
|
||||
inline for (languages) |language| {
|
||||
try installFile("res/lang/" ++ language, lang_dir, ly_lang_path, language, .{});
|
||||
try installFile(io, "res/lang/" ++ language, lang_dir, ly_lang_path, language, .{});
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const pam_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/pam.d" });
|
||||
std.fs.cwd().makePath(pam_path) catch {
|
||||
const pam_path = try std.Io.Dir.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/pam.d" });
|
||||
std.Io.Dir.cwd().createDirPath(io, pam_path) catch {
|
||||
if (!std.mem.eql(u8, dest_directory, "")) {
|
||||
std.debug.print("warn: {s} already exists as a directory.\n", .{pam_path});
|
||||
}
|
||||
};
|
||||
|
||||
var pam_dir = std.fs.cwd().openDir(pam_path, .{}) catch unreachable;
|
||||
defer pam_dir.close();
|
||||
var pam_dir = std.Io.Dir.cwd().openDir(io, pam_path, .{}) catch unreachable;
|
||||
defer pam_dir.close(io);
|
||||
|
||||
try installFile(if (init_system == .freebsd) "res/pam.d/ly-freebsd" else "res/pam.d/ly-linux", pam_dir, pam_path, "ly", .{ .override_mode = 0o644 });
|
||||
try installFile(if (init_system == .freebsd) "res/pam.d/ly-freebsd-autologin" else "res/pam.d/ly-linux-autologin", pam_dir, pam_path, "ly-autologin", .{ .override_mode = 0o644 });
|
||||
try installFile(io, if (init_system == .freebsd) "res/pam.d/ly-freebsd" else "res/pam.d/ly-linux", pam_dir, pam_path, "ly", .{ .permissions = .fromMode(0o644) });
|
||||
try installFile(io, if (init_system == .freebsd) "res/pam.d/ly-freebsd-autologin" else "res/pam.d/ly-linux-autologin", pam_dir, pam_path, "ly-autologin", .{ .permissions = .fromMode(0o644) });
|
||||
}
|
||||
}
|
||||
|
||||
fn install_service(allocator: std.mem.Allocator, patch_map: PatchMap) !void {
|
||||
fn install_service(allocator: std.mem.Allocator, io: std.Io, patch_map: PatchMap) !void {
|
||||
switch (init_system) {
|
||||
.systemd => {
|
||||
const service_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, prefix_directory, "/lib/systemd/system" });
|
||||
std.fs.cwd().makePath(service_path) catch {};
|
||||
var service_dir = std.fs.cwd().openDir(service_path, .{}) catch unreachable;
|
||||
defer service_dir.close();
|
||||
const service_path = try std.Io.Dir.path.join(allocator, &[_][]const u8{ dest_directory, prefix_directory, "/lib/systemd/system" });
|
||||
std.Io.Dir.cwd().createDirPath(io, service_path) catch {};
|
||||
var service_dir = std.Io.Dir.cwd().openDir(io, service_path, .{}) catch unreachable;
|
||||
defer service_dir.close(io);
|
||||
|
||||
const patched_service = try patchFile(allocator, "res/ly@.service", patch_map);
|
||||
try installText(patched_service, service_dir, service_path, "ly@.service", .{ .mode = 0o644 });
|
||||
const patched_service = try patchFile(allocator, io, "res/ly@.service", patch_map);
|
||||
try installText(io, patched_service, service_dir, service_path, "ly@.service", .{ .permissions = .fromMode(0o644) });
|
||||
|
||||
const patched_kmsconvt_service = try patchFile(allocator, "res/ly-kmsconvt@.service", patch_map);
|
||||
try installText(patched_kmsconvt_service, service_dir, service_path, "ly-kmsconvt@.service", .{ .mode = 0o644 });
|
||||
const patched_kmsconvt_service = try patchFile(allocator, io, "res/ly-kmsconvt@.service", patch_map);
|
||||
try installText(io, patched_kmsconvt_service, service_dir, service_path, "ly-kmsconvt@.service", .{ .permissions = .fromMode(0o644) });
|
||||
},
|
||||
.openrc => {
|
||||
const service_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/init.d" });
|
||||
std.fs.cwd().makePath(service_path) catch {};
|
||||
var service_dir = std.fs.cwd().openDir(service_path, .{}) catch unreachable;
|
||||
defer service_dir.close();
|
||||
const service_path = try std.Io.Dir.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/init.d" });
|
||||
std.Io.Dir.cwd().createDirPath(io, service_path) catch {};
|
||||
var service_dir = std.Io.Dir.cwd().openDir(io, service_path, .{}) catch unreachable;
|
||||
defer service_dir.close(io);
|
||||
|
||||
const patched_service = try patchFile(allocator, "res/ly-openrc", patch_map);
|
||||
try installText(patched_service, service_dir, service_path, executable_name, .{ .mode = 0o755 });
|
||||
const patched_service = try patchFile(allocator, io, "res/ly-openrc", patch_map);
|
||||
try installText(io, patched_service, service_dir, service_path, executable_name, .{ .permissions = .fromMode(0o755) });
|
||||
},
|
||||
.runit => {
|
||||
const service_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/sv/ly" });
|
||||
std.fs.cwd().makePath(service_path) catch {};
|
||||
var service_dir = std.fs.cwd().openDir(service_path, .{}) catch unreachable;
|
||||
defer service_dir.close();
|
||||
const service_path = try std.Io.Dir.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/sv/ly" });
|
||||
std.Io.Dir.cwd().createDirPath(io, service_path) catch {};
|
||||
var service_dir = std.Io.Dir.cwd().openDir(io, service_path, .{}) catch unreachable;
|
||||
defer service_dir.close(io);
|
||||
|
||||
const supervise_path = try std.fs.path.join(allocator, &[_][]const u8{ service_path, "supervise" });
|
||||
const supervise_path = try std.Io.Dir.path.join(allocator, &[_][]const u8{ service_path, "supervise" });
|
||||
|
||||
const patched_conf = try patchFile(allocator, "res/ly-runit-service/conf", patch_map);
|
||||
try installText(patched_conf, service_dir, service_path, "conf", .{});
|
||||
const patched_conf = try patchFile(allocator, io, "res/ly-runit-service/conf", patch_map);
|
||||
try installText(io, patched_conf, service_dir, service_path, "conf", .{});
|
||||
|
||||
try installFile("res/ly-runit-service/finish", service_dir, service_path, "finish", .{ .override_mode = 0o755 });
|
||||
try installFile(io, "res/ly-runit-service/finish", service_dir, service_path, "finish", .{ .permissions = .fromMode(0o755) });
|
||||
|
||||
const patched_run = try patchFile(allocator, "res/ly-runit-service/run", patch_map);
|
||||
try installText(patched_run, service_dir, service_path, "run", .{ .mode = 0o755 });
|
||||
const patched_run = try patchFile(allocator, io, "res/ly-runit-service/run", patch_map);
|
||||
try installText(io, patched_run, service_dir, service_path, "run", .{ .permissions = .fromMode(0o755) });
|
||||
|
||||
std.fs.cwd().symLink("/run/runit/supervise.ly", supervise_path, .{}) catch |err| {
|
||||
std.Io.Dir.cwd().symLink(io, "/run/runit/supervise.ly", supervise_path, .{}) catch |err| {
|
||||
if (err == error.PathAlreadyExists) {
|
||||
std.debug.print("warn: /run/runit/supervise.ly already exists as a symbolic link.\n", .{});
|
||||
} else {
|
||||
@@ -290,49 +291,49 @@ fn install_service(allocator: std.mem.Allocator, patch_map: PatchMap) !void {
|
||||
std.debug.print("info: installed symlink /run/runit/supervise.ly\n", .{});
|
||||
},
|
||||
.s6 => {
|
||||
const admin_service_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/s6/adminsv/default/contents.d" });
|
||||
std.fs.cwd().makePath(admin_service_path) catch {};
|
||||
var admin_service_dir = std.fs.cwd().openDir(admin_service_path, .{}) catch unreachable;
|
||||
defer admin_service_dir.close();
|
||||
const admin_service_path = try std.Io.Dir.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/s6/adminsv/default/contents.d" });
|
||||
std.Io.Dir.cwd().createDirPath(io, admin_service_path) catch {};
|
||||
var admin_service_dir = std.Io.Dir.cwd().openDir(io, admin_service_path, .{}) catch unreachable;
|
||||
defer admin_service_dir.close(io);
|
||||
|
||||
const file = try admin_service_dir.createFile("ly-srv", .{});
|
||||
file.close();
|
||||
const file = try admin_service_dir.createFile(io, "ly-srv", .{});
|
||||
file.close(io);
|
||||
|
||||
const service_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/s6/sv/ly-srv" });
|
||||
std.fs.cwd().makePath(service_path) catch {};
|
||||
var service_dir = std.fs.cwd().openDir(service_path, .{}) catch unreachable;
|
||||
defer service_dir.close();
|
||||
const service_path = try std.Io.Dir.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/s6/sv/ly-srv" });
|
||||
std.Io.Dir.cwd().createDirPath(io, service_path) catch {};
|
||||
var service_dir = std.Io.Dir.cwd().openDir(io, service_path, .{}) catch unreachable;
|
||||
defer service_dir.close(io);
|
||||
|
||||
const patched_run = try patchFile(allocator, "res/ly-s6/run", patch_map);
|
||||
try installText(patched_run, service_dir, service_path, "run", .{ .mode = 0o755 });
|
||||
const patched_run = try patchFile(allocator, io, "res/ly-s6/run", patch_map);
|
||||
try installText(io, patched_run, service_dir, service_path, "run", .{ .permissions = .fromMode(0o755) });
|
||||
|
||||
try installFile("res/ly-s6/type", service_dir, service_path, "type", .{});
|
||||
try installFile(io, "res/ly-s6/type", service_dir, service_path, "type", .{});
|
||||
},
|
||||
.dinit => {
|
||||
const service_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/dinit.d" });
|
||||
std.fs.cwd().makePath(service_path) catch {};
|
||||
var service_dir = std.fs.cwd().openDir(service_path, .{}) catch unreachable;
|
||||
defer service_dir.close();
|
||||
const service_path = try std.Io.Dir.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/dinit.d" });
|
||||
std.Io.Dir.cwd().createDirPath(io, service_path) catch {};
|
||||
var service_dir = std.Io.Dir.cwd().openDir(io, service_path, .{}) catch unreachable;
|
||||
defer service_dir.close(io);
|
||||
|
||||
const patched_service = try patchFile(allocator, "res/ly-dinit", patch_map);
|
||||
try installText(patched_service, service_dir, service_path, "ly", .{});
|
||||
const patched_service = try patchFile(allocator, io, "res/ly-dinit", patch_map);
|
||||
try installText(io, patched_service, service_dir, service_path, "ly", .{});
|
||||
},
|
||||
.sysvinit => {
|
||||
const service_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/init.d" });
|
||||
std.fs.cwd().makePath(service_path) catch {};
|
||||
var service_dir = std.fs.cwd().openDir(service_path, .{}) catch unreachable;
|
||||
defer service_dir.close();
|
||||
const service_path = try std.Io.Dir.path.join(allocator, &[_][]const u8{ dest_directory, config_directory, "/init.d" });
|
||||
std.Io.Dir.cwd().createDirPath(io, service_path) catch {};
|
||||
var service_dir = std.Io.Dir.cwd().openDir(io, service_path, .{}) catch unreachable;
|
||||
defer service_dir.close(io);
|
||||
|
||||
const patched_service = try patchFile(allocator, "res/ly-sysvinit", patch_map);
|
||||
try installText(patched_service, service_dir, service_path, "ly", .{ .mode = 0o755 });
|
||||
const patched_service = try patchFile(allocator, io, "res/ly-sysvinit", patch_map);
|
||||
try installText(io, patched_service, service_dir, service_path, "ly", .{ .permissions = .fromMode(0o755) });
|
||||
},
|
||||
.freebsd => {
|
||||
const exe_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, prefix_directory, "/bin" });
|
||||
var executable_dir = std.fs.cwd().openDir(exe_path, .{}) catch unreachable;
|
||||
defer executable_dir.close();
|
||||
const exe_path = try std.Io.Dir.path.join(allocator, &[_][]const u8{ dest_directory, prefix_directory, "/bin" });
|
||||
var executable_dir = std.Io.Dir.cwd().openDir(io, exe_path, .{}) catch unreachable;
|
||||
defer executable_dir.close(io);
|
||||
|
||||
const patched_wrapper = try patchFile(allocator, "res/ly-freebsd-wrapper", patch_map);
|
||||
try installText(patched_wrapper, executable_dir, exe_path, "ly_wrapper", .{ .mode = 0o755 });
|
||||
const patched_wrapper = try patchFile(allocator, io, "res/ly-freebsd-wrapper", patch_map);
|
||||
try installText(io, patched_wrapper, executable_dir, exe_path, "ly_wrapper", .{ .permissions = .fromMode(0o755) });
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -340,33 +341,35 @@ fn install_service(allocator: std.mem.Allocator, patch_map: PatchMap) !void {
|
||||
pub fn Uninstaller(uninstall_config: bool) type {
|
||||
return struct {
|
||||
pub fn make(step: *std.Build.Step, _: std.Build.Step.MakeOptions) !void {
|
||||
var threaded: std.Io.Threaded = .init_single_threaded;
|
||||
const io = threaded.io();
|
||||
const allocator = step.owner.allocator;
|
||||
|
||||
if (uninstall_config) {
|
||||
try deleteTree(allocator, config_directory, "/ly", "ly config directory not found");
|
||||
try deleteTree(allocator, io, config_directory, "/ly", "ly config directory not found");
|
||||
}
|
||||
|
||||
const exe_path = try std.fs.path.join(allocator, &[_][]const u8{ prefix_directory, "/bin/", executable_name });
|
||||
const exe_path = try std.Io.Dir.path.join(allocator, &[_][]const u8{ prefix_directory, "/bin/", executable_name });
|
||||
var success = true;
|
||||
std.fs.cwd().deleteFile(exe_path) catch {
|
||||
std.Io.Dir.cwd().deleteFile(io, exe_path) catch {
|
||||
std.debug.print("warn: ly executable not found\n", .{});
|
||||
success = false;
|
||||
};
|
||||
if (success) std.debug.print("info: deleted {s}\n", .{exe_path});
|
||||
|
||||
try deleteFile(allocator, config_directory, "/pam.d/ly", "ly pam file not found");
|
||||
try deleteFile(allocator, io, config_directory, "/pam.d/ly", "ly pam file not found");
|
||||
|
||||
switch (init_system) {
|
||||
.systemd => try deleteFile(allocator, prefix_directory, "/lib/systemd/system/ly@.service", "systemd service not found"),
|
||||
.openrc => try deleteFile(allocator, config_directory, "/init.d/ly", "openrc service not found"),
|
||||
.runit => try deleteTree(allocator, config_directory, "/sv/ly", "runit service not found"),
|
||||
.systemd => try deleteFile(allocator, io, prefix_directory, "/lib/systemd/system/ly@.service", "systemd service not found"),
|
||||
.openrc => try deleteFile(allocator, io, config_directory, "/init.d/ly", "openrc service not found"),
|
||||
.runit => try deleteTree(allocator, io, config_directory, "/sv/ly", "runit service not found"),
|
||||
.s6 => {
|
||||
try deleteTree(allocator, config_directory, "/s6/sv/ly-srv", "s6 service not found");
|
||||
try deleteFile(allocator, config_directory, "/s6/adminsv/default/contents.d/ly-srv", "s6 admin service not found");
|
||||
try deleteTree(allocator, io, config_directory, "/s6/sv/ly-srv", "s6 service not found");
|
||||
try deleteFile(allocator, io, config_directory, "/s6/adminsv/default/contents.d/ly-srv", "s6 admin service not found");
|
||||
},
|
||||
.dinit => try deleteFile(allocator, config_directory, "/dinit.d/ly", "dinit service not found"),
|
||||
.sysvinit => try deleteFile(allocator, config_directory, "/init.d/ly", "sysvinit service not found"),
|
||||
.freebsd => try deleteFile(allocator, prefix_directory, "/bin/ly_wrapper", "freebsd wrapper not found"),
|
||||
.dinit => try deleteFile(allocator, io, config_directory, "/dinit.d/ly", "dinit service not found"),
|
||||
.sysvinit => try deleteFile(allocator, io, config_directory, "/init.d/ly", "sysvinit service not found"),
|
||||
.freebsd => try deleteFile(allocator, io, prefix_directory, "/bin/ly_wrapper", "freebsd wrapper not found"),
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -384,11 +387,11 @@ fn getVersionStr(b: *std.Build, name: []const u8, version: std.SemanticVersion)
|
||||
"--match",
|
||||
"*.*.*",
|
||||
"--tags",
|
||||
}, &status, .Ignore) catch {
|
||||
}, &status, .ignore) catch {
|
||||
return version_str;
|
||||
};
|
||||
var git_describe = std.mem.trim(u8, git_describe_raw, " \n\r");
|
||||
git_describe = std.mem.trimLeft(u8, git_describe, "v");
|
||||
git_describe = std.mem.trimStart(u8, git_describe, "v");
|
||||
|
||||
switch (std.mem.count(u8, git_describe, "-")) {
|
||||
0 => {
|
||||
@@ -401,7 +404,7 @@ fn getVersionStr(b: *std.Build, name: []const u8, version: std.SemanticVersion)
|
||||
2 => {
|
||||
// Untagged development build (e.g. 0.10.0-dev.2025+ecf0050a9).
|
||||
var it = std.mem.splitScalar(u8, git_describe, '-');
|
||||
const tagged_ancestor = std.mem.trimLeft(u8, it.first(), "v");
|
||||
const tagged_ancestor = std.mem.trimStart(u8, it.first(), "v");
|
||||
const commit_height = it.next().?;
|
||||
const commit_id = it.next().?;
|
||||
|
||||
@@ -428,24 +431,25 @@ fn getVersionStr(b: *std.Build, name: []const u8, version: std.SemanticVersion)
|
||||
}
|
||||
|
||||
fn installFile(
|
||||
io: std.Io,
|
||||
source_file: []const u8,
|
||||
destination_directory: std.fs.Dir,
|
||||
destination_directory: std.Io.Dir,
|
||||
destination_directory_path: []const u8,
|
||||
destination_file: []const u8,
|
||||
options: std.fs.Dir.CopyFileOptions,
|
||||
options: std.Io.Dir.CopyFileOptions,
|
||||
) !void {
|
||||
try std.fs.cwd().copyFile(source_file, destination_directory, destination_file, options);
|
||||
try std.Io.Dir.cwd().copyFile(source_file, destination_directory, destination_file, io, options);
|
||||
std.debug.print("info: installed {s}/{s}\n", .{ destination_directory_path, destination_file });
|
||||
}
|
||||
|
||||
fn patchFile(allocator: std.mem.Allocator, source_file: []const u8, patch_map: PatchMap) ![]const u8 {
|
||||
var file = try std.fs.cwd().openFile(source_file, .{});
|
||||
defer file.close();
|
||||
fn patchFile(allocator: std.mem.Allocator, io: std.Io, source_file: []const u8, patch_map: PatchMap) ![]const u8 {
|
||||
var file = try std.Io.Dir.cwd().openFile(io, source_file, .{});
|
||||
defer file.close(io);
|
||||
|
||||
const stat = try file.stat();
|
||||
const stat = try file.stat(io);
|
||||
|
||||
var buffer: [4096]u8 = undefined;
|
||||
var reader = file.reader(&buffer);
|
||||
var reader = file.reader(io, &buffer);
|
||||
var text = try reader.interface.readAlloc(allocator, stat.size);
|
||||
|
||||
var iterator = patch_map.iterator();
|
||||
@@ -459,17 +463,18 @@ fn patchFile(allocator: std.mem.Allocator, source_file: []const u8, patch_map: P
|
||||
}
|
||||
|
||||
fn installText(
|
||||
io: std.Io,
|
||||
text: []const u8,
|
||||
destination_directory: std.fs.Dir,
|
||||
destination_directory: std.Io.Dir,
|
||||
destination_directory_path: []const u8,
|
||||
destination_file: []const u8,
|
||||
options: std.fs.File.CreateFlags,
|
||||
options: std.Io.File.CreateFlags,
|
||||
) !void {
|
||||
var file = try destination_directory.createFile(destination_file, options);
|
||||
defer file.close();
|
||||
var file = try destination_directory.createFile(io, destination_file, options);
|
||||
defer file.close(io);
|
||||
|
||||
var buffer: [1024]u8 = undefined;
|
||||
var writer = file.writer(&buffer);
|
||||
var writer = file.writer(io, &buffer);
|
||||
try writer.interface.writeAll(text);
|
||||
try writer.interface.flush();
|
||||
|
||||
@@ -478,13 +483,14 @@ fn installText(
|
||||
|
||||
fn deleteFile(
|
||||
allocator: std.mem.Allocator,
|
||||
io: std.Io,
|
||||
prefix: []const u8,
|
||||
file: []const u8,
|
||||
warning: []const u8,
|
||||
) !void {
|
||||
const path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, prefix, file });
|
||||
const path = try std.Io.Dir.path.join(allocator, &[_][]const u8{ dest_directory, prefix, file });
|
||||
|
||||
std.fs.cwd().deleteFile(path) catch |err| {
|
||||
std.Io.Dir.cwd().deleteFile(io, path) catch |err| {
|
||||
if (err == error.FileNotFound) {
|
||||
std.debug.print("warn: {s}\n", .{warning});
|
||||
return;
|
||||
@@ -498,13 +504,14 @@ fn deleteFile(
|
||||
|
||||
fn deleteTree(
|
||||
allocator: std.mem.Allocator,
|
||||
io: std.Io,
|
||||
prefix: []const u8,
|
||||
directory: []const u8,
|
||||
warning: []const u8,
|
||||
) !void {
|
||||
const path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, prefix, directory });
|
||||
const path = try std.Io.Dir.path.join(allocator, &[_][]const u8{ dest_directory, prefix, directory });
|
||||
|
||||
var dir = std.fs.cwd().openDir(path, .{}) catch |err| {
|
||||
var dir = std.Io.Dir.cwd().openDir(io, path, .{}) catch |err| {
|
||||
if (err == error.FileNotFound) {
|
||||
std.debug.print("warn: {s}\n", .{warning});
|
||||
return;
|
||||
@@ -512,9 +519,9 @@ fn deleteTree(
|
||||
|
||||
return err;
|
||||
};
|
||||
dir.close();
|
||||
dir.close(io);
|
||||
|
||||
try std.fs.cwd().deleteTree(path);
|
||||
try std.Io.Dir.cwd().deleteTree(io, path);
|
||||
|
||||
std.debug.print("info: deleted {s}\n", .{path});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user