switched all builds to bh.declareOptions

This commit is contained in:
peterino2 2025-11-28 20:14:56 -08:00
parent ffc84ce44c
commit cc00fb076e
23 changed files with 201 additions and 193 deletions

11
lib/.claude/settings.local.json vendored Normal file
View File

@ -0,0 +1,11 @@
{
"permissions": {
"allow": [
"Bash(cat:*)",
"Bash(git log:*)",
"Bash(zig build:*)"
],
"deny": [],
"ask": []
}
}

17
lib/bh/build.zig vendored
View File

@ -48,6 +48,23 @@ pub fn MakeModlib(b: *std.Build, o: ModLibOptions) ModLib {
}; };
} }
pub const Options = struct {
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
static_build: bool,
tracy: bool,
};
// standard set of options that all backlog modules and dependenices shall use.
pub fn declareOptions(b: *std.Build) Options {
return .{
.target = b.standardTargetOptions(.{}),
.optimize = b.standardOptimizeOption(.{}),
.static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false,
.tracy = b.option(bool, "tracy", "builds with tracy support") orelse false,
};
}
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});

20
lib/cimgui/build.zig vendored
View File

@ -1,15 +1,13 @@
const std = @import("std"); const std = @import("std");
const bh = @import("bh");
// very tiny, not intended to build anything just to run tests linked with libc // very tiny, not intended to build anything just to run tests linked with libc
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const opts = bh.declareOptions(b);
const optimize = b.standardOptimizeOption(.{});
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false;
_ = static_build;
const mod = b.addModule("cimgui", .{ const mod = b.addModule("cimgui", .{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.link_libc = true, .link_libc = true,
.root_source_file = b.path("src/cimgui.zig"), .root_source_file = b.path("src/cimgui.zig"),
}); });
@ -22,14 +20,14 @@ pub fn build(b: *std.Build) void {
const cimgui = b.addLibrary(.{ const cimgui = b.addLibrary(.{
.name = "cimgui", .name = "cimgui",
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.optimize = optimize, .optimize = opts.optimize,
.target = target, .target = opts.target,
}), }),
}); });
cimgui.linkLibC(); cimgui.linkLibC();
if (target.result.abi != .msvc) if (opts.target.result.abi != .msvc)
cimgui.linkLibCpp(); cimgui.linkLibCpp();
cimgui.addIncludePath(b.path("cimgui")); cimgui.addIncludePath(b.path("cimgui"));
@ -71,8 +69,8 @@ pub fn build(b: *std.Build) void {
const test_step = b.step("test", "run unit tests for imgui"); const test_step = b.step("test", "run unit tests for imgui");
const tests = b.addTest(.{ const tests = b.addTest(.{
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("tests/tests.zig"), .root_source_file = b.path("tests/tests.zig"),
}), }),
}); });

28
lib/enet/build.zig vendored
View File

@ -1,10 +1,8 @@
const std = @import("std"); const std = @import("std");
const bh = @import("bh");
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const opts = bh.declareOptions(b);
const optimize = b.standardOptimizeOption(.{});
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false;
_ = static_build;
// am i good to always have enet as static? // am i good to always have enet as static?
// const enet = if (true) b.addStaticLibrary(.{ // const enet = if (true) b.addStaticLibrary(.{
@ -21,8 +19,8 @@ pub fn build(b: *std.Build) void {
.name = "enet_c", .name = "enet_c",
.linkage = .static, .linkage = .static,
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
}), }),
}); });
@ -47,7 +45,7 @@ pub fn build(b: *std.Build) void {
enet.addIncludePath(b.path("enet-1.3.18/include")); enet.addIncludePath(b.path("enet-1.3.18/include"));
// Platform-specific configuration // Platform-specific configuration
switch (target.result.os.tag) { switch (opts.target.result.os.tag) {
.windows => { .windows => {
enet.linkSystemLibrary("ws2_32"); enet.linkSystemLibrary("ws2_32");
enet.linkSystemLibrary("winmm"); enet.linkSystemLibrary("winmm");
@ -62,8 +60,8 @@ pub fn build(b: *std.Build) void {
b.installArtifact(enet); b.installArtifact(enet);
const mod = b.addModule("enet", .{ const mod = b.addModule("enet", .{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("src/enet.zig"), .root_source_file = b.path("src/enet.zig"),
.link_libc = true, .link_libc = true,
}); });
@ -75,8 +73,8 @@ pub fn build(b: *std.Build) void {
const tests = b.addTest(.{ const tests = b.addTest(.{
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.link_libc = true, .link_libc = true,
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("src/tests.zig"), .root_source_file = b.path("src/tests.zig"),
}), }),
}); });
@ -91,8 +89,8 @@ pub fn build(b: *std.Build) void {
.name = "test-server", .name = "test-server",
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.root_source_file = b.path("src/test_server.zig"), .root_source_file = b.path("src/test_server.zig"),
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
}), }),
}); });
test_server.root_module.addImport("enet", mod); test_server.root_module.addImport("enet", mod);
@ -103,8 +101,8 @@ pub fn build(b: *std.Build) void {
.name = "test-client", .name = "test-client",
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.root_source_file = b.path("src/test_client.zig"), .root_source_file = b.path("src/test_client.zig"),
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
}), }),
}); });
test_client.root_module.addImport("enet", mod); test_client.root_module.addImport("enet", mod);

