@@ -9,18 +9,21 @@ const current_minor_version = 15;
99
1010const base_version_path = "website/versioned_docs/version-" ;
1111const version_path = switch (zig_version .minor ) {
12- 11 = > base_version_path ++ "0.11.0 " ,
13- 12 = > base_version_path ++ "0.12.1 " ,
14- 13 = > base_version_path ++ "0.13.0 " ,
12+ 11 = > base_version_path ++ "0.11" ,
13+ 12 = > base_version_path ++ "0.12" ,
14+ 13 = > base_version_path ++ "0.13" ,
1515 // 14
1616 15 = > base_version_path ++ "0.15.x" ,
1717 16 = > base_version_path ++ "0.16.x" ,
1818 else = > @compileError ("Unknown version" ),
1919};
2020
21+ const Dir = if (zig_version .minor >= 16 ) std .Io .Dir else std .fs .Dir ;
22+ const Io = if (zig_version .minor >= 16 ) std .Io else void ;
23+
2124/// Returns paths to all files inside version_path with a .zig extension.
2225/// Also tests /blog when current_minor_version is detected.
23- fn getAllTestPaths (root_dir : std.fs. Dir , allocator : std.mem.Allocator ) ! [][]const u8 {
26+ fn getAllTestPaths (root_dir : Dir , allocator : std.mem.Allocator , io : Io ) ! [][]const u8 {
2427 var test_file_paths : std .ArrayList ([]const u8 ) = .empty ;
2528 errdefer {
2629 for (test_file_paths .items ) | test_path | allocator .free (test_path );
@@ -29,11 +32,17 @@ fn getAllTestPaths(root_dir: std.fs.Dir, allocator: std.mem.Allocator) ![][]cons
2932 {
3033 var dirs = try switch (zig_version .minor ) {
3134 11 = > root_dir .openIterableDir (version_path , .{}),
32- else = > root_dir .openDir (version_path , .{ .iterate = true }),
35+ 12... 15 = > root_dir .openDir (version_path , .{ .iterate = true }),
36+ else = > root_dir .openDir (io , version_path , .{ .iterate = true }),
3337 };
34- defer dirs .close ();
38+ defer if (zig_version .minor >= 16 ) dirs .close (io ) else dirs .close ();
39+
3540 var walker = try dirs .walk (allocator );
36- while (try walker .next ()) | entry | {
41+ while (try if (zig_version .minor >= 16 )
42+ walker .next (io )
43+ else
44+ walker .next ()) | entry |
45+ {
3746 if (entry .kind != .file ) continue ;
3847 if (! std .mem .endsWith (u8 , entry .path , ".zig" )) continue ;
3948
@@ -101,7 +110,9 @@ pub fn build(b: *std.Build) !void {
101110 const target = b .standardTargetOptions (.{});
102111 const optimize = b .standardOptimizeOption (.{});
103112
104- const test_file_paths = try getAllTestPaths (b .build_root .handle , b .allocator );
113+ const io = if (zig_version .minor >= 16 ) b .graph .io else {};
114+
115+ const test_file_paths = try getAllTestPaths (b .build_root .handle , b .allocator , io );
105116 defer {
106117 for (test_file_paths ) | test_path | b .allocator .free (test_path );
107118 b .allocator .free (test_file_paths );
@@ -139,78 +150,9 @@ pub fn build(b: *std.Build) !void {
139150 const fmt_step = b .step ("fmt" , "Test all files for correct formatting" );
140151 fmt_step .dependOn (& fmt .step );
141152
142- const dir_logger = DebugDirLogger .create (b );
143- dir_logger .step .dependOn (& write_files .step );
144-
145153 const test_with_fmt = b .step ("test-with-fmt" , "Run unit tests & test all files for correct formatting" );
146154 test_with_fmt .dependOn (test_step );
147155 test_with_fmt .dependOn (fmt_step );
148- test_with_fmt .dependOn (& dir_logger .step );
149156
150157 b .default_step = test_with_fmt ;
151158}
152-
153- const WriteFileStep = switch (zig_version .minor ) {
154- 11 = > std .build .WriteFileStep ,
155- else = > std .Build .Step .WriteFile ,
156- };
157-
158- /// Logs the output directory of its WriteFileStep dependency.
159- const DebugDirLogger = struct {
160- step : std.Build.Step ,
161- pub fn create (owner : * std.Build ) * DebugDirLogger {
162- const ds = owner .allocator .create (DebugDirLogger ) catch @panic ("OOM" );
163- ds .* = .{
164- .step = std .Build .Step .init (.{
165- .id = .custom ,
166- .name = "debug-dir-logger" ,
167- .owner = owner ,
168- .makeFn = switch (zig_version .minor ) {
169- 11 = > makeZig0_11 ,
170- 12 = > makeZig0_12 ,
171- 13 = > makeZig0_13 ,
172- else = > makeZig0_14 ,
173- },
174- }),
175- };
176- return ds ;
177- }
178-
179- /// Bad hack to work on 0.11 and later major versions
180- /// We can't use the real @fieldParentPtr in this file as its parameters
181- /// changed in 0.12.
182- fn fieldParentPtr (step : * std.Build.Step ) * WriteFileStep {
183- return @ptrFromInt (@intFromPtr (step ) - @offsetOf (WriteFileStep , "step" ));
184- }
185-
186- fn makeZig0_11 (step : * std.Build.Step , _ : * std.Progress.Node ) ! void {
187- const dependency = step .dependencies .items [0 ];
188- if (dependency .id != .write_file ) unreachable ; // DebugDirLogger only supports a WriteFileStep dependency
189-
190- std .log .debug (
191- "test-dir at {s}" ,
192- .{fieldParentPtr (dependency ).generated_directory .path .? },
193- );
194- }
195-
196- fn makeZig0_12 (step : * std.Build.Step , _ : * std.Progress.Node ) ! void {
197- try makeZig (step );
198- }
199-
200- fn makeZig0_13 (step : * std.Build.Step , _ : std.Progress.Node ) ! void {
201- try makeZig (step );
202- }
203-
204- fn makeZig0_14 (step : * std.Build.Step , _ : std.Build.Step.MakeOptions ) ! void {
205- try makeZig (step );
206- }
207-
208- fn makeZig (step : * std.Build.Step ) ! void {
209- const dependency = step .dependencies .items [0 ];
210- if (dependency .id != .write_file ) unreachable ; // DebugDirLogger only supports a WriteFileStep dependency
211- std .log .debug (
212- "test-dir at {s}" ,
213- .{fieldParentPtr (dependency ).generated_directory .path .? },
214- );
215- }
216- };
0 commit comments