@@ -150,12 +150,10 @@ fn anyzigLog(
150150
151151const Extent = struct { start : usize , limit : usize };
152152
153- fn extractMinZigVersion (zon : []const u8 ) ? Extent {
154- return extractZigVersion (zon , ".minimum_zig_version" );
155- }
156- fn extractMachZigVersion (zon : []const u8 ) ? Extent {
157- return extractZigVersion (zon , ".mach_zig_version" );
158- }
153+ const key_minimum_zig_version = ".minimum_zig_version" ;
154+ const key_zig_version = ".zig_version" ;
155+ const key_mach_zig_version = ".mach_zig_version" ;
156+
159157fn extractZigVersion (zon : []const u8 , needle : []const u8 ) ? Extent {
160158 var offset : usize = 0 ;
161159 while (true ) {
@@ -249,35 +247,35 @@ fn determineSemanticVersion(scratch: Allocator, build_root: BuildRoot) !Semantic
249247 };
250248 defer scratch .free (zon );
251249
252- if (extractMachZigVersion (zon )) | version_extent | {
250+ for ([_ ][]const u8 {
251+ key_mach_zig_version ,
252+ key_zig_version ,
253+ key_minimum_zig_version ,
254+ }) | key_version | {
255+ const version_extent = extractZigVersion (zon , key_version ) orelse continue ;
253256 const version = zon [version_extent .start .. version_extent .limit ];
254- if (! std .mem .endsWith (u8 , version , "-mach" )) errExit (
255- "expected the .mach_zig_version value to end with '-mach' but got '{s}'" ,
256- .{version },
257- );
257+
258+ if (key_version .ptr == key_mach_zig_version .ptr ) {
259+ if (! std .mem .endsWith (u8 , version , "-mach" )) errExit (
260+ "expected the " ++ key_mach_zig_version ++ " to end with '-mach' but got '{s}'" ,
261+ .{version },
262+ );
263+ }
264+
258265 log .info (
259- "zig mach version '{s}' pulled from '{}build.zig.zon'" ,
260- .{ version , build_root .directory },
266+ "{s} '{s}' pulled from '{}build.zig.zon'" ,
267+ .{ key_version , version , build_root .directory },
261268 );
262269 return SemanticVersion .parse (version ) orelse errExit (
263- "{}build.zig.zon has invalid .mach_zig_version \" {s}\" " ,
264- .{ build_root .directory , version },
270+ "{}build.zig.zon has invalid {s} \" {s}\" " ,
271+ .{ build_root .directory , key_version , version },
265272 );
266273 }
267274
268- const version_extent = extractMinZigVersion ( zon ) orelse errExit (
275+ errExit (
269276 "build.zig.zon is missing minimum_zig_version, either add it or run '{s} VERSION' to specify a version" ,
270277 .{@tagName (build_options .exe )},
271278 );
272- const minimum_zig_version = zon [version_extent .start .. version_extent .limit ];
273- log .info (
274- "zig version '{s}' pulled from '{}build.zig.zon'" ,
275- .{ minimum_zig_version , build_root .directory },
276- );
277- return SemanticVersion .parse (minimum_zig_version ) orelse errExit (
278- "{}build.zig.zon has invalid .minimum_zig_version \" {s}\" " ,
279- .{ build_root .directory , minimum_zig_version },
280- );
281279
282280 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
283281 // TODO: if we find ".{ .path = "..." }" in build.zig then we know zig must be older than 0.13.0
@@ -504,7 +502,7 @@ pub fn main() !void {
504502 , .{semantic_version });
505503 return ;
506504 };
507- const version_extent = extractMinZigVersion (zon ) orelse {
505+ const version_extent = extractZigVersion (zon , key_minimum_zig_version ) orelse {
508506 if (! std .mem .startsWith (u8 , zon , ".{" )) @panic ("zon file did not start with '.{'" );
509507 if (zon .len < 2 or zon [2 ] != '\n ' ) @panic ("zon file not start with '.{\\ n" );
510508 const f = try std .fs .cwd ().createFile ("build.zig.zon" , .{});
0 commit comments