authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-11-19 13:05:03+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-11-20 10:42:20+00:00
loge1fa4011fbe812dc7d05326239a62388b591ba52
treeea1d481ee0c24f09f1f23ce948e665c2c1ac5347
parent010dcd6a9b64d5bd13579a4b0c4c70a5aee5c967
signaturelock-open Commit is signed but in an unrecognized format.

fuzz: hack around unknown module structure


1 files changed, 15 insertions(+), 14 deletions(-)

lib/build-web/fuzz.zig+15-14
......@@ -228,20 +228,21 @@ fn unpackSourcesInner(tar_bytes: []u8) !void {
228228 if (std.mem.endsWith(u8, tar_file.name, ".zig")) {
229229 log.debug("found file: '{s}'", .{tar_file.name});
230230 const file_name = try gpa.dupe(u8, tar_file.name);
231 if (std.mem.indexOfScalar(u8, file_name, '/')) |pkg_name_end| {
232 const pkg_name = file_name[0..pkg_name_end];
233 const gop = try Walk.modules.getOrPut(gpa, pkg_name);
234 const file: Walk.File.Index = @enumFromInt(Walk.files.entries.len);
235 if (!gop.found_existing or
236 std.mem.eql(u8, file_name[pkg_name_end..], "/root.zig") or
237 std.mem.eql(u8, file_name[pkg_name_end + 1 .. file_name.len - ".zig".len], pkg_name))
238 {
239 gop.value_ptr.* = file;
240 }
241 const file_bytes = tar_reader.take(@intCast(tar_file.size)) catch unreachable;
242 it.unread_file_bytes = 0; // we have read the whole thing
243 assert(file == try Walk.add_file(file_name, file_bytes));
244 }
231 // This is a hack to guess modules from the tar file contents. To handle modules
232 // properly, the build system will need to change the structure here to have one
233 // directory per module. This in turn requires compiler enhancements to allow
234 // the build system to actually discover the required information.
235 const mod_name, const is_module_root = p: {
236 if (std.mem.find(u8, file_name, "std/")) |i| break :p .{ "std", std.mem.eql(u8, file_name[i + 4 ..], "std.zig") };
237 if (std.mem.endsWith(u8, file_name, "/builtin.zig")) break :p .{ "builtin", true };
238 break :p .{ "root", std.mem.endsWith(u8, file_name, "/root.zig") };
239 };
240 const gop = try Walk.modules.getOrPut(gpa, mod_name);
241 const file: Walk.File.Index = @enumFromInt(Walk.files.entries.len);
242 if (!gop.found_existing or is_module_root) gop.value_ptr.* = file;
243 const file_bytes = tar_reader.take(@intCast(tar_file.size)) catch unreachable;
244 it.unread_file_bytes = 0; // we have read the whole thing
245 assert(file == try Walk.add_file(file_name, file_bytes));
245246 } else {
246247 log.warn("skipping: '{s}' - the tar creation should have done that", .{tar_file.name});
247248 }