From b46c6f6dc81015e283653d58c5b0c04b26c2d445 Mon Sep 17 00:00:00 2001 From: IonutParau Date: Wed, 1 Oct 2025 16:53:49 +0200 Subject: [PATCH] fixed a massive bug --- build.zig | 36 ++++++++++++++++------------- src/components/volatileFilesystem.c | 8 ++++--- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/build.zig b/build.zig index 5c061d7..cad21df 100644 --- a/build.zig +++ b/build.zig @@ -15,6 +15,7 @@ fn addEngineSources(b: *std.Build, opts: LibBuildOpts) *std.Build.Module { .optimize = opts.optimize, .strip = if(opts.optimize == .Debug) false else true, .unwind_tables = if(opts.optimize == .Debug) null else .none, + .pic = true, }); const strict = opts.optimize != .Debug; @@ -89,20 +90,23 @@ fn compileTheRightLua(b: *std.Build, target: std.Build.ResolvedTarget, version: const dirName = @tagName(version); // its a static library because COFF is a pile of shit - const c = b.addStaticLibrary(.{ + const c = b.addLibrary(.{ .name = "lua", - .link_libc = true, - .optimize = .ReleaseFast, - .target = target, + .root_module = b.addModule("luamod", .{ + .link_libc = true, + .optimize = .ReleaseFast, + .target = target, + }), + .linkage = .static, }); const rootPath = try std.mem.join(alloc, std.fs.path.sep_str, &.{ "foreign", dirName }); // get all the .c files - var files = std.ArrayList([]const u8).init(alloc); - errdefer files.deinit(); + var files = try std.ArrayList([]const u8).initCapacity(b.allocator, 0); + errdefer files.deinit(b.allocator); - var dir = try std.fs.cwd().openDir(rootPath, std.fs.Dir.OpenDirOptions{ .iterate = true }); + var dir = try std.fs.cwd().openDir(rootPath, std.fs.Dir.OpenOptions { .iterate = true }); defer dir.close(); var iter = dir.iterate(); @@ -110,7 +114,7 @@ fn compileTheRightLua(b: *std.Build, target: std.Build.ResolvedTarget, version: while (try iter.next()) |e| { if (std.mem.startsWith(u8, e.name, "l") and std.mem.endsWith(u8, e.name, ".c") and !std.mem.eql(u8, e.name, "lua.c")) { const name = try alloc.dupe(u8, e.name); - try files.append(name); + try files.append(b.allocator, name); } } @@ -151,18 +155,16 @@ pub fn build(b: *std.Build) !void { const engineMod = addEngineSources(b, opts); - const engineStatic = b.addStaticLibrary(.{ + const engineStatic = b.addLibrary(.{ .name = "neonucleus", .root_module = engineMod, - .pic = true, - .code_model = .default, + .linkage = .static, }); - const engineShared = b.addSharedLibrary(.{ + const engineShared = b.addLibrary(.{ .name = if(os == .windows) "neonucleusdll" else "neonucleus", .root_module = engineMod, - .pic = true, - .code_model = .default, + .linkage = .dynamic, }); const engineStep = b.step("engine", "Builds the engine as a static library"); @@ -178,8 +180,10 @@ pub fn build(b: *std.Build) !void { if(!noEmu) { const emulator = b.addExecutable(.{ .name = "neonucleus", - .target = target, - .optimize = optimize, + .root_module = b.addModule("emulator", .{ + .target = target, + .optimize = optimize, + }), }); emulator.linkLibC(); diff --git a/src/components/volatileFilesystem.c b/src/components/volatileFilesystem.c index 4d2bdba..c4ab36b 100644 --- a/src/components/volatileFilesystem.c +++ b/src/components/volatileFilesystem.c @@ -565,15 +565,16 @@ static nn_vfilesystemImageNode nni_vfsimg_nextNode(nn_vfilesystemImage *stream) return node; } -static nn_vfnode *nni_vfsimg_parseNode(nn_vfilesystem *fs, nn_vfilesystemImage *stream) { +static nn_vfnode *nni_vfsimg_parseNode(nn_vfilesystem *fs, nn_vfilesystemImage *stream, nn_vfnode *parent) { // TODO: make this handle OOMs nn_vfilesystemImageNode node = nni_vfsimg_nextNode(stream); if(node.data == NULL) { // directory!!!!! nn_vfnode *dir = nn_vf_allocDirectory(fs, node.name); dir->len = node.len; + dir->parent = parent; for(int i = 0; i < node.len; i++) { - nn_vfnode *entry = nni_vfsimg_parseNode(fs, stream); + nn_vfnode *entry = nni_vfsimg_parseNode(fs, stream, dir); dir->entries[i] = entry; } return dir; @@ -582,6 +583,7 @@ static nn_vfnode *nni_vfsimg_parseNode(nn_vfilesystem *fs, nn_vfilesystemImage * nn_vfnode *file = nn_vf_allocFile(fs, node.name); nn_vf_ensureFileCapacity(file, node.len); file->len = node.len; + file->parent = parent; nn_memcpy(file->data, node.data, node.len); return file; } @@ -606,7 +608,7 @@ nn_filesystem *nn_volatileFilesystem(nn_Context *context, nn_vfilesystemOptions // we got supplied an image, shit fs->root->len = opts.rootEntriesInImage; for(int i = 0; i < opts.rootEntriesInImage; i++) { - nn_vfnode *entry = nni_vfsimg_parseNode(fs, &stream); + nn_vfnode *entry = nni_vfsimg_parseNode(fs, &stream, fs->root); fs->root->entries[i] = entry; } }