115 lines
5.0 KiB
Zig
115 lines
5.0 KiB
Zig
const std = @import("std");
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
// Standard target options allows the person running `zig build` to choose
|
|
// what target to build for. Here we do not override the defaults, which
|
|
// means any target is allowed, and the default is native. Other options
|
|
// for restricting supported target set are available.
|
|
const target = b.standardTargetOptions(.{});
|
|
|
|
// Standard release options allow the person running `zig build` to select
|
|
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
const uploadexe = switch (target.result.os.tag) {
|
|
.linux => b.addExecutable(.{ .name = "clipboard-upload", .root_source_file = b.path("src/main-linux.zig"), .target = target }),
|
|
.windows => b.addExecutable(.{ .name = "clipboard-upload", .root_source_file = b.path("src/main-windows.zig"), .target = target }),
|
|
else => std.process.exit(1),
|
|
};
|
|
|
|
const path = if (b.option(bool, "curl", "use external curl command") orelse false)
|
|
"config/curl.zig"
|
|
else
|
|
"config/nocurl.zig";
|
|
|
|
const enc_path = blk: {
|
|
if (b.option(bool, "seperate-encryption", "use external encryption command") orelse false) {
|
|
const encryptionexe = b.addExecutable(.{
|
|
.name = "encrypt",
|
|
.root_source_file = b.path("src/encrypt.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
b.getInstallStep().dependOn(&b.addInstallArtifact(encryptionexe, .{}).step);
|
|
break :blk "config/external_encryption.zig";
|
|
} else {
|
|
break :blk "config/sane_encryption.zig";
|
|
}
|
|
};
|
|
|
|
configureExe(uploadexe, b, target, optimize, path, enc_path);
|
|
|
|
const run_cmd = b.addRunArtifact(uploadexe);
|
|
run_cmd.step.dependOn(b.getInstallStep());
|
|
if (b.args) |args| {
|
|
run_cmd.addArgs(args);
|
|
}
|
|
|
|
const run_step = b.step("run", "Run the app (uplaods clipboard contents)");
|
|
run_step.dependOn(&run_cmd.step);
|
|
|
|
const downloadexe = b.addExecutable(.{ .name = "clipboard-download", .root_source_file = b.path("src/download.zig"), .target = target });
|
|
|
|
configureExe(downloadexe, b, target, optimize, path, enc_path);
|
|
|
|
const run_download_cmd = b.addRunArtifact(downloadexe);
|
|
run_download_cmd.step.dependOn(b.getInstallStep());
|
|
if (b.args) |args| {
|
|
run_download_cmd.addArgs(args);
|
|
}
|
|
|
|
const run_download_step = b.step("run-down", "Run the app (downloads clipboard contents)");
|
|
run_download_step.dependOn(&run_download_cmd.step);
|
|
}
|
|
|
|
fn configureExe(exe: *std.Build.Step.Compile, b: *std.Build, target: std.Build.ResolvedTarget, mode: std.builtin.OptimizeMode, config_path: []const u8, enc_config_path: []const u8) void {
|
|
exe.root_module.optimize = mode;
|
|
if (target.result.os.tag == .linux) {
|
|
exe.linkLibC();
|
|
// LibX11 1.7.2: https://gitlab.freedesktop.org/xorg/lib/libx11/-/archive/libX11-1.7.2/libx11-libX11-1.7.2.tar.gz
|
|
// LibXfixes 5.0.3: https://gitlab.freedesktop.org/xorg/lib/libxfixes/-/archive/libXfixes-5.0.3/libxfixes-libXfixes-5.0.3.tar.gz
|
|
// XOrg Proto: https://gitlab.freedesktop.org/xorg/proto/xorgproto/-/archive/xorgproto-2021.5/xorgproto-xorgproto-2021.5.tar.gz
|
|
// We can download the above by taking each url and processing in a
|
|
// command e.g.:
|
|
// curl <url> | tar xz --wildcards '*.h'
|
|
exe.addIncludePath(b.path("libx11-libX11-1.7.2/include"));
|
|
exe.addIncludePath(b.path("libxfixes-libXfixes-5.0.3/include"));
|
|
exe.addIncludePath(b.path("xorgproto-xorgproto-2021.5/include"));
|
|
|
|
// More than a little messy. We're grabbing libX11 and libXfixes from
|
|
// the host, while using downloaded headers. This assumes debian
|
|
// bullseye host, and also means you can't cross-compile from Windows.
|
|
// TODO: Make this better
|
|
// const dependent_objects = .{
|
|
// "/usr/lib/x86_64-linux-gnu/libX11.so.6",
|
|
// "/usr/lib/x86_64-linux-gnu/libXfixes.so.3",
|
|
// };
|
|
// const dependent_objects = .{
|
|
// "/usr/lib/x86_64-linux-gnu/libX11.so.6",
|
|
// "/nix/store/wd7b3f9sqgs0flgicx213iiyzjb4jxqm-libXfixes-6.0.1/lib/libXfixes.so.3",
|
|
// };
|
|
const dependent_objects = .{
|
|
"X11",
|
|
"Xfixes",
|
|
};
|
|
inline for (dependent_objects) |obj|
|
|
exe.linkSystemLibrary(obj);
|
|
// exe.addObjectFile(b.path(obj));
|
|
}
|
|
if (target.result.os.tag == .windows) {
|
|
// woah...we don't actually need libc!
|
|
exe.linkSystemLibrary("user32");
|
|
exe.linkSystemLibrary("kernel32");
|
|
exe.linkSystemLibrary("shell32");
|
|
}
|
|
|
|
exe.root_module.addImport("config", b.createModule(.{
|
|
.root_source_file = b.path(config_path),
|
|
}));
|
|
exe.root_module.addImport("encryptionconfig", b.createModule(.{
|
|
.root_source_file = b.path(enc_config_path),
|
|
}));
|
|
|
|
b.getInstallStep().dependOn(&b.addInstallArtifact(exe, .{}).step);
|
|
}
|