From cc00fb076e118d7066cb7a503cb645000c5ffdd1 Mon Sep 17 00:00:00 2001 From: peterino2 Date: Fri, 28 Nov 2025 20:14:56 -0800 Subject: [PATCH] switched all builds to bh.declareOptions --- lib/.claude/settings.local.json | 11 +++++++++ lib/bh/build.zig | 17 +++++++++++++ lib/cimgui/build.zig | 20 +++++++--------- lib/enet/build.zig | 28 ++++++++++------------ lib/lua/build.zig | 23 +++++++++--------- lib/miniaudio/build.zig | 17 +++++++------ lib/nfd/build.zig | 21 ++++++++--------- lib/objLoader/build.zig | 14 +++++------ lib/ozz/build.zig | 17 +++++++------ lib/p2/build.zig | 14 +++++------ lib/packer/build.zig | 16 ++++++------- lib/sdl3/build.zig | 38 ++++++++++++++---------------- lib/sdl3/shaderTypes/build.zig | 11 ++++----- lib/sdl3/shaderTypes/build.zig.zon | 4 +++- lib/sdl3/spvreflect/build.zig | 8 +++---- lib/sdl3/spvreflect/build.zig.zon | 11 +++++++++ lib/spng/build.zig | 20 +++++++--------- lib/theoratest/build.zig | 16 ++++++------- lib/tracy/build.zig | 22 ++++++++--------- lib/watcher/build.zig | 17 ++++++------- lib/zgltf/build.zig | 11 ++++----- lib/zmath/build.zig | 14 +++++------ lib/zphysics/build.zig | 24 +++++++++---------- 23 files changed, 201 insertions(+), 193 deletions(-) create mode 100644 lib/.claude/settings.local.json create mode 100644 lib/sdl3/spvreflect/build.zig.zon diff --git a/lib/.claude/settings.local.json b/lib/.claude/settings.local.json new file mode 100644 index 0000000..bb0ea4a --- /dev/null +++ b/lib/.claude/settings.local.json @@ -0,0 +1,11 @@ +{ + "permissions": { + "allow": [ + "Bash(cat:*)", + "Bash(git log:*)", + "Bash(zig build:*)" + ], + "deny": [], + "ask": [] + } +} diff --git a/lib/bh/build.zig b/lib/bh/build.zig index 87adf74..a8d1723 100644 --- a/lib/bh/build.zig +++ b/lib/bh/build.zig @@ -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 { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); diff --git a/lib/cimgui/build.zig b/lib/cimgui/build.zig index 1a4e2ce..2ef8d1c 100644 --- a/lib/cimgui/build.zig +++ b/lib/cimgui/build.zig @@ -1,15 +1,13 @@ const std = @import("std"); +const bh = @import("bh"); // very tiny, not intended to build anything just to run tests linked with libc pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); - const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - _ = static_build; + const opts = bh.declareOptions(b); const mod = b.addModule("cimgui", .{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .link_libc = true, .root_source_file = b.path("src/cimgui.zig"), }); @@ -22,14 +20,14 @@ pub fn build(b: *std.Build) void { const cimgui = b.addLibrary(.{ .name = "cimgui", .root_module = b.createModule(.{ - .optimize = optimize, - .target = target, + .optimize = opts.optimize, + .target = opts.target, }), }); cimgui.linkLibC(); - if (target.result.abi != .msvc) + if (opts.target.result.abi != .msvc) cimgui.linkLibCpp(); 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 tests = b.addTest(.{ .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("tests/tests.zig"), }), }); diff --git a/lib/enet/build.zig b/lib/enet/build.zig index 3efb5d3..88d4d25 100644 --- a/lib/enet/build.zig +++ b/lib/enet/build.zig @@ -1,10 +1,8 @@ const std = @import("std"); +const bh = @import("bh"); pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); - const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - _ = static_build; + const opts = bh.declareOptions(b); // am i good to always have enet as static? // const enet = if (true) b.addStaticLibrary(.{ @@ -21,8 +19,8 @@ pub fn build(b: *std.Build) void { .name = "enet_c", .linkage = .static, .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, }), }); @@ -47,7 +45,7 @@ pub fn build(b: *std.Build) void { enet.addIncludePath(b.path("enet-1.3.18/include")); // Platform-specific configuration - switch (target.result.os.tag) { + switch (opts.target.result.os.tag) { .windows => { enet.linkSystemLibrary("ws2_32"); enet.linkSystemLibrary("winmm"); @@ -62,8 +60,8 @@ pub fn build(b: *std.Build) void { b.installArtifact(enet); const mod = b.addModule("enet", .{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("src/enet.zig"), .link_libc = true, }); @@ -75,8 +73,8 @@ pub fn build(b: *std.Build) void { const tests = b.addTest(.{ .root_module = b.createModule(.{ .link_libc = true, - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("src/tests.zig"), }), }); @@ -91,8 +89,8 @@ pub fn build(b: *std.Build) void { .name = "test-server", .root_module = b.createModule(.{ .root_source_file = b.path("src/test_server.zig"), - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, }), }); test_server.root_module.addImport("enet", mod); @@ -103,8 +101,8 @@ pub fn build(b: *std.Build) void { .name = "test-client", .root_module = b.createModule(.{ .root_source_file = b.path("src/test_client.zig"), - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, }), }); test_client.root_module.addImport("enet", mod); diff --git a/lib/lua/build.zig b/lib/lua/build.zig index 35af690..37d729e 100644 --- a/lib/lua/build.zig +++ b/lib/lua/build.zig @@ -1,23 +1,22 @@ const std = @import("std"); +const bh = @import("bh"); pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); - const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; + const opts = bh.declareOptions(b); const mod = b.addModule("lua", .{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("src/lua.zig"), .link_libc = true, }); const luac = b.addLibrary(.{ .name = "luac", - .linkage = if (static_build) .static else .dynamic, + .linkage = if (opts.static_build) .static else .dynamic, .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .link_libc = true, }), }); @@ -64,9 +63,9 @@ pub fn build(b: *std.Build) void { 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") }); - if (target.result.abi != .msvc) + if (opts.target.result.abi != .msvc) luac.linkLibCpp(); luac.linkLibC(); } else { @@ -85,8 +84,8 @@ pub fn build(b: *std.Build) void { const tests = b.addExecutable(.{ .name = "run-lua", .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("test/test-lua.zig"), .link_libc = true, }), diff --git a/lib/miniaudio/build.zig b/lib/miniaudio/build.zig index a4b98b5..db9c0b9 100644 --- a/lib/miniaudio/build.zig +++ b/lib/miniaudio/build.zig @@ -1,16 +1,15 @@ const std = @import("std"); +const bh = @import("bh"); pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); - const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; + const opts = bh.declareOptions(b); const miniaudio_c = b.addLibrary(.{ .name = "miniaudio_c", - .linkage = if (static_build) .static else .dynamic, + .linkage = if (opts.static_build) .static else .dynamic, .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .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.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.addIncludePath(b.path("./include")); @@ -28,8 +27,8 @@ pub fn build(b: *std.Build) void { const test_step = b.step("test", ""); const tests = b.addTest(.{ .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("src/miniaudio-test.zig"), .link_libc = true, }), diff --git a/lib/nfd/build.zig b/lib/nfd/build.zig index b4e1b17..52312a2 100644 --- a/lib/nfd/build.zig +++ b/lib/nfd/build.zig @@ -1,13 +1,12 @@ const std = @import("std"); +const bh = @import("bh"); pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); - const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; + const opts = bh.declareOptions(b); const mod = b.addModule("nfd", .{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("src/nfd.zig"), .link_libc = true, }); @@ -19,19 +18,19 @@ pub fn build(b: *std.Build) void { mod.addIncludePath(b.path("include")); - if (target.result.os.tag == .macos) { + if (opts.target.result.os.tag == .macos) { mod.addCSourceFile(.{ .file = b.path("src/nfd_cocoa.m"), .flags = &.{}, }); mod.linkFramework("AppKit", .{}); - } else if (target.result.os.tag == .windows) { + } else if (opts.target.result.os.tag == .windows) { mod.addCSourceFile(.{ .file = b.path("src/nfd_win.cpp"), .flags = &.{}, }); mod.linkSystemLibrary("ole32", .{}); - } else if (target.result.os.tag == .linux) { + } else if (opts.target.result.os.tag == .linux) { // mod.addCSourceFile(.{ // .file = b.path("src/nfd_gtk.c"), // .flags = &.{}, @@ -47,7 +46,7 @@ pub fn build(b: *std.Build) void { // 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"); mod.addImport("p2", p2mod); @@ -55,8 +54,8 @@ pub fn build(b: *std.Build) void { const test_step = b.step("test", ""); const tests = b.addTest(.{ .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("src/nfd.zig"), .link_libc = true, }), diff --git a/lib/objLoader/build.zig b/lib/objLoader/build.zig index 381b62f..87f7250 100644 --- a/lib/objLoader/build.zig +++ b/lib/objLoader/build.zig @@ -1,22 +1,20 @@ const std = @import("std"); +const bh = @import("bh"); pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); - const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - _ = static_build; + const opts = bh.declareOptions(b); const mod = b.addModule("objLoader", .{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("src/obj_loader.zig"), }); const test_step = b.step("test", ""); const tests = b.addTest(.{ .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("src/obj_loader.zig"), .link_libc = true, }), diff --git a/lib/ozz/build.zig b/lib/ozz/build.zig index c206499..bc9249f 100644 --- a/lib/ozz/build.zig +++ b/lib/ozz/build.zig @@ -21,6 +21,7 @@ // ozz_animation_offline_fbx -- fbx importing, requires linking wiht fbx sdk... maybe i dont want this... fuck adobe const std = @import("std"); +const bh = @import("bh"); const Build = std.Build; const LazyPath = LazyPath; @@ -142,16 +143,14 @@ pub const GltfToOzz = struct { }; pub fn build(b: *std.Build) void { - const optimize = b.standardOptimizeOption(.{}); - const target = b.standardTargetOptions(.{}); - const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; + const opts = bh.declareOptions(b); const ozz_cpp = b.addLibrary(.{ - .linkage = if (static_build) .static else .dynamic, + .linkage = if (opts.static_build) .static else .dynamic, .name = "ozz_cpp", .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, }), }); @@ -161,7 +160,7 @@ pub fn build(b: *std.Build) void { ozz_cpp.addIncludePath(b.path("ozz-animation/src")); ozz_cpp.linkLibC(); - if (target.result.abi != .msvc) + if (opts.target.result.abi != .msvc) ozz_cpp.linkLibCpp(); const src_dir = "ozz-animation/src/"; @@ -208,8 +207,8 @@ pub fn build(b: *std.Build) void { .name = "ozz-tests", .root_module = b.createModule(.{ .root_source_file = b.path("tests/test.zig"), - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, }), }); b.installArtifact(tests); diff --git a/lib/p2/build.zig b/lib/p2/build.zig index 26a3090..fe20d2c 100644 --- a/lib/p2/build.zig +++ b/lib/p2/build.zig @@ -1,22 +1,20 @@ const std = @import("std"); +const bh = @import("bh"); pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); - const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse true; - _ = static_build; + const opts = bh.declareOptions(b); const mod = b.addModule("p2", .{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("src/p2.zig"), }); const test_step = b.step("test", "test p2"); const tests = b.addTest(.{ .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("src/p2.zig"), }), // .link_libc = true, diff --git a/lib/packer/build.zig b/lib/packer/build.zig index eeb7ee2..e6b98e3 100644 --- a/lib/packer/build.zig +++ b/lib/packer/build.zig @@ -1,16 +1,14 @@ const std = @import("std"); +const bh = @import("bh"); pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); + const opts = bh.declareOptions(b); - const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - - 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 mod = b.addModule("packer", .{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("src/packer.zig"), }); @@ -19,8 +17,8 @@ pub fn build(b: *std.Build) void { const test_exe = b.addTest(.{ .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("tests/test.zig"), }), }); diff --git a/lib/sdl3/build.zig b/lib/sdl3/build.zig index cbcb6d1..81121b2 100644 --- a/lib/sdl3/build.zig +++ b/lib/sdl3/build.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const bh = @import("bh"); pub fn addShaderDefinition( b: *std.Build, @@ -48,38 +49,35 @@ pub fn shaderDefintion( } pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); + const opts = bh.declareOptions(b); - const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - - const preferred_linkage: std.builtin.LinkMode = if (static_build) .static else .dynamic; + const preferred_linkage: std.builtin.LinkMode = if (opts.static_build) .static else .dynamic; const sdl_dep = b.dependency("sdl", .{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .preferred_linkage = preferred_linkage, }); const sdl3_lib = sdl_dep.artifact("SDL3"); const sdl3_fwd = b.addModule("SDL3", .{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("src/sdl3_lib_fwd.zig"), }); sdl3_fwd.linkLibrary(sdl3_lib); const mod = b.addModule("sdl3", .{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("src/sdl3.zig"), }); const shaderTypes = b.dependency("shaderTypes", .{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, }); mod.addImport("shaderTypes", shaderTypes.module("shaderTypes")); @@ -90,8 +88,8 @@ pub fn build(b: *std.Build) void { const tests2 = b.addExecutable(.{ .name = "hello-sdl", .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("src/samples/compiletest.zig"), .link_libc = true, }), @@ -101,8 +99,8 @@ pub fn build(b: *std.Build) void { const tests = b.addExecutable(.{ .name = "hello-triangle", .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("src/samples/hello-triangle.zig"), .link_libc = true, }), @@ -112,8 +110,8 @@ pub fn build(b: *std.Build) void { const hello_window_exe = b.addExecutable(.{ .name = "hello-window", .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("src/samples/hello-window.zig"), .link_libc = true, }), @@ -124,7 +122,7 @@ pub fn build(b: *std.Build) void { 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); const runArtifact = b.addRunArtifact(tests); diff --git a/lib/sdl3/shaderTypes/build.zig b/lib/sdl3/shaderTypes/build.zig index 394be03..4488cb7 100644 --- a/lib/sdl3/shaderTypes/build.zig +++ b/lib/sdl3/shaderTypes/build.zig @@ -1,15 +1,12 @@ const std = @import("std"); +const bh = @import("bh"); pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); - - const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - _ = static_build; + const opts = bh.declareOptions(b); const mod = b.addModule("shaderTypes", .{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("shaderTypes.zig"), }); diff --git a/lib/sdl3/shaderTypes/build.zig.zon b/lib/sdl3/shaderTypes/build.zig.zon index 16e4290..94ab578 100644 --- a/lib/sdl3/shaderTypes/build.zig.zon +++ b/lib/sdl3/shaderTypes/build.zig.zon @@ -1,7 +1,9 @@ .{ .name = .shaderTypes, .version = "0.0.0", - .dependencies = .{}, + .dependencies = .{ + .bh = .{ .path = "../../bh" }, + }, .paths = .{ "", }, diff --git a/lib/sdl3/spvreflect/build.zig b/lib/sdl3/spvreflect/build.zig index ff1de16..0d5bcba 100644 --- a/lib/sdl3/spvreflect/build.zig +++ b/lib/sdl3/spvreflect/build.zig @@ -1,15 +1,15 @@ const std = @import("std"); +const bh = @import("bh"); pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); + const opts = bh.declareOptions(b); const exe = b.addExecutable(.{ .name = "spvReflect2", .root_module = b.createModule(.{ .root_source_file = b.path("spvReflect2.zig"), - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, }), }); diff --git a/lib/sdl3/spvreflect/build.zig.zon b/lib/sdl3/spvreflect/build.zig.zon new file mode 100644 index 0000000..2a16ab6 --- /dev/null +++ b/lib/sdl3/spvreflect/build.zig.zon @@ -0,0 +1,11 @@ +.{ + .name = .spvreflect, + .version = "0.0.0", + .dependencies = .{ + .bh = .{ .path = "../../bh" }, + }, + .paths = .{ + "", + }, + .fingerprint = 0x77801c18119671a4, +} diff --git a/lib/spng/build.zig b/lib/spng/build.zig index 0596e0a..dedf0e5 100644 --- a/lib/spng/build.zig +++ b/lib/spng/build.zig @@ -1,17 +1,15 @@ const std = @import("std"); +const bh = @import("bh"); pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); - - const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; + const opts = bh.declareOptions(b); const spng_c = b.addLibrary(.{ - .linkage = if (static_build) .static else .dynamic, + .linkage = if (opts.static_build) .static else .dynamic, .name = "spng_c", .root_module = b.createModule(.{ - .optimize = optimize, - .target = target, + .optimize = opts.optimize, + .target = opts.target, .link_libc = true, }), }); @@ -24,8 +22,8 @@ pub fn build(b: *std.Build) void { spng_c.root_module.addCMacro("SPNG_USE_MINIZ", "1"); const mod = b.addModule("spng", .{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .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 tests = b.addTest(.{ .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("src/spng.zig"), .link_libc = true, }), diff --git a/lib/theoratest/build.zig b/lib/theoratest/build.zig index 9384b43..39c6204 100644 --- a/lib/theoratest/build.zig +++ b/lib/theoratest/build.zig @@ -1,22 +1,22 @@ const std = @import("std"); +const bh = @import("bh"); pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); + const opts = bh.declareOptions(b); const theorafile = b.addModule( "theorafile", .{ - .optimize = optimize, - .target = target, + .optimize = opts.optimize, + .target = opts.target, .root_source_file = b.path("theorafile.zig"), .link_libc = true, }, ); const sdl_dep = b.dependency("sdl", .{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, }); const sdl_lib = sdl_dep.artifact("SDL3"); @@ -99,8 +99,8 @@ pub fn build(b: *std.Build) void { const tests = b.addExecutable(.{ .name = "test", .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .link_libc = true, .root_source_file = b.path("sdl3test/sdl3test.zig"), }), diff --git a/lib/tracy/build.zig b/lib/tracy/build.zig index 7e80293..79ffac6 100644 --- a/lib/tracy/build.zig +++ b/lib/tracy/build.zig @@ -1,13 +1,11 @@ const std = @import("std"); +const bh = @import("bh"); const tracy_path = "tracy-0.10/public"; const tracy_path_include = tracy_path ++ "/tracy"; pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); - const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - _ = static_build; + const opts = bh.declareOptions(b); //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"}); const mod = b.addModule("tracy", .{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("tracy.zig"), .link_libc = 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("User32", .{}); mod.linkSystemLibrary("Ws2_32", .{}); @@ -47,16 +45,16 @@ pub fn build(b: *std.Build) void { } } - const opts = b.addOptions(); - opts.addOption(bool, "tracy_enabled", tracy_enabled); - mod.addOptions("build_options", opts); + const build_opts = b.addOptions(); + build_opts.addOption(bool, "tracy_enabled", tracy_enabled); + mod.addOptions("build_options", build_opts); // ========== tests ============= const test_step = b.step("test", "run unit tests for tracy"); const tests = b.addTest(.{ .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("tracy_test.zig"), }), }); diff --git a/lib/watcher/build.zig b/lib/watcher/build.zig index dd3fcb4..6201ea1 100644 --- a/lib/watcher/build.zig +++ b/lib/watcher/build.zig @@ -1,15 +1,12 @@ const std = @import("std"); +const bh = @import("bh"); pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); - - const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - _ = static_build; + const opts = bh.declareOptions(b); const mod = b.addModule("watcher", .{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("src/watcher.zig"), .link_libc = true, .link_libcpp = true, @@ -17,7 +14,7 @@ pub fn build(b: *std.Build) void { 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("CoreServices", .{}); } @@ -26,8 +23,8 @@ pub fn build(b: *std.Build) void { const test_exe = b.addTest(.{ .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("tests/test.zig"), }), }); diff --git a/lib/zgltf/build.zig b/lib/zgltf/build.zig index ee9f9c8..235cf0e 100644 --- a/lib/zgltf/build.zig +++ b/lib/zgltf/build.zig @@ -1,16 +1,13 @@ const std = @import("std"); +const bh = @import("bh"); pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); - - const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - _ = static_build; + const opts = bh.declareOptions(b); const mod = b.addModule("zgltf", .{ .root_source_file = b.path("src/zgltf.zig"), - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, }); const tests = b.addTest(.{ diff --git a/lib/zmath/build.zig b/lib/zmath/build.zig index 772156b..e25d0a5 100644 --- a/lib/zmath/build.zig +++ b/lib/zmath/build.zig @@ -1,22 +1,20 @@ const std = @import("std"); +const bh = @import("bh"); pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); - const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - _ = static_build; + const opts = bh.declareOptions(b); const mod = b.addModule("zmath", .{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("zmath.zig"), }); const test_step = b.step("test", "runs tests for zmath"); const tests = b.addTest(.{ .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, .root_source_file = b.path("zmath.zig"), .link_libc = true, }), diff --git a/lib/zphysics/build.zig b/lib/zphysics/build.zig index 53d9082..7598283 100644 --- a/lib/zphysics/build.zig +++ b/lib/zphysics/build.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const bh = @import("bh"); fn addMacros(module: *std.Build.Module, options: anytype) void { 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 { - const optimize = b.standardOptimizeOption(.{}); - const target = b.standardTargetOptions(.{}); + const opts = bh.declareOptions(b); const options = .{ .use_double_precision = b.option( @@ -25,7 +25,7 @@ pub fn build(b: *std.Build) void { bool, "enable_asserts", "Enable assertions", - ) orelse (optimize == .Debug), + ) orelse (opts.optimize == .Debug), .enable_cross_platform_determinism = b.option( bool, "enable_cross_platform_determinism", @@ -48,8 +48,6 @@ pub fn build(b: *std.Build) void { ) orelse true, }; - const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse true; - const user_extensions = b.option( []const std.Build.LazyPath, "user_extensions", @@ -73,14 +71,14 @@ pub fn build(b: *std.Build) void { const joltc = b.addLibrary(.{ .name = "joltc", - .linkage = if (!static_build) .dynamic else .static, + .linkage = if (!opts.static_build) .dynamic else .static, .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = opts.target, + .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)"); 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")); joltc.linkLibC(); - if (target.result.abi != .msvc) { + if (opts.target.result.abi != .msvc) { joltc.linkLibCpp(); } else { joltc.linkSystemLibrary("advapi32"); @@ -257,14 +255,14 @@ pub fn build(b: *std.Build) void { .name = "zphysics-tests", .root_module = b.createModule(.{ .root_source_file = b.path("src/zphysics.zig"), - .target = target, - .optimize = optimize, + .target = opts.target, + .optimize = opts.optimize, }), }); b.installArtifact(tests); // TODO: Problems with LTO on Windows. - if (target.result.os.tag == .windows) { + if (opts.target.result.os.tag == .windows) { tests.want_lto = false; }