build(zig): use ArrayListUnmanaged

This is supported in 0.14 and 0.15

(cherry picked from commit 298b6775c6)
This commit is contained in:
ObserverOfTime 2025-08-26 22:49:18 +03:00
parent 910b3c738c
commit dc0b5530b3
2 changed files with 7 additions and 4 deletions

View file

@ -25,9 +25,11 @@ pub fn build(b: *std.Build) !void {
.flags = &.{"-std=c11"},
});
} else {
const files = try findSourceFiles(b);
defer b.allocator.free(files);
lib.addCSourceFiles(.{
.root = b.path("lib/src"),
.files = try findSourceFiles(b),
.files = files,
.flags = &.{"-std=c11"},
});
}
@ -96,7 +98,7 @@ pub fn wasmtimeDep(target: std.Target) []const u8 {
}
fn findSourceFiles(b: *std.Build) ![]const []const u8 {
var sources = std.ArrayList([]const u8).init(b.allocator);
var sources: std.ArrayListUnmanaged([]const u8) = .empty;
var dir = try b.build_root.handle.openDir("lib/src", .{ .iterate = true });
var iter = dir.iterate();
@ -107,9 +109,9 @@ fn findSourceFiles(b: *std.Build) ![]const []const u8 {
const file = entry.name;
const ext = std.fs.path.extension(file);
if (std.mem.eql(u8, ext, ".c") and !std.mem.eql(u8, file, "lib.c")) {
try sources.append(b.dupe(file));
try sources.append(b.allocator, b.dupe(file));
}
}
return sources.items;
return sources.toOwnedSlice(b.allocator);
}

View file

@ -2,6 +2,7 @@
.name = .tree_sitter,
.fingerprint = 0x841224b447ac0d4f,
.version = "0.25.8",
.minimum_zig_version = "0.14.1",
.paths = .{
"build.zig",
"build.zig.zon",