23
lib/lua/build.zig vendored
View File

@ -1,23 +1,22 @@
const std = @import("std"); const std = @import("std");
const bh = @import("bh");
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const opts = bh.declareOptions(b);
const optimize = b.standardOptimizeOption(.{});
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false;
const mod = b.addModule("lua", .{ const mod = b.addModule("lua", .{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("src/lua.zig"), .root_source_file = b.path("src/lua.zig"),
.link_libc = true, .link_libc = true,
}); });
const luac = b.addLibrary(.{ const luac = b.addLibrary(.{
.name = "luac", .name = "luac",
.linkage = if (static_build) .static else .dynamic, .linkage = if (opts.static_build) .static else .dynamic,
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.link_libc = true, .link_libc = true,
}), }),
}); });
@ -64,9 +63,9 @@ pub fn build(b: *std.Build) void {
luac.addCSourceFile(.{ .file = b.path("src/limited_io.c") }); luac.addCSourceFile(.{ .file = b.path("src/limited_io.c") });
if (target.result.os.tag == .windows) { if (opts.target.result.os.tag == .windows) {
luac.addCSourceFile(.{ .file = b.path("src/minidumpsetup.cpp") }); luac.addCSourceFile(.{ .file = b.path("src/minidumpsetup.cpp") });
if (target.result.abi != .msvc) if (opts.target.result.abi != .msvc)
luac.linkLibCpp(); luac.linkLibCpp();
luac.linkLibC(); luac.linkLibC();
} else { } else {
@ -85,8 +84,8 @@ pub fn build(b: *std.Build) void {
const tests = b.addExecutable(.{ const tests = b.addExecutable(.{
.name = "run-lua", .name = "run-lua",
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("test/test-lua.zig"), .root_source_file = b.path("test/test-lua.zig"),
.link_libc = true, .link_libc = true,
}), }),

View File

@ -1,16 +1,15 @@
const std = @import("std"); const std = @import("std");
const bh = @import("bh");
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const opts = bh.declareOptions(b);
const optimize = b.standardOptimizeOption(.{});
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false;
const miniaudio_c = b.addLibrary(.{ const miniaudio_c = b.addLibrary(.{
.name = "miniaudio_c", .name = "miniaudio_c",
.linkage = if (static_build) .static else .dynamic, .linkage = if (opts.static_build) .static else .dynamic,
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.link_libc = true, .link_libc = true,
}), }),
}); });
@ -19,7 +18,7 @@ pub fn build(b: *std.Build) void {
miniaudio_c.addCSourceFile(.{ .file = b.path("src/miniaudio.cpp"), .flags = &.{"-fno-sanitize=all"}, .language = .c }); miniaudio_c.addCSourceFile(.{ .file = b.path("src/miniaudio.cpp"), .flags = &.{"-fno-sanitize=all"}, .language = .c });
miniaudio_c.addIncludePath(b.path("include")); miniaudio_c.addIncludePath(b.path("include"));
const mod = b.addModule("miniaudio", .{ .target = target, .optimize = optimize, .root_source_file = b.path("src/miniaudio.zig") }); const mod = b.addModule("miniaudio", .{ .target = opts.target, .optimize = opts.optimize, .root_source_file = b.path("src/miniaudio.zig") });
mod.linkLibrary(miniaudio_c); mod.linkLibrary(miniaudio_c);
mod.addIncludePath(b.path("./include")); mod.addIncludePath(b.path("./include"));
@ -28,8 +27,8 @@ pub fn build(b: *std.Build) void {
const test_step = b.step("test", ""); const test_step = b.step("test", "");
const tests = b.addTest(.{ const tests = b.addTest(.{
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("src/miniaudio-test.zig"), .root_source_file = b.path("src/miniaudio-test.zig"),
.link_libc = true, .link_libc = true,
}), }),

21
lib/nfd/build.zig vendored
View File

@ -1,13 +1,12 @@
const std = @import("std"); const std = @import("std");
const bh = @import("bh");
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const opts = bh.declareOptions(b);
const optimize = b.standardOptimizeOption(.{});
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false;
const mod = b.addModule("nfd", .{ const mod = b.addModule("nfd", .{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("src/nfd.zig"), .root_source_file = b.path("src/nfd.zig"),
.link_libc = true, .link_libc = true,
}); });
@ -19,19 +18,19 @@ pub fn build(b: *std.Build) void {
mod.addIncludePath(b.path("include")); mod.addIncludePath(b.path("include"));
if (target.result.os.tag == .macos) { if (opts.target.result.os.tag == .macos) {
mod.addCSourceFile(.{ mod.addCSourceFile(.{
.file = b.path("src/nfd_cocoa.m"), .file = b.path("src/nfd_cocoa.m"),
.flags = &.{}, .flags = &.{},
}); });
mod.linkFramework("AppKit", .{}); mod.linkFramework("AppKit", .{});
} else if (target.result.os.tag == .windows) { } else if (opts.target.result.os.tag == .windows) {
mod.addCSourceFile(.{ mod.addCSourceFile(.{
.file = b.path("src/nfd_win.cpp"), .file = b.path("src/nfd_win.cpp"),
.flags = &.{}, .flags = &.{},
}); });
mod.linkSystemLibrary("ole32", .{}); mod.linkSystemLibrary("ole32", .{});
} else if (target.result.os.tag == .linux) { } else if (opts.target.result.os.tag == .linux) {
// mod.addCSourceFile(.{ // mod.addCSourceFile(.{
// .file = b.path("src/nfd_gtk.c"), // .file = b.path("src/nfd_gtk.c"),
// .flags = &.{}, // .flags = &.{},
@ -47,7 +46,7 @@ pub fn build(b: *std.Build) void {
// mod.linkSystemLibrary("gobject-2.0", .{}); // mod.linkSystemLibrary("gobject-2.0", .{});
} }
const p2dep = b.dependency("p2", .{ .target = target, .optimize = optimize, .static_build = static_build }); const p2dep = b.dependency("p2", .{ .target = opts.target, .optimize = opts.optimize, .static_build = opts.static_build });
const p2mod = p2dep.module("p2"); const p2mod = p2dep.module("p2");
mod.addImport("p2", p2mod); mod.addImport("p2", p2mod);
@ -55,8 +54,8 @@ pub fn build(b: *std.Build) void {
const test_step = b.step("test", ""); const test_step = b.step("test", "");
const tests = b.addTest(.{ const tests = b.addTest(.{
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("src/nfd.zig"), .root_source_file = b.path("src/nfd.zig"),
.link_libc = true, .link_libc = true,
}), }),

View File

@ -1,22 +1,20 @@
const std = @import("std"); const std = @import("std");
const bh = @import("bh");
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const opts = bh.declareOptions(b);
const optimize = b.standardOptimizeOption(.{});
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false;
_ = static_build;
const mod = b.addModule("objLoader", .{ const mod = b.addModule("objLoader", .{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("src/obj_loader.zig"), .root_source_file = b.path("src/obj_loader.zig"),
}); });
const test_step = b.step("test", ""); const test_step = b.step("test", "");
const tests = b.addTest(.{ const tests = b.addTest(.{
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("src/obj_loader.zig"), .root_source_file = b.path("src/obj_loader.zig"),
.link_libc = true, .link_libc = true,
}), }),

17
lib/ozz/build.zig vendored
View File

@ -21,6 +21,7 @@
// ozz_animation_offline_fbx -- fbx importing, requires linking wiht fbx sdk... maybe i dont want this... fuck adobe // ozz_animation_offline_fbx -- fbx importing, requires linking wiht fbx sdk... maybe i dont want this... fuck adobe
const std = @import("std"); const std = @import("std");
const bh = @import("bh");
const Build = std.Build; const Build = std.Build;
const LazyPath = LazyPath; const LazyPath = LazyPath;
@ -142,16 +143,14 @@ pub const GltfToOzz = struct {
}; };
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{}); const opts = bh.declareOptions(b);
const target = b.standardTargetOptions(.{});
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false;
const ozz_cpp = b.addLibrary(.{ const ozz_cpp = b.addLibrary(.{
.linkage = if (static_build) .static else .dynamic, .linkage = if (opts.static_build) .static else .dynamic,
.name = "ozz_cpp", .name = "ozz_cpp",
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
}), }),
}); });
@ -161,7 +160,7 @@ pub fn build(b: *std.Build) void {
ozz_cpp.addIncludePath(b.path("ozz-animation/src")); ozz_cpp.addIncludePath(b.path("ozz-animation/src"));
ozz_cpp.linkLibC(); ozz_cpp.linkLibC();
if (target.result.abi != .msvc) if (opts.target.result.abi != .msvc)
ozz_cpp.linkLibCpp(); ozz_cpp.linkLibCpp();
const src_dir = "ozz-animation/src/"; const src_dir = "ozz-animation/src/";
@ -208,8 +207,8 @@ pub fn build(b: *std.Build) void {
.name = "ozz-tests", .name = "ozz-tests",
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.root_source_file = b.path("tests/test.zig"), .root_source_file = b.path("tests/test.zig"),
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
}), }),
}); });
b.installArtifact(tests); b.installArtifact(tests);

