Skip to content

Commit 5ab9b6c

Browse files
committed
Unify build modes and outputs
1 parent 71ddc9c commit 5ab9b6c

4 files changed

Lines changed: 132 additions & 75 deletions

File tree

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,21 @@ Build release binaries for all supported targets:
109109
zig build build-all-targets
110110
```
111111

112-
Artifacts are written to `release/all-targets/` as `codex-manager-<os>-<arch>`.
112+
Artifacts are written to `zig-out/bin/` as `codex-manager-<os>-<arch>`.
113113

114114
Target set depends on host OS:
115115
- Linux host: Linux + Windows targets
116116
- macOS host: macOS targets
117117
- Windows host: Windows targets
118118

119+
To include macOS cross-builds from Linux, provide a macOS SDK path:
120+
121+
```bash
122+
MACOS_SDK_ROOT=/path/to/MacOSX.sdk zig build build-all-targets
123+
```
124+
125+
This is required because `zig-webui` links macOS frameworks (`Cocoa`, `WebKit`) for macOS targets.
126+
119127
Binary output:
120128

121129
- Linux/macOS: `zig-out/bin/codex-manager`

build-all-targets.sh

Lines changed: 0 additions & 65 deletions
This file was deleted.

build.zig

Lines changed: 123 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,40 @@
11
const std = @import("std");
2+
const builtin = @import("builtin");
3+
4+
fn addMatrixInstallCommand(
5+
b: *std.Build,
6+
step: *std.Build.Step,
7+
target_triple: []const u8,
8+
install_name: []const u8,
9+
maybe_sysroot: ?[]const u8,
10+
) void {
11+
var argv = std.ArrayList([]const u8).empty;
12+
defer argv.deinit(b.allocator);
13+
14+
argv.appendSlice(b.allocator, &.{
15+
"zig",
16+
"build",
17+
"install",
18+
"--prefix",
19+
"zig-out",
20+
"-Doptimize=ReleaseFast",
21+
}) catch @panic("OOM");
22+
23+
if (maybe_sysroot) |sysroot| {
24+
argv.appendSlice(b.allocator, &.{ "--sysroot", sysroot }) catch @panic("OOM");
25+
}
26+
27+
argv.append(b.allocator, b.fmt("-Dtarget={s}", .{target_triple})) catch @panic("OOM");
28+
argv.append(b.allocator, b.fmt("-Dmatrix_name={s}", .{install_name})) catch @panic("OOM");
29+
30+
const cmd = b.addSystemCommand(argv.items);
31+
step.dependOn(&cmd.step);
32+
}
233

334
pub fn build(b: *std.Build) void {
435
const target = b.standardTargetOptions(.{});
536
const optimize = b.standardOptimizeOption(.{});
37+
const matrix_name = b.option([]const u8, "matrix_name", "Override installed binary name");
638

739
const frontend_install = b.addSystemCommand(&.{
840
"bash",
@@ -58,7 +90,11 @@ pub fn build(b: *std.Build) void {
5890
});
5991
exe.step.dependOn(&frontend_build.step);
6092

61-
b.installArtifact(exe);
93+
const install_artifact = b.addInstallArtifact(exe, .{
94+
.dest_sub_path = matrix_name,
95+
.pdb_dir = if (matrix_name == null) .default else .disabled,
96+
});
97+
b.getInstallStep().dependOn(&install_artifact.step);
6298

6399
const dev_step = b.step("dev", "Build frontend and run Codex Manager in dev mode");
64100
const run_cmd = b.addRunArtifact(exe);
@@ -80,14 +116,93 @@ pub fn build(b: *std.Build) void {
80116
const test_step = b.step("test", "Run backend Zig tests");
81117
test_step.dependOn(&run_backend_tests.step);
82118

83-
const build_all_targets_cmd = b.addSystemCommand(&.{
84-
"bash",
85-
"-lc",
86-
"./build-all-targets.sh",
87-
});
88119
const build_all_targets_step = b.step(
89120
"build-all-targets",
90-
"Compile release binaries for all supported targets",
121+
"Compile release binaries for supported target matrix into zig-out/bin",
91122
);
92-
build_all_targets_step.dependOn(&build_all_targets_cmd.step);
123+
124+
switch (builtin.os.tag) {
125+
.linux => {
126+
addMatrixInstallCommand(
127+
b,
128+
build_all_targets_step,
129+
"x86_64-linux-gnu",
130+
"codex-manager-linux-x86_64",
131+
null,
132+
);
133+
addMatrixInstallCommand(
134+
b,
135+
build_all_targets_step,
136+
"aarch64-linux-gnu",
137+
"codex-manager-linux-aarch64",
138+
null,
139+
);
140+
addMatrixInstallCommand(
141+
b,
142+
build_all_targets_step,
143+
"x86_64-windows-gnu",
144+
"codex-manager-windows-x86_64",
145+
null,
146+
);
147+
addMatrixInstallCommand(
148+
b,
149+
build_all_targets_step,
150+
"aarch64-windows-gnu",
151+
"codex-manager-windows-aarch64",
152+
null,
153+
);
154+
155+
if (b.graph.env_map.get("MACOS_SDK_ROOT")) |macos_sdk_root| {
156+
if (macos_sdk_root.len > 0) {
157+
addMatrixInstallCommand(
158+
b,
159+
build_all_targets_step,
160+
"x86_64-macos",
161+
"codex-manager-macos-x86_64",
162+
macos_sdk_root,
163+
);
164+
addMatrixInstallCommand(
165+
b,
166+
build_all_targets_step,
167+
"aarch64-macos",
168+
"codex-manager-macos-aarch64",
169+
macos_sdk_root,
170+
);
171+
}
172+
}
173+
},
174+
.macos => {
175+
addMatrixInstallCommand(
176+
b,
177+
build_all_targets_step,
178+
"x86_64-macos",
179+
"codex-manager-macos-x86_64",
180+
null,
181+
);
182+
addMatrixInstallCommand(
183+
b,
184+
build_all_targets_step,
185+
"aarch64-macos",
186+
"codex-manager-macos-aarch64",
187+
null,
188+
);
189+
},
190+
.windows => {
191+
addMatrixInstallCommand(
192+
b,
193+
build_all_targets_step,
194+
"x86_64-windows-gnu",
195+
"codex-manager-windows-x86_64",
196+
null,
197+
);
198+
addMatrixInstallCommand(
199+
b,
200+
build_all_targets_step,
201+
"aarch64-windows-gnu",
202+
"codex-manager-windows-aarch64",
203+
null,
204+
);
205+
},
206+
else => {},
207+
}
93208
}

build.zig.zon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
.paths = .{
1313
"build.zig",
1414
"build.zig.zon",
15-
"build-all-targets.sh",
1615
"main.zig",
1716
"frontend",
1817
"src",

0 commit comments

Comments
 (0)