11const 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
334pub 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}
0 commit comments