- commit
- 6b1e8c3
- parent
- 330a889
- author
- Eric Bower
- date
- 2025-12-05 14:56:02 -0500 EST
feat: add release build
2 files changed,
+51,
-1
+50,
-0
1@@ -1,8 +1,20 @@
2 const std = @import("std");
3
4+const linux_targets: []const std.Target.Query = &.{
5+ .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .gnu },
6+ .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .gnu },
7+};
8+
9+const macos_targets: []const std.Target.Query = &.{
10+ .{ .cpu_arch = .x86_64, .os_tag = .macos },
11+ .{ .cpu_arch = .aarch64, .os_tag = .macos },
12+};
13+
14 pub fn build(b: *std.Build) void {
15 const target = b.standardTargetOptions(.{});
16 const optimize = b.standardOptimizeOption(.{});
17+ const version = b.option([]const u8, "version", "Version string for release") orelse
18+ @as([]const u8, @import("build.zig.zon").version);
19
20 const run_step = b.step("run", "Run the app");
21 const test_step = b.step("test", "Run unit tests");
22@@ -70,4 +82,42 @@ pub fn build(b: *std.Build) void {
23 // If you copy this into your `build.zig`, make sure to rename 'foo'
24 const check = b.step("check", "Check if foo compiles");
25 check.dependOn(&exe_check.step);
26+
27+ // Release step - macOS can cross-compile to Linux, but Linux cannot cross-compile to macOS (needs SDK)
28+ const native_os = @import("builtin").os.tag;
29+ const release_targets = if (native_os == .macos) linux_targets ++ macos_targets else linux_targets;
30+ const release_step = b.step("release", "Build release binaries (macOS builds all, Linux builds Linux only)");
31+ for (release_targets) |release_target| {
32+ const resolved = b.resolveTargetQuery(release_target);
33+ const release_mod = b.createModule(.{
34+ .root_source_file = b.path("src/main.zig"),
35+ .target = resolved,
36+ .optimize = .ReleaseSafe,
37+ });
38+
39+ if (b.lazyDependency("ghostty", .{
40+ .target = resolved,
41+ .optimize = .ReleaseSafe,
42+ })) |dep| {
43+ release_mod.addImport("ghostty-vt", dep.module("ghostty-vt"));
44+ }
45+
46+ const release_exe = b.addExecutable(.{
47+ .name = "zmx",
48+ .root_module = release_mod,
49+ });
50+
51+ const os_name = @tagName(release_target.os_tag orelse .linux);
52+ const arch_name = @tagName(release_target.cpu_arch orelse .x86_64);
53+ const tarball_name = b.fmt("zmx-{s}-{s}-{s}.tar.gz", .{ version, os_name, arch_name });
54+
55+ const tar = b.addSystemCommand(&.{ "tar", "-czf" });
56+ const tarball = tar.addOutputFileArg(tarball_name);
57+ tar.addArg("-C");
58+ tar.addDirectoryArg(release_exe.getEmittedBinDirectory());
59+ tar.addArg("zmx");
60+
61+ const install_tar = b.addInstallFile(tarball, b.fmt("dist/{s}", .{tarball_name}));
62+ release_step.dependOn(&install_tar.step);
63+ }
64 }
+1,
-1
1@@ -9,7 +9,7 @@
2 .name = .zmx,
3 // This is a [Semantic Version](https://semver.org/).
4 // In a future version of Zig it will be used for package deduplication.
5- .version = "0.0.0",
6+ .version = "0.0.2",
7 // Together with name, this represents a globally unique package
8 // identifier. This field is generated by the Zig toolchain when the
9 // package is first created, and then *never changes*. This allows