From b0d1a81d8493f1e2b5a50d818267e1677aba66e7 Mon Sep 17 00:00:00 2001 From: peterino2 Date: Sun, 9 Nov 2025 23:30:44 -0800 Subject: [PATCH] split between zig and c libraries complete --- CLAUDE.md | 12 ++--- build.zig | 15 +++--- engine/assets/build.zig | 5 +- engine/audio/build.zig | 3 +- engine/core/build.zig | 16 ++++++ engine/core/build.zig.zon | 2 +- engine/imgui/build.zig | 1 + engine/net/build.zig | 3 +- engine/papyrus/build.zig | 15 ++---- engine/papyrus/src/BmpRenderer.zig | 2 +- engine/papyrus/src/Font.zig | 2 +- engine/papyrus/src/papyrus.zig | 2 +- engine/papyrus/tests/testing.zig | 5 +- engine/physics/build.zig | 23 ++++---- engine/platform/build.zig | 21 ++++---- engine/platform/src/platform.zig | 2 +- engine/platform/tests/tests.zig | 2 +- engine/rend/build.zig | 52 +++++++++++-------- engine/sys/build.zig | 25 +++------ engine/sys/src/systemProc.zig | 18 +++---- engine/ui/build.zig | 32 +++++------- lib/bh/build.zig | 6 +-- lib/cimgui/build.zig | 2 +- lib/enet/build.zig | 2 +- lib/lua/build.zig | 2 +- lib/miniaudio/build.zig | 2 +- lib/nfd/build.zig | 2 +- lib/objLoader/build.zig | 2 +- lib/ozz/build.zig | 2 +- lib/p2/build.zig | 2 +- lib/p2/src/p2.zig | 2 +- lib/packer/build.zig | 2 +- lib/sdl3/build.zig | 17 +++--- lib/sdl3/shaderTypes/build.zig | 10 ++++ lib/sdl3/shaderTypes/stubc.zig | 0 lib/spng/build.zig | 2 +- lib/tracy/build.zig | 2 +- lib/watcher/build.zig | 2 +- lib/zgltf/build.zig | 2 +- lib/zmath/build.zig | 2 +- lib/zphysics/build.zig | 2 +- projects/build.zig | 38 ++++++++------ projects/sampleGame/externGame/externGame.zig | 9 +++- 43 files changed, 201 insertions(+), 169 deletions(-) create mode 100644 lib/sdl3/shaderTypes/stubc.zig diff --git a/CLAUDE.md b/CLAUDE.md index f19e46b..f353b78 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -96,12 +96,12 @@ The shader compilation system automatically discovers `.hlsl` files in `engine/* - The build system generates API wrappers automatically for enabled modules - Content directory location is determined by `content.txt` file pointing to `projects/content/` -### MakeModlib Build Helper +### MakeModLib Build Helper -The project uses a custom `MakeModlib` helper function (defined in `lib/bh/build.zig`) to create library modules with consistent patterns: +The project uses a custom `MakeModLib` helper function (defined in `lib/bh/build.zig`) to create library modules with consistent patterns: ```zig -const mylib = bh.MakeModlib(b, .{ +const mylib = bh.MakeModLib(b, .{ .name = "mylib", .target = target, .optimize = optimize, @@ -110,19 +110,19 @@ const mylib = bh.MakeModlib(b, .{ }); ``` -**What MakeModlib creates:** +**What MakeModLib creates:** - A Zig module (`.mod`) for compile-time imports - A library artifact (`.lib`) for linking (static or dynamic based on `static_build` flag) - The library uses an empty stub source file and is intended to carry C dependencies **Usage pattern:** -All libraries using `MakeModlib` follow this pattern in their test executables: +All libraries using `MakeModLib` follow this pattern in their test executables: ```zig tests.root_module.addImport("mylib", mylib.mod); // Import the module tests.root_module.linkLibrary(mylib.lib); // Link the library ``` -**Libraries using MakeModlib:** +**Libraries using MakeModLib:** - `bh`, `cimgui`, `enet`, `lua`, `miniaudio`, `nfd`, `objLoader`, `p2`, `packer`, `spng`, `tracy`, `watcher`, `zgltf`, `zmath` This pattern separates Zig code (in the module) from C/C++ dependencies (in the library), allowing for flexible static/dynamic linking while maintaining consistent module interfaces. diff --git a/build.zig b/build.zig index 26771fc..26f9c62 100644 --- a/build.zig +++ b/build.zig @@ -243,12 +243,12 @@ pub fn addDependencyInstalls(self: *BuildSystem, b: *std.Build, optimize: std.bu const DynamicDepList: []const struct { dep: []const u8, artifact: []const u8 } = &.{ .{ .dep = "sdl3", .artifact = "SDL3" }, - .{ .dep = "spng", .artifact = "spng_c" }, - .{ .dep = "lua", .artifact = "luac" }, - .{ .dep = "miniaudio", .artifact = "miniaudio_c" }, - .{ .dep = "zphysics", .artifact = "joltc" }, + .{ .dep = "spng", .artifact = "spng" }, + .{ .dep = "lua", .artifact = "lua" }, + .{ .dep = "miniaudio", .artifact = "miniaudio" }, + .{ .dep = "zphysics", .artifact = "zphysics" }, // .{ .dep = "enet", .artifact = "enet_c" }, - .{ .dep = "ozz", .artifact = "ozz_cpp" }, + .{ .dep = "ozz", .artifact = "ozz" }, }; // all other modules are disabled by default @@ -551,6 +551,8 @@ pub fn build(b: *std.Build) void { mod.addImport(b.fmt("{s}", .{depName}), modFwd); modFwd.addImport("module", dep.module(depName)); + b.installArtifact(dep.artifact(depName)); + // mod.addImport(depName, dep.module(depName)); } @@ -561,7 +563,7 @@ pub fn build(b: *std.Build) void { .optimize = optimize, .static_build = static_build, }); - const lib = dep.module("SDL3"); + const lib = dep.module("sdl3"); mod.addImport("sdl3_fwd", lib); } @@ -594,6 +596,7 @@ pub fn generateApi(self: *@This(), programName: []const u8, moduleList: []const }); for (moduleList) |modName| { mod.addImport(modName, self.nwdep.module(modName)); + mod.linkLibrary(self.nwdep.artifact(modName)); } const loadStatics = self.generateInstallStaticResources(programName, "content/_shaders") catch unreachable; diff --git a/engine/assets/build.zig b/engine/assets/build.zig index 767d50e..8811cc9 100644 --- a/engine/assets/build.zig +++ b/engine/assets/build.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const core = @import("core").MakeModLib; +const core = @import("core"); const depList = [_][]const u8{ "core", @@ -19,6 +19,7 @@ pub fn build(b: *std.Build) void { }); engineMod.linkModLibs(&depList); + engineMod.install(); const test_step = b.step("test", "run unit tests for assets"); const tests = b.addTest(.{ @@ -29,7 +30,7 @@ pub fn build(b: *std.Build) void { }), }); - tests.root_module.addImport("assets", engineMod); + tests.root_module.addImport("assets", engineMod.mod); const runArtifact = b.addRunArtifact(tests); test_step.dependOn(&runArtifact.step); b.installArtifact(tests); diff --git a/engine/audio/build.zig b/engine/audio/build.zig index 46a4faf..61d0e03 100644 --- a/engine/audio/build.zig +++ b/engine/audio/build.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const core = @import("core").MakeModLib; +const core = @import("core"); const depList = [_][]const u8{ "miniaudio", @@ -20,6 +20,7 @@ pub fn build(b: *std.Build) void { }); engineMod.linkModLibs(&depList); + engineMod.install(); const test_step = b.step("test", "run unit tests for audio"); const tests = b.addTest(.{ diff --git a/engine/core/build.zig b/engine/core/build.zig index fc659fe..de64814 100644 --- a/engine/core/build.zig +++ b/engine/core/build.zig @@ -11,6 +11,21 @@ const dependencyList = [_][]const u8{ "packer", // packer no longer has C deps. }; +pub fn MakeEngineMod(b: *std.Build, name: []const u8) ModLib { + 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 engineMod = MakeModLib(b, .{ + .name = name, + .target = target, + .optimize = optimize, + .static_build = static_build, + }); + + return engineMod; +} + pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); @@ -23,6 +38,7 @@ pub fn build(b: *std.Build) void { .static_build = static_build, }); + engineMod.install(); engineMod.linkModLibs(&dependencyList); const test_step = b.step("test", "run unit tests for core"); diff --git a/engine/core/build.zig.zon b/engine/core/build.zig.zon index 02e2e54..da5792d 100644 --- a/engine/core/build.zig.zon +++ b/engine/core/build.zig.zon @@ -7,7 +7,7 @@ // with -Dtracy = false, this one pulls in no C dependencies .tracy = .{ .path = "../../lib/tracy" }, - .bh = .{.path = "../../lib/bh" }, + .bh = .{ .path = "../../lib/bh" }, // these are zig only .zmath = .{ .path = "../../lib/zmath" }, diff --git a/engine/imgui/build.zig b/engine/imgui/build.zig index 5b5ddd7..1d4dabf 100644 --- a/engine/imgui/build.zig +++ b/engine/imgui/build.zig @@ -21,6 +21,7 @@ pub fn build(b: *std.Build) void { .static_build = static_build, }); + engineMod.install(); engineMod.linkModLibs(&dependencyList); // ========== tests ========== diff --git a/engine/net/build.zig b/engine/net/build.zig index cfd9282..0133c04 100644 --- a/engine/net/build.zig +++ b/engine/net/build.zig @@ -12,12 +12,13 @@ pub fn build(b: *std.Build) void { const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; const engineMod = core.MakeModLib(b, .{ - .name = "imgui", + .name = "net", .target = target, .optimize = optimize, .static_build = static_build, }); + engineMod.install(); engineMod.linkModLibs(&depList); const test_step = b.step("test", "run unit tests for net"); diff --git a/engine/papyrus/build.zig b/engine/papyrus/build.zig index 8bd28cf..f8250f2 100644 --- a/engine/papyrus/build.zig +++ b/engine/papyrus/build.zig @@ -17,17 +17,12 @@ pub fn build(b: *std.Build) void { .optimize = optimize, .static_build = static_build, }); + engineMod.lib.linkLibC(); + engineMod.install(); engineMod.linkModLibs(&depList); engineMod.addIncludePath("src/"); - engineMod.lib.addCSourceFile(b.path("src/compat.cpp")); - - const mod = b.addModule("papyrus", .{ - .target = target, - .optimize = optimize, - .link_libc = true, - .root_source_file = b.path("src/papyrus.zig"), - }); + engineMod.lib.addCSourceFile(.{ .file = b.path("src/compat.cpp"), .flags = &.{} }); // Creates a step for unit testing. const main_tests = b.addTest(.{ @@ -39,9 +34,9 @@ pub fn build(b: *std.Build) void { }), }); - main_tests.root_module.addImport("papyrus", mod); + main_tests.root_module.addImport("papyrus", engineMod.mod); main_tests.root_module.addIncludePath(b.path("src/")); - + main_tests.linkLibrary(engineMod.lib); main_tests.linkLibC(); main_tests.linkLibCpp(); const run_tests = b.addRunArtifact(main_tests); diff --git a/engine/papyrus/src/BmpRenderer.zig b/engine/papyrus/src/BmpRenderer.zig index edcd6f3..ac82869 100644 --- a/engine/papyrus/src/BmpRenderer.zig +++ b/engine/papyrus/src/BmpRenderer.zig @@ -2,7 +2,7 @@ const std = @import("std"); const papyrus = @import("papyrus.zig"); const Context = papyrus.Context; -const core = @import("core"); +const core = papyrus.core; const Vector2i = core.Vector2i; const Vector2 = core.Vector2; diff --git a/engine/papyrus/src/Font.zig b/engine/papyrus/src/Font.zig index aefecde..1464174 100644 --- a/engine/papyrus/src/Font.zig +++ b/engine/papyrus/src/Font.zig @@ -1,7 +1,7 @@ const std = @import("std"); const c = @import("c.zig").c; -const core = @import("core"); +const core = @import("papyrus.zig").core; const Vector2i = core.Vector2i; const Vector2f = core.Vector2f; const Name = core.Name; diff --git a/engine/papyrus/src/papyrus.zig b/engine/papyrus/src/papyrus.zig index d718a1d..2b116ed 100644 --- a/engine/papyrus/src/papyrus.zig +++ b/engine/papyrus/src/papyrus.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const c = @cImport({ +pub const c = @cImport({ @cInclude("stb_ttf.h"); }); diff --git a/engine/papyrus/tests/testing.zig b/engine/papyrus/tests/testing.zig index cef2a63..b8f8f84 100644 --- a/engine/papyrus/tests/testing.zig +++ b/engine/papyrus/tests/testing.zig @@ -2,10 +2,7 @@ const std = @import("std"); const papyrus = @import("papyrus"); const localization = papyrus.localization; const utils = papyrus.utils; -const c = @cImport({ - @cInclude("stb_ttf.h"); -}); - +const c = papyrus.c; const PapyrusContext = papyrus.Context; const PapyrusNode = papyrus.Node; const MakeText = localization.MakeText; diff --git a/engine/physics/build.zig b/engine/physics/build.zig index b1efd2b..5dc41aa 100644 --- a/engine/physics/build.zig +++ b/engine/physics/build.zig @@ -1,4 +1,9 @@ const std = @import("std"); +const core = @import("core"); + +const depList = [_][]const u8{ + "core", +}; // very tiny, not intended to build anything just to run tests linked with libc pub fn build(b: *std.Build) void { @@ -6,25 +11,24 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - const mod = b.addModule("physics", .{ + const engineMod = core.MakeModLib(b, .{ + .name = "physics", .target = target, .optimize = optimize, - .link_libc = true, - .root_source_file = b.path("src/physics.zig"), + .static_build = static_build, }); - const core_dep = b.dependency("core", .{ .target = target, .optimize = optimize, .static_build = static_build }); + engineMod.install(); + engineMod.linkModLibs(&depList); const zphysics_dep = b.dependency("zphysics", .{ .target = target, .optimize = optimize, - .enable_cross_platform_determinism = false, .static_build = static_build, }); - mod.addImport("core", core_dep.module("core")); - mod.addImport("zphysics", zphysics_dep.module("root")); - mod.linkLibrary(zphysics_dep.artifact("joltc")); + engineMod.mod.addImport("zphysics", zphysics_dep.module("root")); + engineMod.lib.linkLibrary(zphysics_dep.artifact("zphysics")); const test_step = b.step("test", "run unit tests for physics"); const tests = b.addTest(.{ @@ -35,7 +39,8 @@ pub fn build(b: *std.Build) void { }), }); - tests.root_module.addImport("physics", mod); + tests.root_module.addImport("physics", engineMod.mod); + tests.root_module.linkLibrary(zphysics_dep.artifact("zphysics")); const runArtifact = b.addRunArtifact(tests); test_step.dependOn(&runArtifact.step); b.installArtifact(tests); diff --git a/engine/platform/build.zig b/engine/platform/build.zig index c790a73..5cc6667 100644 --- a/engine/platform/build.zig +++ b/engine/platform/build.zig @@ -1,5 +1,6 @@ const std = @import("std"); const sdl3 = @import("sdl3"); +const core = @import("core"); const dependencyList = [_][]const u8{ "core", @@ -13,12 +14,16 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - const mod = b.addModule("platform", .{ - .target = target, + const engineMod = core.MakeModLib(b, .{ + .name = "platform", .optimize = optimize, - .root_source_file = b.path("src/platform.zig"), + .target = target, + .static_build = static_build, }); + engineMod.linkModLibs(&dependencyList); + engineMod.install(); + const tests = b.addTest(.{ .root_module = b.createModule(.{ .target = target, @@ -27,16 +32,10 @@ pub fn build(b: *std.Build) void { }), }); - for (dependencyList) |depName| { - const dep = b.dependency(depName, .{ .target = target, .optimize = optimize, .static_build = static_build }); - const dep_mod = dep.module(depName); - mod.addImport(depName, dep_mod); - tests.root_module.addImport(depName, dep_mod); - } - const test_step = b.step("test", "run unit tests for platform"); + tests.root_module.addImport("platform", engineMod.mod); + tests.linkLibrary(engineMod.lib); - tests.root_module.addImport("platform", mod); const runArtifact = b.addRunArtifact(tests); test_step.dependOn(&runArtifact.step); b.installArtifact(tests); diff --git a/engine/platform/src/platform.zig b/engine/platform/src/platform.zig index 5bf018b..1c4fef4 100644 --- a/engine/platform/src/platform.zig +++ b/engine/platform/src/platform.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const core = @import("core"); +pub const core = @import("core"); const test_vert = @import("test.vert"); pub const nfd = @import("nfd"); diff --git a/engine/platform/tests/tests.zig b/engine/platform/tests/tests.zig index e5a7151..7c2d48c 100644 --- a/engine/platform/tests/tests.zig +++ b/engine/platform/tests/tests.zig @@ -1,5 +1,5 @@ -const core = @import("core"); const platform = @import("platform"); +const core = @import("platform").core; const std = @import("std"); diff --git a/engine/rend/build.zig b/engine/rend/build.zig index a29c7be..aac1c7c 100644 --- a/engine/rend/build.zig +++ b/engine/rend/build.zig @@ -1,5 +1,6 @@ const std = @import("std"); const sdl3 = @import("sdl3"); +const core = @import("core"); const dependencyList = [_][]const u8{ "core", @@ -19,38 +20,47 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - const mod = b.addModule("rend", .{ + const engineMod = core.MakeModLib(b, .{ + .name = "rend", .target = target, .optimize = optimize, - .root_source_file = b.path("src/rend.zig"), + .static_build = static_build, }); + engineMod.linkModLibs(&dependencyList); + engineMod.install(); - for (dependencyList) |depName| { - const dep = b.dependency(depName, .{ .target = target, .optimize = optimize, .static_build = static_build }); - const dep_mod = dep.module(depName); - mod.addImport(depName, dep_mod); + // const mod = b.addModule("rend", .{ + // .target = target, + // .optimize = optimize, + // .root_source_file = b.path("src/rend.zig"), + // }); - if (std.mem.eql(u8, depName, "ozz")) { - mod.linkLibrary(dep.artifact("ozz_cpp")); - } - } + // for (dependencyList) |depName| { + // const dep = b.dependency(depName, .{ .target = target, .optimize = optimize, .static_build = static_build }); + // const dep_mod = dep.module(depName); + // mod.addImport(depName, dep_mod); - sdl3.shaderDefintion(b, mod, "../../lib/sdl3", target, optimize, "sample.vert", b.path("shaders/sample.vert.json")); - sdl3.shaderDefintion(b, mod, "../../lib/sdl3", target, optimize, "meshes.vert", b.path("shaders/meshes.vert.json")); - sdl3.shaderDefintion(b, mod, "../../lib/sdl3", target, optimize, "lit_mesh.frag", b.path("shaders/lit_mesh.frag.json")); + // if (std.mem.eql(u8, depName, "ozz")) { + // mod.linkLibrary(dep.artifact("ozz_cpp")); + // } + // } - sdl3.shaderDefintion(b, mod, "../../lib/sdl3", target, optimize, "debug.frag", b.path("shaders/debug.frag.json")); - sdl3.shaderDefintion(b, mod, "../../lib/sdl3", target, optimize, "debug.vert", b.path("shaders/debug.vert.json")); + sdl3.shaderDefintion(b, engineMod.mod, "../../lib/sdl3", target, optimize, "sample.vert", b.path("shaders/sample.vert.json")); + sdl3.shaderDefintion(b, engineMod.mod, "../../lib/sdl3", target, optimize, "meshes.vert", b.path("shaders/meshes.vert.json")); + sdl3.shaderDefintion(b, engineMod.mod, "../../lib/sdl3", target, optimize, "lit_mesh.frag", b.path("shaders/lit_mesh.frag.json")); - sdl3.shaderDefintion(b, mod, "../../lib/sdl3", target, optimize, "depthOnly.frag", b.path("shaders/depthOnly.frag.json")); + sdl3.shaderDefintion(b, engineMod.mod, "../../lib/sdl3", target, optimize, "debug.frag", b.path("shaders/debug.frag.json")); + sdl3.shaderDefintion(b, engineMod.mod, "../../lib/sdl3", target, optimize, "debug.vert", b.path("shaders/debug.vert.json")); - sdl3.shaderDefintion(b, mod, "../../lib/sdl3", target, optimize, "skybox.frag", b.path("shaders/skybox.frag.json")); - sdl3.shaderDefintion(b, mod, "../../lib/sdl3", target, optimize, "skybox.vert", b.path("shaders/skybox.vert.json")); + sdl3.shaderDefintion(b, engineMod.mod, "../../lib/sdl3", target, optimize, "depthOnly.frag", b.path("shaders/depthOnly.frag.json")); - sdl3.shaderDefintion(b, mod, "../../lib/sdl3", target, optimize, "postProc.frag", b.path("shaders/postProc.frag.json")); - sdl3.shaderDefintion(b, mod, "../../lib/sdl3", target, optimize, "postProc.vert", b.path("shaders/postProc.vert.json")); + sdl3.shaderDefintion(b, engineMod.mod, "../../lib/sdl3", target, optimize, "skybox.frag", b.path("shaders/skybox.frag.json")); + sdl3.shaderDefintion(b, engineMod.mod, "../../lib/sdl3", target, optimize, "skybox.vert", b.path("shaders/skybox.vert.json")); - sdl3.shaderDefintion(b, mod, "../../lib/sdl3", target, optimize, "ssao.frag", b.path("shaders/ssao.frag.json")); + sdl3.shaderDefintion(b, engineMod.mod, "../../lib/sdl3", target, optimize, "postProc.frag", b.path("shaders/postProc.frag.json")); + sdl3.shaderDefintion(b, engineMod.mod, "../../lib/sdl3", target, optimize, "postProc.vert", b.path("shaders/postProc.vert.json")); + + sdl3.shaderDefintion(b, engineMod.mod, "../../lib/sdl3", target, optimize, "ssao.frag", b.path("shaders/ssao.frag.json")); // ========== tests ========== const tests = b.addTest(.{ diff --git a/engine/sys/build.zig b/engine/sys/build.zig index e4254d7..6232f26 100644 --- a/engine/sys/build.zig +++ b/engine/sys/build.zig @@ -1,38 +1,27 @@ const std = @import("std"); const sdl3 = @import("sdl3"); +const core = @import("core"); const dependencyList = [_][]const u8{ "core", }; 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 mod = b.addModule("sys", .{ - .target = target, - .optimize = optimize, - .root_source_file = b.path("src/sys.zig"), - }); - - for (dependencyList) |depName| { - const dep = b.dependency(depName, .{ .target = target, .optimize = optimize, .static_build = static_build }); - const dep_mod = dep.module(depName); - mod.addImport(depName, dep_mod); - } + const engineMod = core.MakeEngineMod(b, "sys"); + engineMod.linkModLibs(&dependencyList); + engineMod.install(); // ========== tests ========== const tests = b.addTest(.{ .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, + .target = engineMod.target, + .optimize = engineMod.optimize, .root_source_file = b.path("tests/tests.zig"), }), }); const test_step = b.step("test", "run unit tests for ui"); - tests.root_module.addImport("sys", mod); + tests.root_module.addImport("sys", engineMod.mod); const runArtifact = b.addRunArtifact(tests); b.installArtifact(tests); test_step.dependOn(&runArtifact.step); diff --git a/engine/sys/src/systemProc.zig b/engine/sys/src/systemProc.zig index d653088..8eb9043 100644 --- a/engine/sys/src/systemProc.zig +++ b/engine/sys/src/systemProc.zig @@ -21,8 +21,8 @@ pub const SubprocessTask = struct { allocator: std.mem.Allocator, child: ?std.process.Child = null, - completed: bool = false, - success: bool = false, + completed: std.atomic.Value(bool) = std.atomic.Value(bool).init(false), + success: std.atomic.Value(bool) = std.atomic.Value(bool).init(false), workingDir: ?[]const u8 = null, @@ -76,29 +76,29 @@ pub const SubprocessTask = struct { } pub fn destroy(self: *@This()) void { - self.mutex.lock(); + // self.mutex.lock(); self.argsArena.deinit(); self.argsOwned.deinit(self.allocator); if (self.child) |*child| { _ = child; core.engine_log("destroying child process", .{}); } - self.mutex.unlock(); + // self.mutex.unlock(); self.stdout.deinit(self.allocator); self.stderr.deinit(self.allocator); self.allocator.destroy(self); } pub fn checkComplete(self: *@This()) bool { - return self.completed; + return self.completed.load(.monotonic); } pub fn wait(self: *@This()) void { - var completed: bool = self.completed; + var completed: bool = self.completed.load(.monotonic); while (completed == false) { std.Thread.sleep(1 * 1000 * 1000); self.mutex.lock(); - completed = self.completed; + completed = self.completed.load(.monotonic); self.mutex.unlock(); } debugPrint("task completed", .{}); @@ -117,7 +117,7 @@ pub const SubprocessTask = struct { switch (term) { .Exited => |m| { - if (m == 0) self.success = true; + if (m == 0) self.success.store(true, .release); }, .Signal => |m| { core.engine_log("process Signaled {d}", .{m}); @@ -132,8 +132,8 @@ pub const SubprocessTask = struct { self.mutex.lock(); self.child = null; - self.completed = true; self.mutex.unlock(); + self.completed.store(true, .release); } pub fn runCommand(allocator: std.mem.Allocator, argv: []const []const u8, cwd: ?[]const u8) !*@This() { diff --git a/engine/ui/build.zig b/engine/ui/build.zig index eb07f11..a60adc4 100644 --- a/engine/ui/build.zig +++ b/engine/ui/build.zig @@ -1,5 +1,6 @@ const std = @import("std"); const sdl3 = @import("sdl3"); +const core = @import("core"); const dependencyList = [_][]const u8{ "core", @@ -11,28 +12,18 @@ const dependencyList = [_][]const u8{ }; 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 mod = b.addModule("ui", .{ - .target = target, - .optimize = optimize, - .root_source_file = b.path("src/ui.zig"), - }); - - for (dependencyList) |depName| { - const dep = b.dependency(depName, .{ .target = target, .optimize = optimize, .static_build = static_build }); - const dep_mod = dep.module(depName); - mod.addImport(depName, dep_mod); - } + const engineMod = core.MakeEngineMod(b, "ui"); + engineMod.linkModLibs(&dependencyList); + engineMod.install(); + const target = engineMod.target; + const optimize = engineMod.optimize; // shaders - sdl3.shaderDefintion(b, mod, "../../lib/sdl3", target, optimize, "rect.vert", b.path("shaders/rect.vert.json")); - sdl3.shaderDefintion(b, mod, "../../lib/sdl3", target, optimize, "rect.frag", b.path("shaders/rect.frag.json")); + sdl3.shaderDefintion(b, engineMod.mod, "../../lib/sdl3", target, optimize, "rect.vert", b.path("shaders/rect.vert.json")); + sdl3.shaderDefintion(b, engineMod.mod, "../../lib/sdl3", target, optimize, "rect.frag", b.path("shaders/rect.frag.json")); - sdl3.shaderDefintion(b, mod, "../../lib/sdl3", target, optimize, "text.vert", b.path("shaders/text.vert.json")); - sdl3.shaderDefintion(b, mod, "../../lib/sdl3", target, optimize, "text.frag", b.path("shaders/text.frag.json")); + sdl3.shaderDefintion(b, engineMod.mod, "../../lib/sdl3", target, optimize, "text.vert", b.path("shaders/text.vert.json")); + sdl3.shaderDefintion(b, engineMod.mod, "../../lib/sdl3", target, optimize, "text.frag", b.path("shaders/text.frag.json")); // ========== tests ========== const tests = b.addTest(.{ @@ -44,7 +35,8 @@ pub fn build(b: *std.Build) void { }); const test_step = b.step("test", "run unit tests for ui"); - tests.root_module.addImport("ui", mod); + tests.root_module.addImport("ui", engineMod.mod); + tests.root_module.linkLibrary(engineMod.lib); const runArtifact = b.addRunArtifact(tests); test_step.dependOn(&runArtifact.step); b.installArtifact(tests); diff --git a/lib/bh/build.zig b/lib/bh/build.zig index 5351704..365b157 100644 --- a/lib/bh/build.zig +++ b/lib/bh/build.zig @@ -18,7 +18,7 @@ pub const ModLib = struct { self.mod.addIncludePath(self.b.path(path)); } - pub fn linkModLibs(self: *@This(), list: []const []const u8) void { + pub fn linkModLibs(self: @This(), list: []const []const u8) void { for (list) |depName| { const dep = self.b.dependency(depName, .{ .target = self.target, @@ -44,7 +44,7 @@ pub const ModLibOptions = struct { stub: ?std.Build.LazyPath = null, }; -pub fn MakeModlib(b: *std.Build, o: ModLibOptions) ModLib { +pub fn MakeModLib(b: *std.Build, o: ModLibOptions) ModLib { const mod = b.addModule(o.name, .{ .target = o.target, .optimize = o.optimize, @@ -78,7 +78,7 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - const r = MakeModlib(b, .{ + const r = MakeModLib(b, .{ .name = "bh", .target = target, .optimize = optimize, diff --git a/lib/cimgui/build.zig b/lib/cimgui/build.zig index 240c17e..6bf87a7 100644 --- a/lib/cimgui/build.zig +++ b/lib/cimgui/build.zig @@ -7,7 +7,7 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - const cimgui = bh.MakeModlib(b, .{ + const cimgui = bh.MakeModLib(b, .{ .name = "cimgui", .target = target, .optimize = optimize, diff --git a/lib/enet/build.zig b/lib/enet/build.zig index daf20b3..c12c29f 100644 --- a/lib/enet/build.zig +++ b/lib/enet/build.zig @@ -17,7 +17,7 @@ pub fn build(b: *std.Build) void { // .optimize = optimize, // }); - const enet = bh.MakeModlib(b, .{ + const enet = bh.MakeModLib(b, .{ .name = "enet", .target = target, .optimize = optimize, diff --git a/lib/lua/build.zig b/lib/lua/build.zig index 8ee5dbb..918fdbf 100644 --- a/lib/lua/build.zig +++ b/lib/lua/build.zig @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - const lua = bh.MakeModlib(b, .{ + const lua = bh.MakeModLib(b, .{ .name = "lua", .target = target, .optimize = optimize, diff --git a/lib/miniaudio/build.zig b/lib/miniaudio/build.zig index 7f5125e..65768c2 100644 --- a/lib/miniaudio/build.zig +++ b/lib/miniaudio/build.zig @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - const miniaudio = bh.MakeModlib(b, .{ + const miniaudio = bh.MakeModLib(b, .{ .name = "miniaudio", .target = target, .optimize = optimize, diff --git a/lib/nfd/build.zig b/lib/nfd/build.zig index f03dce2..7e9af91 100644 --- a/lib/nfd/build.zig +++ b/lib/nfd/build.zig @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - const nfd = bh.MakeModlib(b, .{ + const nfd = bh.MakeModLib(b, .{ .name = "nfd", .target = target, .optimize = optimize, diff --git a/lib/objLoader/build.zig b/lib/objLoader/build.zig index 0a0ea61..f018033 100644 --- a/lib/objLoader/build.zig +++ b/lib/objLoader/build.zig @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - const objLoader = bh.MakeModlib(b, .{ + const objLoader = bh.MakeModLib(b, .{ .name = "objLoader", .target = target, .optimize = optimize, diff --git a/lib/ozz/build.zig b/lib/ozz/build.zig index 060a180..533c4d4 100644 --- a/lib/ozz/build.zig +++ b/lib/ozz/build.zig @@ -86,7 +86,7 @@ pub const GltfToOzz = struct { }); const dep = b.dependency(opts.importName, .{}); - const ozz_mod = dep.artifact("ozz_cpp"); + const ozz_mod = dep.artifact("ozz"); exe.root_module.linkLibrary(ozz_mod); exe.root_module.addIncludePath(b.path("ozz-animation/include")); diff --git a/lib/p2/build.zig b/lib/p2/build.zig index 3a7471d..0c9b5f9 100644 --- a/lib/p2/build.zig +++ b/lib/p2/build.zig @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse true; - const p2 = bh.MakeModlib(b, .{ + const p2 = bh.MakeModLib(b, .{ .name = "p2", .target = target, .optimize = optimize, diff --git a/lib/p2/src/p2.zig b/lib/p2/src/p2.zig index a57b924..fcb1540 100644 --- a/lib/p2/src/p2.zig +++ b/lib/p2/src/p2.zig @@ -57,7 +57,7 @@ pub const IndexPool = index_pool.IndexPool; pub const concurrent_queue = @import("structures/concurrent-queue.zig"); pub const ConcurrentQueueU = concurrent_queue.ConcurrentQueueU; -pub const ConcurrentQueueUnmanagedAdvanced = concurrent_queue.ConcurrentQueueUnmanagedAdvanced; +pub const ConcurrentQueueAdvanced = concurrent_queue.ConcurrentQueueAdvanced; pub const string_pool = @import("structures/string-pool.zig"); diff --git a/lib/packer/build.zig b/lib/packer/build.zig index c8d4153..04b9c78 100644 --- a/lib/packer/build.zig +++ b/lib/packer/build.zig @@ -7,7 +7,7 @@ pub fn build(b: *std.Build) void { const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - const packer = bh.MakeModlib(b, .{ + const packer = bh.MakeModLib(b, .{ .name = "packer", .target = target, .optimize = optimize, diff --git a/lib/sdl3/build.zig b/lib/sdl3/build.zig index cbcb6d1..890e2ea 100644 --- a/lib/sdl3/build.zig +++ b/lib/sdl3/build.zig @@ -62,14 +62,18 @@ pub fn build(b: *std.Build) void { }); const sdl3_lib = sdl_dep.artifact("SDL3"); + b.installArtifact(sdl3_lib); - const sdl3_fwd = b.addModule("SDL3", .{ - .target = target, - .optimize = optimize, - .root_source_file = b.path("src/sdl3_lib_fwd.zig"), + const sdl3_fwd = b.addLibrary(.{ + .name = "sdl3", + .root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + .root_source_file = b.path("src/sdl3_lib_fwd.zig"), + }), }); - sdl3_fwd.linkLibrary(sdl3_lib); + b.installArtifact(sdl3_fwd); const mod = b.addModule("sdl3", .{ .target = target, @@ -84,7 +88,7 @@ pub fn build(b: *std.Build) void { mod.addImport("shaderTypes", shaderTypes.module("shaderTypes")); mod.addIncludePath(b.path("SDL/include")); - mod.linkLibrary(sdl3_lib); + mod.linkLibrary(sdl_dep.artifact("SDL3")); const test_step2 = b.step("test", "run unit tests for sdl3"); const tests2 = b.addExecutable(.{ @@ -134,7 +138,6 @@ pub fn build(b: *std.Build) void { test_step2.dependOn(&runArtifact2.step); b.installArtifact(hello_window_exe); - b.installArtifact(sdl3_lib); b.installArtifact(tests); b.installArtifact(tests2); } diff --git a/lib/sdl3/shaderTypes/build.zig b/lib/sdl3/shaderTypes/build.zig index 394be03..32b71a1 100644 --- a/lib/sdl3/shaderTypes/build.zig +++ b/lib/sdl3/shaderTypes/build.zig @@ -13,5 +13,15 @@ pub fn build(b: *std.Build) void { .root_source_file = b.path("shaderTypes.zig"), }); + const lib = b.addLibrary(.{ + .name = "shaderTypes", + .root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + .root_source_file = b.path("stubc.zig"), + }), + }); + + b.installArtifact(lib); _ = mod; } diff --git a/lib/sdl3/shaderTypes/stubc.zig b/lib/sdl3/shaderTypes/stubc.zig new file mode 100644 index 0000000..e69de29 diff --git a/lib/spng/build.zig b/lib/spng/build.zig index 0eb6501..4394309 100644 --- a/lib/spng/build.zig +++ b/lib/spng/build.zig @@ -7,7 +7,7 @@ pub fn build(b: *std.Build) void { const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - const spng = bh.MakeModlib(b, .{ + const spng = bh.MakeModLib(b, .{ .name = "spng", .target = target, .optimize = optimize, diff --git a/lib/tracy/build.zig b/lib/tracy/build.zig index bd1d831..2779005 100644 --- a/lib/tracy/build.zig +++ b/lib/tracy/build.zig @@ -17,7 +17,7 @@ pub fn build(b: *std.Build) void { // } // std.debug.print("tracy enabled {s}\n", .{if (tracy_enabled) "true" else "false"}); - const tracy = bh.MakeModlib(b, .{ + const tracy = bh.MakeModLib(b, .{ .name = "tracy", .target = target, .optimize = optimize, diff --git a/lib/watcher/build.zig b/lib/watcher/build.zig index 2f80f9a..4a65809 100644 --- a/lib/watcher/build.zig +++ b/lib/watcher/build.zig @@ -7,7 +7,7 @@ pub fn build(b: *std.Build) void { const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - const watcher = bh.MakeModlib(b, .{ + const watcher = bh.MakeModLib(b, .{ .name = "watcher", .target = target, .optimize = optimize, diff --git a/lib/zgltf/build.zig b/lib/zgltf/build.zig index 0ec6dc0..609c9f2 100644 --- a/lib/zgltf/build.zig +++ b/lib/zgltf/build.zig @@ -7,7 +7,7 @@ pub fn build(b: *std.Build) void { const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - const zgltf = bh.MakeModlib(b, .{ + const zgltf = bh.MakeModLib(b, .{ .name = "zgltf", .target = target, .optimize = optimize, diff --git a/lib/zmath/build.zig b/lib/zmath/build.zig index 19ecaa8..d6399a1 100644 --- a/lib/zmath/build.zig +++ b/lib/zmath/build.zig @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; - const zmath = bh.MakeModlib(b, .{ + const zmath = bh.MakeModLib(b, .{ .name = "zmath", .target = target, .optimize = optimize, diff --git a/lib/zphysics/build.zig b/lib/zphysics/build.zig index 53d9082..9bd4fc5 100644 --- a/lib/zphysics/build.zig +++ b/lib/zphysics/build.zig @@ -72,7 +72,7 @@ pub fn build(b: *std.Build) void { zjolt.addIncludePath(b.path("libs/JoltC")); const joltc = b.addLibrary(.{ - .name = "joltc", + .name = "zphysics", .linkage = if (!static_build) .dynamic else .static, .root_module = b.createModule(.{ .target = target, diff --git a/projects/build.zig b/projects/build.zig index d51bfd3..b86fd22 100644 --- a/projects/build.zig +++ b/projects/build.zig @@ -17,6 +17,10 @@ pub fn build(b: *std.Build) void { .root_source_file = b.path("sampleGame/main.zig"), }); + // new paradigm has all engine modules be zig modules, + // in that way zig modules act as headers. + // + // due to conditional compiling, we do NOT need to do any special linking against them sampleGame.setModuleEnabled("imgui", true); sampleGame.setModuleEnabled("audio", true); sampleGame.setModuleEnabled("physics", true); @@ -51,26 +55,26 @@ pub fn build(b: *std.Build) void { newProjectMaker.setIconPath("icons/NewProject.ico"); _ = newProjectMaker.compileInstall(); - const toolbox = blbuild.program(.{ - .name = "toolbox", - .desc = "graphical toolbox for random stuff", - .root_source_file = b.path("tools/toolbox.zig"), - }); + // const toolbox = blbuild.program(.{ + // .name = "toolbox", + // .desc = "graphical toolbox for random stuff", + // .root_source_file = b.path("tools/toolbox.zig"), + // }); - toolbox.setModuleEnabled("imgui", true); - toolbox.setModuleEnabled("audio", false); - toolbox.setModuleEnabled("sys", true); - toolbox.setModuleEnabled("net", false); - toolbox.addExtraModule("gameExtras"); + // toolbox.setModuleEnabled("imgui", true); + // toolbox.setModuleEnabled("audio", false); + // toolbox.setModuleEnabled("sys", true); + // toolbox.setModuleEnabled("net", false); + // toolbox.addExtraModule("gameExtras"); - const toolboxExe = toolbox.compileInstall(); + // const toolboxExe = toolbox.compileInstall(); // Add Windows icon resource for toolbox - if (target.result.os.tag == .windows) { - toolboxExe.addWin32ResourceFile(.{ - .file = b.path("tools/toolbox.rc"), - .flags = &.{}, - }); - } + // if (target.result.os.tag == .windows) { + // toolboxExe.addWin32ResourceFile(.{ + // .file = b.path("tools/toolbox.rc"), + // .flags = &.{}, + // }); + // } const headless = blbuild.program(.{ .name = "headless", diff --git a/projects/sampleGame/externGame/externGame.zig b/projects/sampleGame/externGame/externGame.zig index 47fc5d3..b1ce3e1 100644 --- a/projects/sampleGame/externGame/externGame.zig +++ b/projects/sampleGame/externGame/externGame.zig @@ -33,9 +33,9 @@ pub fn start_module(args: core.ModuleLoaderArgs) !void { core.PatchOrCreateObject(imgui.utils.ConsoleWindow, .{}); core.PatchOrCreateObject(@import("fpgame/fpgame.zig"), .{}); - core.engine_log("this change definitely happened :^) ", .{}); + const dt = core.getEngineTime() - core.get(ExternGameObject).recompileStart; - core.engine_log("this change definitely happened :^) ", .{}); + core.engine_log("recompile time: {d}", .{dt}); _ = args; core.logDisplay("externGame", "accessing old object at {x} same object? {d}", .{ @intFromPtr(core.EngineObject(ExternGameObject).get()), @sizeOf(ExternGameObject) }); @@ -120,6 +120,8 @@ pub const ExternGameObject = struct { openSpawner: ?*core.ActionBinding = null, reloadMapInput: ?*core.ActionBinding = null, + recompileStart: f64 = 0.0, + volume: f32 = 100.0, volume2: f32 = 100.0, @@ -403,6 +405,8 @@ pub const ExternGameObject = struct { pub fn recompileComplete(ctx: ?*anyopaque) void { const self = core.cast(*@This(), ctx.?); self.recompiling = false; + const duration = core.getEngineTime() - self.recompileStart; + core.engine_log("recompile time {d}s", .{duration}); } pub fn onOpenSpawner(ctx: ?*anyopaque, _: core.ActionEvent) void { @@ -417,6 +421,7 @@ pub const ExternGameObject = struct { const self = core.cast(*@This(), ctx.?); if (!self.recompiling) { + self.recompileStart = core.getEngineTime(); self.recompiling = true; const x = core.EngineObject(sys.SystemRunner).get(); x.commandQueue.pushLocked(.{