14
lib/p2/build.zig vendored
View File

@ -1,22 +1,20 @@
const std = @import("std"); const std = @import("std");
const bh = @import("bh");
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const opts = bh.declareOptions(b);
const optimize = b.standardOptimizeOption(.{});
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse true;
_ = static_build;
const mod = b.addModule("p2", .{ const mod = b.addModule("p2", .{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("src/p2.zig"), .root_source_file = b.path("src/p2.zig"),
}); });
const test_step = b.step("test", "test p2"); const test_step = b.step("test", "test p2");
const tests = b.addTest(.{ const tests = b.addTest(.{
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("src/p2.zig"), .root_source_file = b.path("src/p2.zig"),
}), }),
// .link_libc = true, // .link_libc = true,

16
lib/packer/build.zig vendored
View File

@ -1,16 +1,14 @@
const std = @import("std"); const std = @import("std");
const bh = @import("bh");
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const opts = bh.declareOptions(b);
const optimize = b.standardOptimizeOption(.{});
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; const p2dep = b.dependency("p2", .{ .target = opts.target, .optimize = opts.optimize, .static_build = opts.static_build });
const p2dep = b.dependency("p2", .{ .target = target, .optimize = optimize, .static_build = static_build });
const mod = b.addModule("packer", .{ const mod = b.addModule("packer", .{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("src/packer.zig"), .root_source_file = b.path("src/packer.zig"),
}); });
@ -19,8 +17,8 @@ pub fn build(b: *std.Build) void {
const test_exe = b.addTest(.{ const test_exe = b.addTest(.{
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("tests/test.zig"), .root_source_file = b.path("tests/test.zig"),
}), }),
}); });

