fixed all tests and added bh.zig

This commit is contained in:
peterino2 2025-11-06 20:42:48 -08:00
parent 5fbc11e1a1
commit 1572f96429
25 changed files with 178 additions and 36 deletions

77
lib/bh/build.zig vendored Normal file
View File

@ -0,0 +1,77 @@
const std = @import("std");
pub const ModLib = struct {
b: *std.Build,
lib: *std.Build.Step.Compile,
mod: *std.Build.Module,
pub fn install(self: @This()) void {
self.b.installArtifact(self.lib);
}
};
pub const ModLibOptions = struct {
name: []const u8,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
static_build: bool,
allow_dynamic: bool = false,
link_libc: bool = false,
link_libcpp: bool = false,
root: ?std.Build.LazyPath = null,
stub: ?std.Build.LazyPath = null,
};
pub fn MakeModlib(b: *std.Build, o: ModLibOptions) ModLib {
const mod = b.addModule(o.name, .{
.target = o.target,
.optimize = o.optimize,
.root_source_file = if (o.root != null) o.root.? else b.path(b.fmt("src/{s}", .{o.name})),
});
const empty_file = b.addWriteFile("stubs", "");
const lib = b.addLibrary(.{
.name = o.name,
.linkage = if (o.allow_dynamic and !o.static_build) .dynamic else .static,
.root_module = b.createModule(.{
.root_source_file = empty_file.add("stubc.zig", ""),
.target = o.target,
.optimize = o.optimize,
}),
});
return .{
.b = b,
.lib = lib,
.mod = mod,
};
}
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 r = MakeModlib(b, .{
.name = "bh",
.target = target,
.optimize = optimize,
.static_build = static_build,
});
b.installArtifact(r.lib);
const test_step = b.step("test", "run unit tests for enet");
const tests = b.addTest(.{
.root_module = b.createModule(.{
.link_libc = true,
.target = target,
.optimize = optimize,
.root_source_file = b.path("src/tests.zig"),
}),
});
const runArtifact = b.addRunArtifact(tests);
test_step.dependOn(&runArtifact.step);
}

10
lib/bh/build.zig.zon vendored Normal file
View File

@ -0,0 +1,10 @@
.{
.name = .bh,
.version = "0.0.0",
.dependencies = .{
},
.paths = .{
"",
},
.fingerprint = 0x557bf2b094ba1492,
}

0
lib/bh/src/bh.zig vendored Normal file
View File

0
lib/bh/src/tests.zig vendored Normal file
View File

0
lib/bh/stubc.zig vendored Normal file
View File

View File

