From 67883be7fb7c5d43f8bc597617ea2f4da783d46d Mon Sep 17 00:00:00 2001 From: peterino2 Date: Sun, 8 Jun 2025 18:06:19 -0700 Subject: [PATCH] module forwarding optionals and apigen --- build.zig | 160 ++++++++++++++++++++-- build.zig.zon | 1 - build/buildExternModule.zig | 0 build/generateApi.zig | 167 +++++++++++++++++++++++ build/generateFwd.zig | 25 ++++ engine/audio/src/embedded/engineTick.wav | Bin 0 -> 1746 bytes engine/backlog.zig | 54 ++++++-- engine/core/src/core.zig | 8 +- engine/core/src/extern/externModule.zig | 2 +- engine/moduleFwd.zig | 1 + engine/moduleStub.zig | 18 +++ extras/bsp/build.zig | 3 +- extras/doomplayer/build.zig | 3 +- extras/gameExtras/build.zig | 4 +- extras/videoplayer/build.zig | 3 +- lib/sdl3/build.zig | 3 +- projects/build.zig.zon | 2 +- projects/minimal/build.zig | 35 ++++- projects/minimal/build.zig.zon | 4 +- projects/minimal/src/main.zig | 17 +-- 20 files changed, 462 insertions(+), 48 deletions(-) delete mode 100644 build/buildExternModule.zig create mode 100644 build/generateApi.zig create mode 100644 build/generateFwd.zig create mode 100644 engine/audio/src/embedded/engineTick.wav create mode 100644 engine/moduleFwd.zig create mode 100644 engine/moduleStub.zig diff --git a/build.zig b/build.zig index 9cfb70f..9c413d0 100644 --- a/build.zig +++ b/build.zig @@ -16,6 +16,9 @@ reflectShaderPathList: [][]u8 = undefined, staticBuild: bool = false, +nwdep: *std.Build.Dependency, +apigen: *std.Build.Step.Compile, + const engineDepList = [_][]const u8{ "assets", "audio", @@ -59,7 +62,7 @@ pub fn init(b: *std.Build, opts: InitOptions) BuildSystem { .static_build = buildOpts.static_build, }); - const self = BuildSystem{ + var self = BuildSystem{ .b = b, .nw_builder = nwdep.builder, .target = opts.target, @@ -72,6 +75,8 @@ pub fn init(b: *std.Build, opts: InitOptions) BuildSystem { .cookShaders = b.option(bool, "cookShaders", "generates shaders and updates .json files before running the build. (needs to be done whenever shaders are updated, this just runs tools/scripts/cook-shaders.py)") orelse false, .staticBuild = buildOpts.static_build, + .nwdep = nwdep, + .apigen = nwdep.artifact("backlog-apigen"), }; const exeList = [2]*std.Build.Step.Compile{ self.gltf2ozz.exe, self.spirvReflect.reflect }; @@ -104,6 +109,8 @@ pub fn init(b: *std.Build, opts: InitOptions) BuildSystem { run_exe.dependOn(&runArtifact.step); } + self.addDependencyInstalls(self.b, .ReleaseFast); + return self; } @@ -112,7 +119,6 @@ pub const AddProgramOptions = struct { desc: []const u8, root_source_file: LazyPath, imports: []const Build.Module.Import = &.{}, - staticBuild: bool = false, // ugh.... why is this so hard... }; pub fn addProgram(self: *BuildSystem, opts: AddProgramOptions) *std.Build.Module { @@ -223,19 +229,21 @@ pub fn addDependencyInstalls(self: *BuildSystem, b: *std.Build, optimize: std.bu return; } - inline for (cDependencyList) |d| { + inline for (DynamicDepList) |d| { b.installArtifact(b.dependency( d.dep, .{ .target = self.target, .optimize = optimize, .static_build = self.staticBuild }, ).artifact(d.artifact)); } - b.installArtifact(b.dependency( - "sdl3_lib", - .{ .target = self.target, .optimize = optimize, .static_build = self.staticBuild, .preferred_linkage = .dynamic }, - ).artifact("SDL3")); + + // b.installArtifact(b.dependency( + // "sdl3", + // .{ .target = self.target, .optimize = optimize, .static_build = self.staticBuild }, + // ).artifact("SDL3")); } -const cDependencyList: []const struct { dep: []const u8, artifact: []const u8 } = &.{ +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" }, @@ -243,8 +251,87 @@ const cDependencyList: []const struct { dep: []const u8, artifact: []const u8 } .{ .dep = "ozz", .artifact = "ozz_cpp" }, }; +// all other modules are disabled by default +pub const defaultEnabledModules: []const []const u8 = &.{ + "core", + "assets", + "platform", + "rend", +}; + +pub const moduleOrder: []const []const u8 = &.{ + "core", + "assets", + "platform", + "physics", + "audio", + "rend", + "imgui", + "papyrus", + "ui", +}; + +pub const GameModule = struct { + name: []const u8, + enabled: bool = true, +}; + +pub const Program = struct { + allocator: std.mem.Allocator, + opts: AddProgramOptions, + gameModules: std.ArrayListUnmanaged(GameModule) = .{}, + buildSystem: *BuildSystem, + + pub fn setModuleEnabled(self: *@This(), module: []const u8, enable: bool) void { + for (self.gameModules.items) |*m| { + if (std.mem.eql(u8, m.name, module)) { + m.enabled = enable; + return; + } + } + + // module not found, add it here. + self.gameModules.append(self.allocator, .{ .name = module, .enabled = enable }) catch unreachable; + } + + pub fn compileInstall(self: *@This()) *std.Build.Module { + const exe = self.buildSystem.addProgram(self.opts); + var modlist = std.ArrayList([]const u8).init(self.buildSystem.b.allocator); + + for (self.gameModules.items) |mod| { + if (mod.enabled) { + modlist.append(mod.name) catch unreachable; + } + } + + exe.addImport("backlog", self.buildSystem.generateApi(self.opts.name, modlist.items)); + + return exe; + } +}; + +pub fn program(self: *BuildSystem, opts: AddProgramOptions) *Program { + const prog = self.b.allocator.create(Program) catch unreachable; + + prog.* = .{ + .allocator = self.b.allocator, + .opts = opts, + .buildSystem = self, + }; + + for (moduleOrder) |module| { + prog.setModuleEnabled(module, false); + } + + for (defaultEnabledModules) |module| { + prog.setModuleEnabled(module, true); + } + + return prog; +} + // ========= standalone build instance ======= -// maybe it should be an engine launcher or something.. +// maybe the default should be like an engine launcher/project launcher or something pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); @@ -257,6 +344,22 @@ pub fn build(b: *std.Build) void { }); _ = spirvDep; + const fwdGeneratorExe = b.addExecutable(.{ + .name = "backlog-generate-fwd", + .target = b.graph.host, + .optimize = .Debug, + .root_source_file = b.path("build/generateFwd.zig"), + }); + + const generateExe = b.addExecutable(.{ + .name = "backlog-apigen", + .target = b.graph.host, + .optimize = .Debug, + .root_source_file = b.path("build/generateApi.zig"), + }); + + b.installArtifact(generateExe); + { const mod = b.addModule("Backlog", .{ .target = target, @@ -273,19 +376,52 @@ pub fn build(b: *std.Build) void { .static_build = static_build, }, ); - mod.addImport(depName, dep.module(depName)); + + const run = b.addRunArtifact(fwdGeneratorExe); + const output = run.addOutputFileArg(b.fmt("{s}_fwd.zig", .{depName})); + + const modFwd = b.addModule(depName, .{ + .target = target, + .optimize = optimize, + .root_source_file = output, + }); + + mod.addImport(b.fmt("{s}", .{depName}), modFwd); + modFwd.addImport("module", dep.module(depName)); + + // mod.addImport(depName, dep.module(depName)); } - // link in large platform support functions + // link in large platform support functions... special case. { const dep = b.dependency("sdl3", .{ .target = target, .optimize = optimize, .static_build = static_build, }); - const lib = dep.module("sdl3_lib"); + const lib = dep.module("SDL3"); mod.addImport("sdl3_fwd", lib); } } } + +pub fn generateApi(self: *@This(), programName: []const u8, moduleList: []const []const u8) *std.Build.Module { + const run = self.b.addRunArtifact(self.apigen); + const pfile = self.b.fmt("{s}Api.zig", .{programName}); + const output = run.addOutputFileArg(pfile); + for (moduleList) |modName| { + run.addArg(modName); + } + + const mod = self.b.addModule(pfile, .{ + .target = self.target, + .optimize = self.optimize, + .root_source_file = output, + }); + for (moduleList) |modName| { + mod.addImport(modName, self.nwdep.module(modName)); + } + + return mod; +} diff --git a/build.zig.zon b/build.zig.zon index 05136bc..254f0d3 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -18,7 +18,6 @@ .zphysics = .{ .path = "lib/zphysics" }, .sdl3 = .{ .path = "lib/sdl3" }, - .sdl3_lib = .{ .path = "lib/sdl3/SDL" }, }, .paths = .{ "", diff --git a/build/buildExternModule.zig b/build/buildExternModule.zig deleted file mode 100644 index e69de29..0000000 diff --git a/build/generateApi.zig b/build/generateApi.zig new file mode 100644 index 0000000..88acef4 --- /dev/null +++ b/build/generateApi.zig @@ -0,0 +1,167 @@ +const std = @import("std"); + +pub fn main() !void { + var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); + defer arena.deinit(); + const allocator = arena.allocator(); + + // Get output filename from build system + const args = try std.process.argsAlloc(allocator); + if (args.len < 3) @panic("Missing output filename"); + const out_path = args[1]; + + // Generate a startup module function that invokes + // startup module for each zig function + // and generates an api + var content = std.ArrayList(u8).init(allocator); + var writer = content.writer(); + const moduleList = args[2..]; + + for (moduleList) |mod| { + try writer.print("pub const {s} = @import(\"{s}\").module;\n", .{ mod, mod }); + } + + try writer.print("pub const moduleList:[]const []const u8 = &.{{\n", .{}); + for (moduleList) |mod| { + try writer.print("\"{s}\",\n", .{mod}); + } + try writer.print("}};\n", .{}); + + try writer.print( + \\var shutdownList: std.ArrayListUnmanaged(*const fn (std.mem.Allocator) void) = .{{}}; + \\var shutdownModuleNames: std.ArrayListUnmanaged([]const u8) = .{{}}; + \\ + \\ pub const NwArgs = struct {{ + \\ useGPA: bool = false, // slower zig based memory allocator, provides detailed tracking of leaks and memory violations + \\ vulkanValidation: bool = true, + \\ fastTest: bool = false, + \\ dmt: bool = false, // detailed memory tracking, implements a timeline for tracking all memory allocations + \\ fatDump: bool = false, // takes a full fat minidump on crash, very large files are produced + \\ }}; + \\ + \\ pub fn getArgs() !NwArgs {{ + \\ const a = try core.ParseArgs(NwArgs); + \\ + \\ return a; + \\ }} + , .{}); + try writer.print("pub fn start_modules_(spec: *core.SpecVariantMap, maybeArgs: ?NwArgs, allocator: std.mem.Allocator) !void {{", .{}); + + try writer.print( + \\ + \\ var z = core.tracy.ZoneN(@src(), "Starting all Modules"); + \\ defer z.End(); + \\ inline for (moduleList) |feature| {{ + \\ if (@hasDecl(@This(), feature)) {{ + \\ const Struct = @field(@This(), feature); + \\ if (core.isModuleEnabled(Struct.Module, spec)) {{ + \\ var z1 = core.tracy.ZoneN(@src(), @ptrCast("Initializing Module")); + \\ defer z1.End(); + \\ core.tracy.Message(Struct.Module.name); + \\ if (maybeArgs) |args| {{ + \\ try Struct.start_module(spec, args, allocator); + \\ }} else {{ + \\ try Struct.start_module(spec, NwArgs{{}}, allocator); + \\ }} + \\ try shutdownList.append(allocator, Struct.shutdown_module); + \\ try shutdownModuleNames.append(allocator, feature); + \\ core.engine_logs("module started >>>> " ++ feature ++ " <<<<"); + \\ }} + \\ }} + \\ }} }} + \\pub fn start_modules(spec: *core.SpecVariantMap, maybeArgs: ?NwArgs, allocator: std.mem.Allocator) bool {{ start_modules_(spec, maybeArgs, allocator) catch return false; return true;}} + \\ + \\ pub fn shutdown_modules(allocator: std.mem.Allocator) void {{ + \\ var i: isize = @intCast(shutdownList.items.len - 1); + \\ while (i >= 0) : (i -= 1) {{ + \\ core.engine_log("module shutting down >>>> {{s}} <<<<", .{{shutdownModuleNames.items[@intCast(i)]}}); + \\ shutdownList.items[@intCast(i)](allocator); + \\ }} + \\ shutdownList.deinit(allocator); + \\ shutdownModuleNames.deinit(allocator); + \\ }} + \\ + , .{}); + + _ = try writer.write( + \\ pub fn startEngine(vtable: *core.EngineObjectVTable, spec: *core.SpecVariantMap) bool { + \\ const args = getArgs() catch return false; + \\ + \\ var backingAllocator: std.mem.Allocator = std.heap.c_allocator; + \\ var gpa: std.heap.GeneralPurposeAllocator(.{ + \\ .stack_trace_frames = 20, + \\ }) = .{}; + \\ + \\ defer { + \\ const cleanupStatus = gpa.deinit(); + \\ if (cleanupStatus == .leak) { + \\ std.debug.print("gpa cleanup leaked memory\n", .{}); + \\ } + \\ } + \\ + \\ if (spec.get("useGPA")) |arg| { + \\ if (arg.boolean == true) { + \\ backingAllocator = gpa.allocator(); + \\ } + \\ } + \\ + \\ const memory = core.MemoryTracker; + \\ memory.MTSetup(backingAllocator, .{ .timeline = args.dmt }); + \\ defer memory.MTShutdown(); + \\ + \\ var tracker = memory.MTGet().?; + \\ const allocator = tracker.allocator(); + \\ + \\ if (!start_modules(spec, args, allocator)) return false; + \\ defer shutdown_modules(allocator); + \\ + \\ run_everything_vtable(vtable) catch return false; + \\ + \\ return true; + \\ } + \\ + \\ + \\ pub fn run_everything_vtable(gameVtable: *core.EngineObjectVTable) !void { + \\ core.engine_logs("creating Game context"); + \\ + \\ //_ = try core.createObject(GameContext, .{}); + \\ _ = try core.createObjectVTable(gameVtable, .{}); + \\ + \\ core.engine_logs("calling gEngine.run"); + \\ + \\ try core.getEngine().run(); + \\ + \\ while (!core.getEngine().exitFinished()) { + \\ const z = core.tracy.ZoneN(@src(), "shutdown poll"); + \\ z.End(); + \\ } + \\ } + \\ + \\ pub fn getSpec(comptime name:[]const u8) !core.SpecVariantMap { + \\ return try core.createSpecVariant(.{ + \\ .name = name, + ); + + for (moduleList) |mod| { + try writer.print(".{s} = true,\n", .{mod}); + } + + try writer.print("}}, std.heap.c_allocator); }}\n", .{}); + + try writer.print("const std = @import(\"std\");\n", .{}); + + // Write to specified output file + // Open or create the file for writing (overwrites if it exists) + const file = try std.fs.cwd().createFile(out_path, .{}); + defer file.close(); + + try content.append(0); + + var ast = try std.zig.Ast.parse(allocator, @as([:0]const u8, @ptrCast(content.items[0 .. content.items.len - 1])), .zig); + std.debug.print("output={s}", .{content.items[0 .. content.items.len - 1]}); + defer ast.deinit(allocator); + const out = try ast.render(allocator); + + // Write the content to the file + try file.writeAll(out); +} diff --git a/build/generateFwd.zig b/build/generateFwd.zig new file mode 100644 index 0000000..f48e2c6 --- /dev/null +++ b/build/generateFwd.zig @@ -0,0 +1,25 @@ +const std = @import("std"); + +pub fn main() !void { + var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); + defer arena.deinit(); + const allocator = arena.allocator(); + + // Get output filename from build system + const args = try std.process.argsAlloc(allocator); + if (args.len < 2) @panic("Missing output filename"); + const out_path = args[1]; + + // Generate Zig code content + const content = + \\pub const module = @import("module"); + ; + + // Write to specified output file + // Open or create the file for writing (overwrites if it exists) + const file = try std.fs.cwd().createFile(out_path, .{}); + defer file.close(); + + // Write the content to the file + try file.writeAll(content); +} diff --git a/engine/audio/src/embedded/engineTick.wav b/engine/audio/src/embedded/engineTick.wav new file mode 100644 index 0000000000000000000000000000000000000000..b8e482c9528ae0a37d83cc6bd233610bdae9b165 GIT binary patch literal 1746 zcmb8uTTfF#5C`zXi}BHq;8!t$Dz#!kE#9%%76GB6ZNd@J)(aKl4K)?ThG?-K6k4w@ zc%|~>r*i%?yL+xQ@z-?QZBBP*W@iU_W3j)xENgIIswX#5*t^HFtS)+WuUq`?vUXdU zbRpfKXSROBFY*(9z<2TuHaClj#3ATohgp*KL*@l}?y;mjW1}a@DREky5oe+B6~2(q z@CiP`2WYj5!*E{9C|PAV9*-Y{1eh>QkQK*yD;n$#TNU+sU6#pdBgO?bl;j-y2jB=C zWyc_uO08{g{~_&mdy9CgC^c;MnLuQrz&dt~y;PPJRFsvkceK#lfOUA!-oYAk9A~2i zO^AAMg%TKK$Jq&nhg1&aMnfB6S^Umq$4m^tJT$p z_b})z$ZPS6R3?;3ue@>J?_NNS^5=sOpF1{sG^Je*xWdMaao0to=B>J0blQ`5U2!jj z&fTO=na|4}?pW~2k4W>;II5X&#>R6);v7p0z9oE5rk8d1==%FYn4583i%|9}1w4GJ zJTV>{i;D|4JF+QcU%={G%cag{AFv${cJ?Z`@&Cs+%5;kR$n;PCk_){siFPxs7JAIq zn?=-&e!A7s?RmHxQV}Ja6N?;Z+i4FwWF|VGS!L&P;eR@*=tauDm{qX&n1ef>l%r4G P-%8> {s}", .{feature.name}); + + try feature.startupFunc(spec, maybeArgs orelse NwArgs{}, allocator); + try shutdownList.append(allocator, feature.shutdownFunc); + try shutdownModuleNames.append(allocator, feature.name); + + core.engine_logs("module started {s}! ", .{feature.name}); + } + //} +} + pub fn shutdown_modules(allocator: std.mem.Allocator) void { var i: isize = @intCast(shutdownList.items.len - 1); while (i >= 0) : (i -= 1) { diff --git a/engine/core/src/core.zig b/engine/core/src/core.zig index a501e80..b8af51b 100644 --- a/engine/core/src/core.zig +++ b/engine/core/src/core.zig @@ -144,7 +144,13 @@ pub const ComponentList = struct { pub const Scene = scene.Scene; }; -pub fn start_module(map: *SpecVariantMap, args: anytype, allocator: std.mem.Allocator) !void { +pub const ModuleStartupError = error{StartupFailed}; + +pub fn start_module(map: *SpecVariantMap, args: anytype, allocator: std.mem.Allocator) ModuleStartupError!void { + start_module_(map, args, allocator) catch return error.StartupFailed; +} + +pub fn start_module_(map: *SpecVariantMap, args: anytype, allocator: std.mem.Allocator) !void { staticsInitialized = true; if (map.get("utility")) |x| { diff --git a/engine/core/src/extern/externModule.zig b/engine/core/src/extern/externModule.zig index 9309eac..78cd6dd 100644 --- a/engine/core/src/extern/externModule.zig +++ b/engine/core/src/extern/externModule.zig @@ -137,7 +137,7 @@ pub const ModuleLoader = struct { pub fn addModule(self: *@This(), moduleName: []const u8) !void { // modules are always looked for under zig-out/modules if (core.BuildOption("static_build")) { - core.engine_log("[ModuleLoader]: skipping dynamic load, hot loading is not available", .{moduleName}); + core.engine_log("[ModuleLoader]: skipping dynamic load, hot loading is not available", .{}); return; } diff --git a/engine/moduleFwd.zig b/engine/moduleFwd.zig new file mode 100644 index 0000000..bd35ce0 --- /dev/null +++ b/engine/moduleFwd.zig @@ -0,0 +1 @@ +pub const module = @import("module"); diff --git a/engine/moduleStub.zig b/engine/moduleStub.zig new file mode 100644 index 0000000..3e40629 --- /dev/null +++ b/engine/moduleStub.zig @@ -0,0 +1,18 @@ +pub const SpecVariantMap = std.StringHashMap(SpecVariant); + +pub const SpecVariant = union(enum(u8)) { + boolean: bool, + string: []const u8, +}; + +pub fn start_module(map: *SpecVariantMap, args: anytype, allocator: std.mem.Allocator) !void { + _ = map; + _ = args; + _ = allocator; + + std.debug.print("Module init stub. this should never be called"); +} + +pub fn shutdown_module(_: std.mem.Allocator) void {} + +const std = @import("std"); diff --git a/extras/bsp/build.zig b/extras/bsp/build.zig index 9204611..2fc6670 100644 --- a/extras/bsp/build.zig +++ b/extras/bsp/build.zig @@ -3,6 +3,7 @@ const std = @import("std"); 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("bsp", .{ .target = target, @@ -11,7 +12,7 @@ pub fn build(b: *std.Build) void { }); { - const dep = b.dependency("Backlog", .{ .target = target, .optimize = optimize }); + const dep = b.dependency("Backlog", .{ .target = target, .optimize = optimize, .static_build = static_build }); mod.addImport("Backlog", dep.module("Backlog")); } } diff --git a/extras/doomplayer/build.zig b/extras/doomplayer/build.zig index 0a61135..650d17b 100644 --- a/extras/doomplayer/build.zig +++ b/extras/doomplayer/build.zig @@ -3,6 +3,7 @@ const std = @import("std"); 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("doomplayer", .{ .target = target, @@ -19,7 +20,7 @@ pub fn build(b: *std.Build) void { }); { - const dep = b.dependency("Backlog", .{ .target = target, .optimize = optimize }); + const dep = b.dependency("Backlog", .{ .target = target, .optimize = optimize, .static_build = static_build }); mod.addImport("Backlog", dep.module("Backlog")); } } diff --git a/extras/gameExtras/build.zig b/extras/gameExtras/build.zig index 6bd324c..ccb6d2c 100644 --- a/extras/gameExtras/build.zig +++ b/extras/gameExtras/build.zig @@ -10,7 +10,9 @@ pub fn build(b: *std.Build) void { .root_source_file = b.path("src/gameExtras.zig"), }); - const dep = b.dependency("Backlog", .{ .target = target, .optimize = optimize }); + const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false; + + const dep = b.dependency("Backlog", .{ .target = target, .optimize = optimize, .static_build = static_build }); mod.addImport("Backlog", dep.module("Backlog")); } diff --git a/extras/videoplayer/build.zig b/extras/videoplayer/build.zig index a441319..822bfc0 100644 --- a/extras/videoplayer/build.zig +++ b/extras/videoplayer/build.zig @@ -3,6 +3,7 @@ const std = @import("std"); 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("videoplayer", .{ .target = target, @@ -11,7 +12,7 @@ pub fn build(b: *std.Build) void { }); { - const dep = b.dependency("Backlog", .{ .target = target, .optimize = optimize }); + const dep = b.dependency("Backlog", .{ .target = target, .optimize = optimize, .static_build = static_build }); mod.addImport("Backlog", dep.module("Backlog")); } diff --git a/lib/sdl3/build.zig b/lib/sdl3/build.zig index a6409bd..0e6610e 100644 --- a/lib/sdl3/build.zig +++ b/lib/sdl3/build.zig @@ -53,7 +53,8 @@ pub fn build(b: *std.Build) void { }); const sdl3_lib = sdl_dep.artifact("SDL3"); - const sdl3_fwd = b.addModule("sdl3_lib", .{ + + const sdl3_fwd = b.addModule("SDL3", .{ .target = target, .optimize = optimize, .root_source_file = b.path("src/sdl3_lib_fwd.zig"), diff --git a/projects/build.zig.zon b/projects/build.zig.zon index f532bf9..8fc9612 100644 --- a/projects/build.zig.zon +++ b/projects/build.zig.zon @@ -25,7 +25,7 @@ .zphysics = .{.path = "../lib/zphysics"}, .spng = .{ .path = "../lib/spng" }, .ozz = .{ .path = "../lib/ozz" }, - .sdl3_lib = .{ .path = "../lib/sdl3/SDL" }, + .sdl3 = .{ .path = "../lib/sdl3" }, .miniaudio = .{ .path = "../lib/miniaudio" }, .lua = .{ .path = "../lib/lua" }, }, diff --git a/projects/minimal/build.zig b/projects/minimal/build.zig index d00b329..908f9c6 100644 --- a/projects/minimal/build.zig +++ b/projects/minimal/build.zig @@ -11,11 +11,40 @@ pub fn build(b: *std.Build) void { .backlogRoot = "../", }); - _ = blbuild.addProgram(.{ + // const minimalExe = blbuild.addProgram(.{ + // .name = "minimal", + // .desc = "tool program, no assets", + // .root_source_file = b.path("src/main.zig"), + // }); + + // minimalExe.addImport("backlog_api", blbuild.generateApi("minimal", &.{ + // "core", + // "platform", + // "assets", + // "audio", + // "physics", + // "rend", + // "imgui", + // "ui", + // })); + + // // minimalExe.addImport("core", blbuild.nwdep.module("core")); + + // blbuild.addDependencyInstalls(b, .ReleaseFast); //.ReleaseFast); + const minimal = blbuild.program(.{ .name = "minimal", - .desc = "tool program, no assets", + .desc = "simple program built with backlog", .root_source_file = b.path("src/main.zig"), }); - blbuild.addDependencyInstalls(b, .ReleaseFast); //.ReleaseFast); + //// each one here corresponds to a different module under engine/ + //// + //// new build system should make a new 'backlog' + //// that doesn't even get these modules linked in + // + // these are already disabled at the start + minimal.setModuleEnabled("imgui", true); + + _ = minimal.compileInstall(); + ////minimal.addExtraModule(); } diff --git a/projects/minimal/build.zig.zon b/projects/minimal/build.zig.zon index f91ce8c..0f063fa 100644 --- a/projects/minimal/build.zig.zon +++ b/projects/minimal/build.zig.zon @@ -7,12 +7,12 @@ // // .. theoretically if this is a static build, .Backlog = .{ .path = "../../" }, - .SpirvReflect = .{ .path = "../../lib/spirv-reflect-zig" }, + .SpirvReflect = .{ .path = "../../lib/spirv-reflect-zig" }, .zphysics = .{.path = "../../lib/zphysics"}, .spng = .{ .path = "../../lib/spng" }, .ozz = .{ .path = "../../lib/ozz" }, - .sdl3_lib = .{ .path = "../../lib/sdl3/SDL" }, + .sdl3 = .{ .path = "../../lib/sdl3" }, .miniaudio = .{ .path = "../../lib/miniaudio" }, .lua = .{ .path = "../../lib/lua" }, }, diff --git a/projects/minimal/src/main.zig b/projects/minimal/src/main.zig index 5a7f5ab..5f1da02 100644 --- a/projects/minimal/src/main.zig +++ b/projects/minimal/src/main.zig @@ -26,17 +26,12 @@ pub fn deinit(self: *@This()) void { } pub fn main() anyerror!void { - var spec = try bl.createSpecVariant(.{ - .name = "sampleGame", - .imgui = true, - .physics = false, - .audio = false, - }, std.heap.c_allocator); - - _ = bl.initAndRun(&NeonObjectTable, &spec); + var spec = try api.getSpec("minimal"); + _ = api.startEngine(&NeonObjectTable, &spec); } const std = @import("std"); -const bl = @import("Backlog"); -const ig = bl.imgui.api; // imgui api -const core = bl.core; +const api = @import("backlog"); +// const bl = @import("Backlog"); +const ig = api.imgui.api; +const core = api.core;