build: add -Dall_targets build option to build all known good release targets

Now just plain `--release` will build the release just for the native cpu arch and os.
Adding `-Dall_targets` will build all targets in the known good list.

closes #311
This commit is contained in:
CJ van den Berg 2025-10-02 09:55:35 +02:00
parent b1e5b2f80f
commit 31c03060cf
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
3 changed files with 12 additions and 3 deletions

View file

@ -4,6 +4,7 @@ const builtin = @import("builtin");
const optimize_deps = .ReleaseFast; const optimize_deps = .ReleaseFast;
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const all_targets = b.option(bool, "all_targets", "Build all known good targets during release builds (default: no)") orelse false;
const tracy_enabled = b.option(bool, "enable_tracy", "Enable tracy client library (default: no)") orelse false; const tracy_enabled = b.option(bool, "enable_tracy", "Enable tracy client library (default: no)") orelse false;
const use_tree_sitter = b.option(bool, "use_tree_sitter", "Enable tree-sitter (default: yes)") orelse true; const use_tree_sitter = b.option(bool, "use_tree_sitter", "Enable tree-sitter (default: yes)") orelse true;
const strip = b.option(bool, "strip", "Disable debug information (default: no)"); const strip = b.option(bool, "strip", "Disable debug information (default: no)");
@ -45,6 +46,7 @@ pub fn build(b: *std.Build) void {
pie, pie,
gui, gui,
version.items, version.items,
all_targets,
); );
} }
@ -61,6 +63,7 @@ fn build_development(
pie: ?bool, pie: ?bool,
gui: bool, gui: bool,
version: []const u8, version: []const u8,
_: bool, // all_targets
) void { ) void {
const target = b.standardTargetOptions(.{ .default_target = .{ .abi = if (builtin.os.tag == .linux and !tracy_enabled) .musl else null } }); const target = b.standardTargetOptions(.{ .default_target = .{ .abi = if (builtin.os.tag == .linux and !tracy_enabled) .musl else null } });
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
@ -97,8 +100,9 @@ fn build_release(
pie: ?bool, pie: ?bool,
_: bool, //gui _: bool, //gui
version: []const u8, version: []const u8,
all_targets: bool,
) void { ) void {
const targets: []const std.Target.Query = &.{ const targets: []const std.Target.Query = if (all_targets) &.{
.{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .musl }, .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .musl },
.{ .cpu_arch = .x86, .os_tag = .linux, .abi = .musl }, .{ .cpu_arch = .x86, .os_tag = .linux, .abi = .musl },
.{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .musl }, .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .musl },
@ -107,6 +111,11 @@ fn build_release(
.{ .cpu_arch = .aarch64, .os_tag = .macos }, .{ .cpu_arch = .aarch64, .os_tag = .macos },
.{ .cpu_arch = .x86_64, .os_tag = .windows }, .{ .cpu_arch = .x86_64, .os_tag = .windows },
.{ .cpu_arch = .aarch64, .os_tag = .windows }, .{ .cpu_arch = .aarch64, .os_tag = .windows },
} else blk: {
const native_target = b.resolveTargetQuery(.{}).result;
break :blk &.{
.{ .cpu_arch = native_target.cpu.arch, .os_tag = native_target.os.tag },
};
}; };
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
const optimize_release = optimize; const optimize_release = optimize;

View file

@ -83,7 +83,7 @@ echo running tests...
echo building... echo building...
./zig build --release --prefix "$DESTDIR/build" ./zig build -Dall_targets --release --prefix "$DESTDIR/build"
VERSION=$(/bin/cat "$DESTDIR/build/version") VERSION=$(/bin/cat "$DESTDIR/build/version")

View file

@ -18,7 +18,7 @@ echo running tests...
echo building... echo building...
./zig build --release --prefix "$DESTDIR/build" ./zig build -Dall_targets --release --prefix "$DESTDIR/build"
cd "$DESTDIR/build" cd "$DESTDIR/build"