38
lib/sdl3/build.zig vendored
View File

@ -1,4 +1,5 @@
const std = @import("std"); const std = @import("std");
const bh = @import("bh");
pub fn addShaderDefinition( pub fn addShaderDefinition(
b: *std.Build, b: *std.Build,
@ -48,38 +49,35 @@ pub fn shaderDefintion(
} }
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const opts = bh.declareOptions(b);
const optimize = b.standardOptimizeOption(.{});
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; const preferred_linkage: std.builtin.LinkMode = if (opts.static_build) .static else .dynamic;
const preferred_linkage: std.builtin.LinkMode = if (static_build) .static else .dynamic;
const sdl_dep = b.dependency("sdl", .{ const sdl_dep = b.dependency("sdl", .{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.preferred_linkage = preferred_linkage, .preferred_linkage = preferred_linkage,
}); });
const sdl3_lib = sdl_dep.artifact("SDL3"); const sdl3_lib = sdl_dep.artifact("SDL3");
const sdl3_fwd = b.addModule("SDL3", .{ const sdl3_fwd = b.addModule("SDL3", .{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("src/sdl3_lib_fwd.zig"), .root_source_file = b.path("src/sdl3_lib_fwd.zig"),
}); });
sdl3_fwd.linkLibrary(sdl3_lib); sdl3_fwd.linkLibrary(sdl3_lib);
const mod = b.addModule("sdl3", .{ const mod = b.addModule("sdl3", .{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("src/sdl3.zig"), .root_source_file = b.path("src/sdl3.zig"),
}); });
const shaderTypes = b.dependency("shaderTypes", .{ const shaderTypes = b.dependency("shaderTypes", .{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
}); });
mod.addImport("shaderTypes", shaderTypes.module("shaderTypes")); mod.addImport("shaderTypes", shaderTypes.module("shaderTypes"));
@ -90,8 +88,8 @@ pub fn build(b: *std.Build) void {
const tests2 = b.addExecutable(.{ const tests2 = b.addExecutable(.{
.name = "hello-sdl", .name = "hello-sdl",
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("src/samples/compiletest.zig"), .root_source_file = b.path("src/samples/compiletest.zig"),
.link_libc = true, .link_libc = true,
}), }),
@ -101,8 +99,8 @@ pub fn build(b: *std.Build) void {
const tests = b.addExecutable(.{ const tests = b.addExecutable(.{
.name = "hello-triangle", .name = "hello-triangle",
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("src/samples/hello-triangle.zig"), .root_source_file = b.path("src/samples/hello-triangle.zig"),
.link_libc = true, .link_libc = true,
}), }),
@ -112,8 +110,8 @@ pub fn build(b: *std.Build) void {
const hello_window_exe = b.addExecutable(.{ const hello_window_exe = b.addExecutable(.{
.name = "hello-window", .name = "hello-window",
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("src/samples/hello-window.zig"), .root_source_file = b.path("src/samples/hello-window.zig"),
.link_libc = true, .link_libc = true,
}), }),
@ -124,7 +122,7 @@ pub fn build(b: *std.Build) void {
tests.root_module.addImport("sdl3", mod); tests.root_module.addImport("sdl3", mod);
const vertexDefinitions = addShaderDefinition(b, ".", target, optimize, "hello-triangle.vert", b.path("content/hello-triangle.vert.json")); const vertexDefinitions = addShaderDefinition(b, ".", opts.target, opts.optimize, "hello-triangle.vert", b.path("content/hello-triangle.vert.json"));
tests.root_module.addImport("hello-triangle.vert", vertexDefinitions); tests.root_module.addImport("hello-triangle.vert", vertexDefinitions);
const runArtifact = b.addRunArtifact(tests); const runArtifact = b.addRunArtifact(tests);

View File

@ -1,15 +1,12 @@
const std = @import("std"); const std = @import("std");
const bh = @import("bh");
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const opts = bh.declareOptions(b);
const optimize = b.standardOptimizeOption(.{});
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false;
_ = static_build;
const mod = b.addModule("shaderTypes", .{ const mod = b.addModule("shaderTypes", .{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("shaderTypes.zig"), .root_source_file = b.path("shaderTypes.zig"),
}); });

View File

@ -1,7 +1,9 @@
.{ .{
.name = .shaderTypes, .name = .shaderTypes,
.version = "0.0.0", .version = "0.0.0",
.dependencies = .{}, .dependencies = .{
.bh = .{ .path = "../../bh" },
},
.paths = .{ .paths = .{
"", "",
}, },

View File

@ -1,15 +1,15 @@
const std = @import("std"); const std = @import("std");
const bh = @import("bh");
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const opts = bh.declareOptions(b);
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "spvReflect2", .name = "spvReflect2",
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.root_source_file = b.path("spvReflect2.zig"), .root_source_file = b.path("spvReflect2.zig"),
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
}), }),
}); });