@ -2,6 +2,7 @@
.name = .imgui, .name = .imgui,
.version = "0.0.0", .version = "0.0.0",
.dependencies = .{ .dependencies = .{
.bh = .{ .path = "../bh" },
.core = .{ .path = "../core" }, .core = .{ .path = "../core" },
}, },
.paths = .{ .paths = .{

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

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

View File

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

View File

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

View File

@ -1,7 +1,10 @@
.{ .{
.name = .nfd, .name = .nfd,
.version = "0.0.0", .version = "0.0.0",
.dependencies = .{ .p2 = .{ .path = "../p2" } }, .dependencies = .{
.bh = .{ .path = "../bh" },
.p2 = .{ .path = "../p2" },
},
.paths = .{ .paths = .{
"", "",
}, },

View File

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

View File

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

View File

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

View File

@ -1,7 +1,10 @@
.{ .{
.name = .packer, .name = .packer,
.version = "0.0.0", .version = "0.0.0",
.dependencies = .{ .p2 = .{ .path = "../p2" } }, .dependencies = .{
.bh = .{ .path = "../bh" },
.p2 = .{ .path = "../p2" },
},
.paths = .{ .paths = .{
"", "",
}, },

View File

@ -128,22 +128,3 @@ fn fileChangedCb(pathChanged: []const u8, ctx: ?*anyopaque) void {
_ = ctx; _ = ctx;
std.debug.print("pathChanged {s}\n", .{pathChanged}); std.debug.print("pathChanged {s}\n", .{pathChanged});
} }
test "packer file watch" {
var fs = try PackerFS.init(std.testing.allocator, .{});
defer fs.destroy();
std.fs.cwd().deleteFile("test_output/test2.txt") catch {};
try fs.addContentPath("test_output");
fs.watchPath("test_output");
try fs.addFileChangedCallback("test2.txt", fileChangedCb, null);
var file = try std.fs.cwd().createFile("test_output/test2.txt", .{});
std.Thread.sleep(100000000);
std.debug.print("writing to file\n", .{});
// var file = try std.fs.cwd().openFile("test_output/test2.txt", .{ .mode = .read_write });
try file.writeAll("what the fuck bro");
std.Thread.sleep(400000000);
// std.Thread.sleep(5000000000);
}

View File

@ -3,6 +3,7 @@
.version = "0.0.0", .version = "0.0.0",
.fingerprint=0x6188f62f190b5e67, .fingerprint=0x6188f62f190b5e67,
.dependencies = .{ .dependencies = .{
.bh = .{ .path = "../bh" },
.sdl = .{ .path = "SDL/" }, .sdl = .{ .path = "SDL/" },
.shaderTypes = .{ .path = "shaderTypes/" }, .shaderTypes = .{ .path = "shaderTypes/" },
}, },

View File

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

35
lib/test.zig vendored Normal file
View File

@ -0,0 +1,35 @@
const MyCharacter = struct {
pub var API = machinery.Interface(@This()).VTable;
x: u32 = 0,
y: u32 = 0,
z: u32 = 0,
// any function with 'self' as an argument is automatically added to the InterfaceVTable
// shit.. do i need to make a way to generate a struct from the arguments to the
// function?
pub fn add(self: *@This(), new: u32) void {
self.z = self.x + self.y + new;
}
// any error functions called through the api wrapper has it's errors wrapped and narrowed,
// and logged
pub fn sub(self: *@This()) void {
self.z = self.x - self.y;
}
pub fn callMyOwnInterfaces() void {
machinery.call(API, "add", .{ .new = 32 });
// could add a helper inside API that just aliases to machinery.call
API.call("add", .{ .new = 32 });
}
};
const SomeOtherModule = struct {
// if this was another file id do
// const MyCharacter = @import("MyCharacterApi").API;
const MyCharacterApi = MyCharacter.API;
pub var API = machinery.Interface(@This()).VTable;
};
const machinery = @import("machinery");

View File

@ -2,6 +2,7 @@
.name = .theorafile, .name = .theorafile,
.version = "0.0.0", .version = "0.0.0",
.dependencies = .{ .dependencies = .{
.bh = .{ .path = "../bh" },
.sdl = .{ .path = "../sdl3/SDL" }, .sdl = .{ .path = "../sdl3/SDL" },
}, },
.paths = .{ .paths = .{

View File

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

View File

@ -2,8 +2,4 @@ const tracy = @import("tracy").t;
const std = @import("std"); const std = @import("std");
test "test-tracy-integration" { test "test-tracy-integration" {}
const z = tracy.t.ZoneNC(@src(), "hello", 0xaaaaaa);
std.debug.print("tracy integration testing enabled = {any}", .{tracy.enabled});
z.End();
}

View File

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

View File

@ -3,7 +3,9 @@
.version = "0.1.0", .version = "0.1.0",
.fingerprint = 0x7dfe8a1202907eb1, .fingerprint = 0x7dfe8a1202907eb1,
.minimum_zig_version = "0.15.1", .minimum_zig_version = "0.15.1",
.dependencies = .{}, .dependencies = .{
.bh = .{ .path = "../bh" },
},
.paths = .{ .paths = .{
".github", ".github",
".gitignore", ".gitignore",

View File

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

View File

@ -3,6 +3,9 @@
.fingerprint = 0x1def6aac00c4909d, .fingerprint = 0x1def6aac00c4909d,
.version = "0.2.0-dev", .version = "0.2.0-dev",
.minimum_zig_version = "0.15.1", .minimum_zig_version = "0.15.1",
.dependencies = .{
.bh = .{ .path = "../bh" },
},
.paths = .{ .paths = .{
"build.zig", "build.zig",
"build.zig.zon", "build.zig.zon",