@@ -5,57 +5,101 @@ const Step = std.build.Step;
55pub fn build(b: *Builder) void {
66 const mode = b.standardReleaseOptions();
77 const strip = b.option(bool, "strip", "strip binaries") orelse true;
8- buildAnytype(b, "", mode, strip);
8+
9+ const path_prefix = "";
10+ const signing_exe = addSigningExe(b, path_prefix);
11+ const dev_signing = Signing{
12+ .exe = signing_exe,
13+ .key_filename = b.pathFromRoot("tuple_dev_ed25519"),
14+ };
15+ _ = addLaunchExes(b, path_prefix, mode, .customer, .{ .pubkey_filepath = "tuple_dev_ed25519.pub", .strip = strip, .exe_suffix = "" , .signing = null });
16+ _ = addLaunchExes(b, path_prefix, mode, .dev , .{ .pubkey_filepath = "tuple_dev_ed25519.pub", .strip = strip, .exe_suffix = "-dev", .signing = dev_signing });
17+ }
18+
19+ pub const SigningExe = struct {
20+ exe: *std.build.LibExeObjStep,
21+ };
22+
23+ fn concat(b: *Builder, left: []const u8, right: []const u8) []u8 {
24+ return std.mem.concat(b.allocator, u8, &.{left, right}) catch unreachable;
925}
1026
27+ pub fn addSigningExe(b: *Builder, comptime path_prefix: []const u8) SigningExe {
28+ const exe = b.addExecutable("signing", path_prefix ++ "signing.zig");
29+ exe.single_threaded = true;
30+ exe.override_dest_dir = .prefix;
31+ exe.install();
32+ return SigningExe{ .exe = exe };
33+ }
34+
35+ pub const LaunchExeVariant = enum { dev, customer };
36+
37+ pub const LaunchExes = struct {
38+ launch: *std.build.LibExeObjStep,
39+ flatpak_launch: *std.build.LibExeObjStep,
40+ };
41+
42+ pub const Signing = struct {
43+ exe: SigningExe,
44+ key_filename: []const u8,
45+ };
46+
1147// This function allows this build to be used as apart of another build.zig. Set `path_prefix`
1248// to the sub_path where this build.zig file exists (include trailing slash).
13- pub fn buildAnytype(b: *Builder, comptime path_prefix: []const u8, mode: std.builtin.Mode, strip: bool) void {
49+ pub fn addLaunchExes(
50+ b: *Builder,
51+ path_prefix: []const u8,
52+ mode: std.builtin.Mode,
53+ variant: LaunchExeVariant,
54+ opt: struct {
55+ pubkey_filepath: []const u8,
56+ strip: bool,
57+ exe_suffix: []const u8,
58+ signing: ?Signing,
59+ },
60+ ) LaunchExes {
1461 const target = std.zig.CrossTarget.parse(.{
1562 .arch_os_abi = "x86_64-linux",
1663 }) catch unreachable;
1764
18- const signing_exe = b.addExecutable("signing", path_prefix ++ "signing.zig");
19- signing_exe.single_threaded = true;
20- signing_exe.override_dest_dir = .prefix;
21- signing_exe.install();
22-
2365 const path_prefix_no_ts = std.mem.trimRight(u8, path_prefix, "/");
2466
25- const LaunchExeVariant = enum { dev, customer };
26- inline for (std.meta.fields(LaunchExeVariant)) |field| {
27- const variant = @intToEnum(LaunchExeVariant, field.value);
28- const suffix = switch (variant) { .dev => "-dev", .customer => "" };
29- const build_options = b.addOptions();
30- build_options.addOption(LaunchExeVariant, "variant", variant);
31-
32- {
33- const exe = b.addExecutable("tuple-launch" ++ suffix, path_prefix ++ "launch.zig");
34- exe.addIncludePath(b.pathFromRoot(path_prefix_no_ts));
35- exe.setBuildMode(mode);
36- exe.setTarget(target);
37- exe.single_threaded = true;
38- exe.strip = strip;
39- exe.override_dest_dir = .prefix;
40- exe.install();
41- exe.addOptions("build_options", build_options);
42- }
43- {
44- const exe = b.addExecutable("tuple-flatpak-launch" ++ suffix, path_prefix ++ "flatpak-launch.zig");
45- exe.addIncludePath(b.pathFromRoot(path_prefix_no_ts));
46- exe.setBuildMode(mode);
47- exe.setTarget(target);
48- exe.single_threaded = true;
49- exe.strip = strip;
50- exe.override_dest_dir = .prefix;
51- exe.install();
52- exe.addOptions("build_options", build_options);
53-
54- const sign_exe = signing_exe.run();
67+ const build_options = b.addOptions();
68+ build_options.addOption(LaunchExeVariant, "variant", variant);
69+ build_options.addOption([]const u8, "pubkey_filepath", opt.pubkey_filepath);
70+
71+ const launch_exe = blk: {
72+ const exe = b.addExecutable(concat(b, "tuple-launch", opt.exe_suffix), concat(b, path_prefix, "launch.zig"));
73+ exe.addIncludePath(b.pathFromRoot(path_prefix_no_ts));
74+ exe.setBuildMode(mode);
75+ exe.setTarget(target);
76+ exe.single_threaded = true;
77+ exe.strip = opt.strip;
78+ exe.override_dest_dir = .prefix;
79+ exe.install();
80+ exe.addOptions("build_options", build_options);
81+ break :blk exe;
82+ };
83+ const flatpak_launch_exe = blk: {
84+ const exe = b.addExecutable("tuple-flatpak-launch", concat(b, path_prefix, "flatpak-launch.zig"));
85+ exe.addIncludePath(b.pathFromRoot(path_prefix_no_ts));
86+ exe.setBuildMode(mode);
87+ exe.setTarget(target);
88+ exe.single_threaded = true;
89+ exe.strip = opt.strip;
90+ exe.override_dest_dir = .prefix;
91+ exe.install();
92+ exe.addOptions("build_options", build_options);
93+
94+ if (opt.signing) |signing| {
95+ const sign_exe = signing.exe.exe.run();
5596 sign_exe.addArg("sign");
56- sign_exe.addArg(b.pathFromRoot(path_prefix ++ "tuple_dev_ed25519") );
97+ sign_exe.addArg(signing.key_filename );
5798 sign_exe.addArtifactArg(exe);
5899 b.getInstallStep().dependOn(&sign_exe.step);
59100 }
60- }
101+ break :blk exe;
102+ };
103+
104+ return .{ .launch = launch_exe, .flatpak_launch = flatpak_launch_exe };
61105}
0 commit comments