11
lib/sdl3/spvreflect/build.zig.zon vendored Normal file
View File

@ -0,0 +1,11 @@
.{
.name = .spvreflect,
.version = "0.0.0",
.dependencies = .{
.bh = .{ .path = "../../bh" },
},
.paths = .{
"",
},
.fingerprint = 0x77801c18119671a4,
}

20
lib/spng/build.zig vendored
View File

@ -1,17 +1,15 @@
const std = @import("std"); const std = @import("std");
const bh = @import("bh");
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const opts = bh.declareOptions(b);
const optimize = b.standardOptimizeOption(.{});
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false;
const spng_c = b.addLibrary(.{ const spng_c = b.addLibrary(.{
.linkage = if (static_build) .static else .dynamic, .linkage = if (opts.static_build) .static else .dynamic,
.name = "spng_c", .name = "spng_c",
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.optimize = optimize, .optimize = opts.optimize,
.target = target, .target = opts.target,
.link_libc = true, .link_libc = true,
}), }),
}); });
@ -24,8 +22,8 @@ pub fn build(b: *std.Build) void {
spng_c.root_module.addCMacro("SPNG_USE_MINIZ", "1"); spng_c.root_module.addCMacro("SPNG_USE_MINIZ", "1");
const mod = b.addModule("spng", .{ const mod = b.addModule("spng", .{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("src/spng.zig"), .root_source_file = b.path("src/spng.zig"),
}); });
@ -38,8 +36,8 @@ pub fn build(b: *std.Build) void {
const test_step = b.step("test", "run unit tests for spng"); const test_step = b.step("test", "run unit tests for spng");
const tests = b.addTest(.{ const tests = b.addTest(.{
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("src/spng.zig"), .root_source_file = b.path("src/spng.zig"),
.link_libc = true, .link_libc = true,
}), }),

View File

@ -1,22 +1,22 @@
const std = @import("std"); const std = @import("std");
const bh = @import("bh");
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const opts = bh.declareOptions(b);
const optimize = b.standardOptimizeOption(.{});
const theorafile = b.addModule( const theorafile = b.addModule(
"theorafile", "theorafile",
.{ .{
.optimize = optimize, .optimize = opts.optimize,
.target = target, .target = opts.target,
.root_source_file = b.path("theorafile.zig"), .root_source_file = b.path("theorafile.zig"),
.link_libc = true, .link_libc = true,
}, },
); );
const sdl_dep = b.dependency("sdl", .{ const sdl_dep = b.dependency("sdl", .{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
}); });
const sdl_lib = sdl_dep.artifact("SDL3"); const sdl_lib = sdl_dep.artifact("SDL3");
@ -99,8 +99,8 @@ pub fn build(b: *std.Build) void {
const tests = b.addExecutable(.{ const tests = b.addExecutable(.{
.name = "test", .name = "test",
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.link_libc = true, .link_libc = true,
.root_source_file = b.path("sdl3test/sdl3test.zig"), .root_source_file = b.path("sdl3test/sdl3test.zig"),
}), }),

22
lib/tracy/build.zig vendored
View File

@ -1,13 +1,11 @@
const std = @import("std"); const std = @import("std");
const bh = @import("bh");
const tracy_path = "tracy-0.10/public"; const tracy_path = "tracy-0.10/public";
const tracy_path_include = tracy_path ++ "/tracy"; const tracy_path_include = tracy_path ++ "/tracy";
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const opts = bh.declareOptions(b);
const optimize = b.standardOptimizeOption(.{});
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false;
_ = static_build;
//const tracy_enabled = b.option(bool, "tracy", "Enables tracy integration") orelse false; //const tracy_enabled = b.option(bool, "tracy", "Enables tracy integration") orelse false;
@ -18,8 +16,8 @@ pub fn build(b: *std.Build) void {
// std.debug.print("tracy enabled {s}\n", .{if (tracy_enabled) "true" else "false"}); // std.debug.print("tracy enabled {s}\n", .{if (tracy_enabled) "true" else "false"});
const mod = b.addModule("tracy", .{ const mod = b.addModule("tracy", .{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("tracy.zig"), .root_source_file = b.path("tracy.zig"),
.link_libc = tracy_enabled, .link_libc = tracy_enabled,
.link_libcpp = tracy_enabled, .link_libcpp = tracy_enabled,
@ -39,7 +37,7 @@ pub fn build(b: *std.Build) void {
}, },
}); });
if (target.result.os.tag == .windows) { if (opts.target.result.os.tag == .windows) {
mod.linkSystemLibrary("Advapi32", .{}); mod.linkSystemLibrary("Advapi32", .{});
mod.linkSystemLibrary("User32", .{}); mod.linkSystemLibrary("User32", .{});
mod.linkSystemLibrary("Ws2_32", .{}); mod.linkSystemLibrary("Ws2_32", .{});
@ -47,16 +45,16 @@ pub fn build(b: *std.Build) void {
} }
} }
const opts = b.addOptions(); const build_opts = b.addOptions();
opts.addOption(bool, "tracy_enabled", tracy_enabled); build_opts.addOption(bool, "tracy_enabled", tracy_enabled);
mod.addOptions("build_options", opts); mod.addOptions("build_options", build_opts);
// ========== tests ============= // ========== tests =============
const test_step = b.step("test", "run unit tests for tracy"); const test_step = b.step("test", "run unit tests for tracy");
const tests = b.addTest(.{ const tests = b.addTest(.{
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("tracy_test.zig"), .root_source_file = b.path("tracy_test.zig"),
}), }),
}); });

