diff --git a/build.zig b/build.zig index 64afee96..19dcb944 100644 --- a/build.zig +++ b/build.zig @@ -56,47 +56,59 @@ pub fn build(b: *std.Build) !void { &.{ "/D _CRT_SECURE_NO_WARNINGS", "/WX" } else &.{"-Wall -Wextra -Werror"}; + const allocator = std.heap.smp_allocator; + var threaded: std.Io.Threaded = .init(allocator, .{ + .environ = std.process.Environ.empty, + }); + + const io = threaded.io(); const soem_sources = try globFiles( b.path("soem"), - std.heap.smp_allocator, + allocator, + io, .{ .extension = "c" }, ); - defer std.heap.smp_allocator.free(soem_sources); + defer allocator.free(soem_sources); const soem_headers = try globFiles( b.path("soem"), - std.heap.smp_allocator, + allocator, + io, .{ .extension = "h" }, ); - defer std.heap.smp_allocator.free(soem_headers); + defer allocator.free(soem_headers); const osal_path = b.path("osal").path(b, os_subdir); const osal_sources = try globFiles( osal_path, - std.heap.smp_allocator, + allocator, + io, .{ .extension = "c" }, ); - defer std.heap.smp_allocator.free(osal_sources); + defer allocator.free(osal_sources); const osal_headers = try globFiles( osal_path, - std.heap.smp_allocator, + allocator, + io, .{ .extension = "h" }, ); - defer std.heap.smp_allocator.free(osal_headers); + defer allocator.free(osal_headers); const oshw_path = b.path("oshw").path(b, os_subdir); const oshw_sources = try globFiles( oshw_path, - std.heap.smp_allocator, + allocator, + io, .{ .extension = "c" }, ); - defer std.heap.smp_allocator.free(oshw_sources); + defer allocator.free(oshw_sources); const oshw_headers = try globFiles( oshw_path, - std.heap.smp_allocator, + allocator, + io, .{ .extension = "h" }, ); - defer std.heap.smp_allocator.free(oshw_headers); + defer allocator.free(oshw_headers); lib_mod.addCSourceFiles(.{ .root = b.path("soem"), @@ -179,12 +191,12 @@ const GlobOptions = struct { recursive: bool = false, }; -fn countFiles(dir: std.fs.Dir, options: GlobOptions) !usize { +fn countFiles(io: std.Io, dir: std.Io.Dir, options: GlobOptions) !usize { var walker = dir.iterate(); var total_count: usize = 0; // Walk once to get total file count. - while (try walker.next()) |entry| { + while (try walker.next(io)) |entry| { if (entry.kind == .file) { if (options.extension.len > 0) { const extension = @@ -197,9 +209,9 @@ fn countFiles(dir: std.fs.Dir, options: GlobOptions) !usize { total_count += 1; } } else if (entry.kind == .directory and options.recursive) { - var sub_dir = try dir.openDir(entry.name, .{ .iterate = true }); - defer sub_dir.close(); - total_count += try countFiles(sub_dir, options); + var sub_dir = try dir.openDir(io, entry.name, .{ .iterate = true }); + defer sub_dir.close(io); + total_count += try countFiles(io, sub_dir, options); } } @@ -207,7 +219,8 @@ fn countFiles(dir: std.fs.Dir, options: GlobOptions) !usize { } fn globInner( - dir: std.fs.Dir, + io: std.Io, + dir: std.Io.Dir, allocator: std.mem.Allocator, results: [][]u8, filled_: usize, @@ -217,7 +230,7 @@ fn globInner( var filled = filled_; // Walk once to get total file count. - while (try walker.next()) |entry| { + while (try walker.next(io)) |entry| { if (entry.kind == .file) { if (options.extension.len > 0) { const extension = @@ -232,10 +245,10 @@ fn globInner( filled += 1; } } else if (entry.kind == .directory and options.recursive) { - var sub_dir = try dir.openDir(entry.name, .{ .iterate = true }); - defer sub_dir.close(); + var sub_dir = try dir.openDir(io, entry.name, .{ .iterate = true }); + defer sub_dir.close(io); - try globInner(sub_dir, allocator, results, filled, options); + try globInner(io, sub_dir, allocator, results, filled, options); } } } @@ -243,29 +256,32 @@ fn globInner( fn globFiles( path: std.Build.LazyPath, allocator: std.mem.Allocator, + io: std.Io, options: GlobOptions, ) ![]const []const u8 { var dir = switch (path) { - .cwd_relative => try std.fs.cwd().openDir( + .cwd_relative => try std.Io.Dir.cwd().openDir( + io, path.src_path.sub_path, .{ .iterate = true }, ), .src_path => |sp| try sp.owner.build_root.handle.openDir( + io, sp.sub_path, .{ .iterate = true }, ), else => unreachable, }; - defer dir.close(); + defer dir.close(io); - const total_count = try countFiles(dir, options); + const total_count = try countFiles(io, dir, options); const result: [][]u8 = try allocator.alloc([]u8, total_count); for (result) |*file| { file.* = &.{}; } - try globInner(dir, allocator, result, 0, options); + try globInner(io, dir, allocator, result, 0, options); return result; } diff --git a/build.zig.zon b/build.zig.zon index 4e0184b8..779ddaa2 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,7 +1,7 @@ .{ .name = .soem, .fingerprint = 0x30ccde7443fac184, - .minimum_zig_version = "0.14.0", + .minimum_zig_version = "0.16.0-dev.2187+e2338edb4", .version = "1.4.0", .paths = .{ "soem",