made it also possible to download individual beacons as opposed to just the installer, to provide more options and make it easier to test
73 lines
2.3 KiB
Zig
73 lines
2.3 KiB
Zig
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(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
const tool = b.addExecutable(.{
|
|
.name = "beacon-compress",
|
|
.root_source_file = b.path("src/gzip.zig"),
|
|
.target = b.host,
|
|
});
|
|
|
|
const tool_step = b.addRunArtifact(tool);
|
|
tool_step.addFileArg(beacon_path);
|
|
const compressed_beacon = tool_step.addOutputFileArg("beacon.gz");
|
|
|
|
const libloader = b.addObject(.{
|
|
.name = "libloader",
|
|
.root_source_file = b.path("src/libloader.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.strip = true,
|
|
.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.root_module.addOptions("config", options);
|
|
|
|
if (target.result.os.tag == .freebsd) {
|
|
libloader.linkLibC();
|
|
}
|
|
|
|
libloader.step.dependOn(&tool_step.step);
|
|
|
|
var lib = b.addSharedLibrary(.{
|
|
.name = try std.fmt.allocPrint(alloc, "unix-loader-{s}", .{target_os}),
|
|
.root_source_file = b.path("src/loader.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.strip = true,
|
|
});
|
|
|
|
const exe = b.addExecutable(.{
|
|
.name = "unix-loader",
|
|
.root_source_file = b.path("src/run.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.strip = true,
|
|
});
|
|
|
|
lib.addIncludePath(b.path("src"));
|
|
lib.addObject(libloader);
|
|
exe.addIncludePath(b.path("src"));
|
|
exe.addObject(libloader);
|
|
|
|
b.installArtifact(lib);
|
|
b.installArtifact(exe);
|
|
}
|