my ziglings
0

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request 'changed compat check to comptime' (#11) from fix_compat into main

Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/11

Chris Boesch (Oct 5, 2023, 10:39 PM UTC) 88a8e064 2ba613b1

+30 -70
+30 -5
build.zig
··· 1 1 const std = @import("std"); 2 2 const builtin = @import("builtin"); 3 - const compat = @import("src/compat.zig"); 4 3 const tests = @import("test/tests.zig"); 5 4 6 - const Build = compat.Build; 7 - const CompileStep = compat.build.CompileStep; 8 - const Step = compat.build.Step; 5 + const Build = std.Build; 6 + const CompileStep = Build.CompileStep; 7 + const Step = Build.Step; 9 8 const Child = std.process.Child; 10 9 11 10 const assert = std.debug.assert; 12 11 const join = std.fs.path.join; 13 12 const print = std.debug.print; 13 + 14 + // When changing this version, be sure to also update README.md in two places: 15 + // 1) Getting Started 16 + // 2) Version Changes 17 + comptime { 18 + const required_zig = "0.11.0-dev.4246"; 19 + const current_zig = builtin.zig_version; 20 + const min_zig = std.SemanticVersion.parse(required_zig) catch unreachable; 21 + if (current_zig.order(min_zig) == .lt) { 22 + const error_message = 23 + \\Sorry, it looks like your version of zig is too old. :-( 24 + \\ 25 + \\Ziglings requires development build 26 + \\ 27 + \\{} 28 + \\ 29 + \\or higher. 30 + \\ 31 + \\Please download a development ("master") build from 32 + \\ 33 + \\https://ziglang.org/download/ 34 + \\ 35 + \\ 36 + ; 37 + @compileError(std.fmt.comptimePrint(error_message, .{min_zig})); 38 + } 39 + } 14 40 15 41 const Kind = enum { 16 42 /// Run the artifact as a normal executable. ··· 93 119 ; 94 120 95 121 pub fn build(b: *Build) !void { 96 - if (!compat.is_compatible) compat.die(); 97 122 if (!validate_exercises()) std.os.exit(2); 98 123 99 124 use_color_escapes = false;
-65
src/compat.zig
··· 1 - /// Compatibility support for very old versions of Zig and recent versions before 2 - /// commit efa25e7d5 (Merge pull request #14498 from ziglang/zig-build-api). 3 - /// 4 - /// Versions of Zig from before 0.6.0 cannot do the version check and will just 5 - /// fail to compile, but 0.5.0 was a long time ago, it is unlikely that anyone 6 - /// who attempts these exercises is still using it. 7 - const std = @import("std"); 8 - const builtin = @import("builtin"); 9 - 10 - const debug = std.debug; 11 - 12 - // Very old versions of Zig used warn instead of print. 13 - const print = if (@hasDecl(debug, "print")) debug.print else debug.warn; 14 - 15 - // When changing this version, be sure to also update README.md in two places: 16 - // 1) Getting Started 17 - // 2) Version Changes 18 - const needed_version_str = "0.11.0-dev.4246"; 19 - 20 - fn isCompatible() bool { 21 - if (!@hasDecl(builtin, "zig_version") or !@hasDecl(std, "SemanticVersion")) { 22 - return false; 23 - } 24 - 25 - const needed_version = std.SemanticVersion.parse(needed_version_str) catch unreachable; 26 - const version = builtin.zig_version; 27 - const order = version.order(needed_version); 28 - 29 - return order != .lt; 30 - } 31 - 32 - pub fn die() noreturn { 33 - const error_message = 34 - \\ERROR: Sorry, it looks like your version of zig is too old. :-( 35 - \\ 36 - \\Ziglings requires development build 37 - \\ 38 - \\ {s} 39 - \\ 40 - \\or higher. Please download a development ("master") build from 41 - \\ 42 - \\ https://ziglang.org/download/ 43 - \\ 44 - \\ 45 - ; 46 - 47 - print(error_message, .{needed_version_str}); 48 - 49 - // Use exit code 2, to differentiate from a normal Zig compiler error. 50 - std.os.exit(2); 51 - } 52 - 53 - // A separate function is required because very old versions of Zig doesn't 54 - // support labeled block expressions. 55 - pub const is_compatible: bool = isCompatible(); 56 - 57 - /// This is the type to be used only for the build function definition, since 58 - /// the type must be compatible with the build runner. 59 - /// 60 - /// Don't use std.Build.Builder, since it is deprecated and may be removed in 61 - /// future. 62 - pub const Build = if (is_compatible) std.Build else std.build.Builder; 63 - 64 - /// This is the type to be used for accessing the build namespace. 65 - pub const build = if (is_compatible) std.Build else std.build;