17
lib/watcher/build.zig vendored
View File

@ -1,15 +1,12 @@
const std = @import("std"); const std = @import("std");
const bh = @import("bh");
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const opts = bh.declareOptions(b);
const optimize = b.standardOptimizeOption(.{});
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false;
_ = static_build;
const mod = b.addModule("watcher", .{ const mod = b.addModule("watcher", .{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("src/watcher.zig"), .root_source_file = b.path("src/watcher.zig"),
.link_libc = true, .link_libc = true,
.link_libcpp = true, .link_libcpp = true,
@ -17,7 +14,7 @@ pub fn build(b: *std.Build) void {
mod.addCSourceFile(.{ .file = b.path("src/watcher.cpp") }); mod.addCSourceFile(.{ .file = b.path("src/watcher.cpp") });
if (target.result.os.tag == .macos) { if (opts.target.result.os.tag == .macos) {
mod.linkFramework("CoreFoundation", .{}); mod.linkFramework("CoreFoundation", .{});
mod.linkFramework("CoreServices", .{}); mod.linkFramework("CoreServices", .{});
} }
@ -26,8 +23,8 @@ pub fn build(b: *std.Build) void {
const test_exe = b.addTest(.{ const test_exe = b.addTest(.{
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("tests/test.zig"), .root_source_file = b.path("tests/test.zig"),
}), }),
}); });

11
lib/zgltf/build.zig vendored
View File

@ -1,16 +1,13 @@
const std = @import("std"); const std = @import("std");
const bh = @import("bh");
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const opts = bh.declareOptions(b);
const optimize = b.standardOptimizeOption(.{});
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false;
_ = static_build;
const mod = b.addModule("zgltf", .{ const mod = b.addModule("zgltf", .{
.root_source_file = b.path("src/zgltf.zig"), .root_source_file = b.path("src/zgltf.zig"),
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
}); });
const tests = b.addTest(.{ const tests = b.addTest(.{

14
lib/zmath/build.zig vendored
View File

@ -1,22 +1,20 @@
const std = @import("std"); const std = @import("std");
const bh = @import("bh");
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const opts = bh.declareOptions(b);
const optimize = b.standardOptimizeOption(.{});
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false;
_ = static_build;
const mod = b.addModule("zmath", .{ const mod = b.addModule("zmath", .{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("zmath.zig"), .root_source_file = b.path("zmath.zig"),
}); });
const test_step = b.step("test", "runs tests for zmath"); const test_step = b.step("test", "runs tests for zmath");
const tests = b.addTest(.{ const tests = b.addTest(.{
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
.root_source_file = b.path("zmath.zig"), .root_source_file = b.path("zmath.zig"),
.link_libc = true, .link_libc = true,
}), }),

View File

@ -1,4 +1,5 @@
const std = @import("std"); const std = @import("std");
const bh = @import("bh");
fn addMacros(module: *std.Build.Module, options: anytype) void { fn addMacros(module: *std.Build.Module, options: anytype) void {
if (options.enable_cross_platform_determinism) if (options.enable_cross_platform_determinism)
@ -12,8 +13,7 @@ fn addMacros(module: *std.Build.Module, options: anytype) void {
} }
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{}); const opts = bh.declareOptions(b);
const target = b.standardTargetOptions(.{});
const options = .{ const options = .{
.use_double_precision = b.option( .use_double_precision = b.option(
@ -25,7 +25,7 @@ pub fn build(b: *std.Build) void {
bool, bool,
"enable_asserts", "enable_asserts",
"Enable assertions", "Enable assertions",
) orelse (optimize == .Debug), ) orelse (opts.optimize == .Debug),
.enable_cross_platform_determinism = b.option( .enable_cross_platform_determinism = b.option(
bool, bool,
"enable_cross_platform_determinism", "enable_cross_platform_determinism",
@ -48,8 +48,6 @@ pub fn build(b: *std.Build) void {
) orelse true, ) orelse true,
}; };
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse true;
const user_extensions = b.option( const user_extensions = b.option(
[]const std.Build.LazyPath, []const std.Build.LazyPath,
"user_extensions", "user_extensions",
@ -73,14 +71,14 @@ pub fn build(b: *std.Build) void {
const joltc = b.addLibrary(.{ const joltc = b.addLibrary(.{
.name = "joltc", .name = "joltc",
.linkage = if (!static_build) .dynamic else .static, .linkage = if (!opts.static_build) .dynamic else .static,
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
}), }),
}); });
if (!static_build and target.result.os.tag == .windows) if (!opts.static_build and opts.target.result.os.tag == .windows)
joltc.root_module.addCMacro("JPC_API", "extern __declspec(dllexport)"); joltc.root_module.addCMacro("JPC_API", "extern __declspec(dllexport)");
b.installArtifact(joltc); b.installArtifact(joltc);
@ -88,7 +86,7 @@ pub fn build(b: *std.Build) void {
joltc.addIncludePath(b.path("libs")); joltc.addIncludePath(b.path("libs"));
joltc.addIncludePath(b.path("libs/JoltC")); joltc.addIncludePath(b.path("libs/JoltC"));
joltc.linkLibC(); joltc.linkLibC();
if (target.result.abi != .msvc) { if (opts.target.result.abi != .msvc) {
joltc.linkLibCpp(); joltc.linkLibCpp();
} else { } else {
joltc.linkSystemLibrary("advapi32"); joltc.linkSystemLibrary("advapi32");
@ -257,14 +255,14 @@ pub fn build(b: *std.Build) void {
.name = "zphysics-tests", .name = "zphysics-tests",
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.root_source_file = b.path("src/zphysics.zig"), .root_source_file = b.path("src/zphysics.zig"),
.target = target, .target = opts.target,
.optimize = optimize, .optimize = opts.optimize,
}), }),
}); });
b.installArtifact(tests); b.installArtifact(tests);
// TODO: Problems with LTO on Windows. // TODO: Problems with LTO on Windows.
if (target.result.os.tag == .windows) { if (opts.target.result.os.tag == .windows) {
tests.want_lto = false; tests.want_lto = false;
} }