feat: made unix-loader more stable on FreeBSD

This commit is contained in:
Andrew Rioux
2025-02-03 02:37:17 -05:00
parent d8a277e769
commit 00331ec550
9 changed files with 159 additions and 59 deletions
+16 -4
View File
@@ -1,7 +1,14 @@
const std = @import("std");
pub fn build(b: *std.Build) !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const alloc = arena.allocator();
const beacon = b.option([]const u8, "beacon", "path to beacon to load") orelse std.debug.panic("Expected a path to a beacon to be provided with -Dbeacon", .{});
const target_os = b.option([]const u8, "os", "os name to inject in final binary") orelse "linux";
const fork = b.option(bool, "fork", "whether to fork or take over the process") orelse false;
const beacon_path = std.Build.LazyPath{ .cwd_relative = beacon };
const target = b.standardTargetOptions(.{});
@@ -26,14 +33,21 @@ pub fn build(b: *std.Build) !void {
.pic = true,
});
const options = b.addOptions();
options.addOption(bool, "fork", fork);
libloader.addIncludePath(b.path("src"));
libloader.root_module.addAnonymousImport("beacon", .{ .root_source_file = compressed_beacon });
libloader.linkLibC();
libloader.root_module.addOptions("config", options);
if (target.result.os.tag == .freebsd) {
libloader.linkLibC();
}
libloader.step.dependOn(&tool_step.step);
var lib = b.addSharedLibrary(.{
.name = "unix-loader",
.name = try std.fmt.allocPrint(alloc, "unix-loader-{s}", .{target_os}),
.root_source_file = b.path("src/loader.zig"),
.target = target,
.optimize = optimize,
@@ -44,8 +58,6 @@ pub fn build(b: *std.Build) !void {
.name = "test-loader",
.root_source_file = b.path("src/test_run.zig"),
.target = target,
.optimize = optimize,
.strip = true,
});
lib.addIncludePath(b.path("src"));