···11const std = @import("std");
22const builtin = @import("builtin");
33-const compat = @import("src/compat.zig");
43const tests = @import("test/tests.zig");
5466-const Build = compat.Build;
77-const CompileStep = compat.build.CompileStep;
88-const Step = compat.build.Step;
55+const Build = std.Build;
66+const CompileStep = Build.CompileStep;
77+const Step = Build.Step;
98const Child = std.process.Child;
1091110const assert = std.debug.assert;
1211const join = std.fs.path.join;
1312const print = std.debug.print;
1313+1414+// When changing this version, be sure to also update README.md in two places:
1515+// 1) Getting Started
1616+// 2) Version Changes
1717+comptime {
1818+ const required_zig = "0.11.0-dev.4246";
1919+ const current_zig = builtin.zig_version;
2020+ const min_zig = std.SemanticVersion.parse(required_zig) catch unreachable;
2121+ if (current_zig.order(min_zig) == .lt) {
2222+ const error_message =
2323+ \\Sorry, it looks like your version of zig is too old. :-(
2424+ \\
2525+ \\Ziglings requires development build
2626+ \\
2727+ \\{}
2828+ \\
2929+ \\or higher.
3030+ \\
3131+ \\Please download a development ("master") build from
3232+ \\
3333+ \\https://ziglang.org/download/
3434+ \\
3535+ \\
3636+ ;
3737+ @compileError(std.fmt.comptimePrint(error_message, .{min_zig}));
3838+ }
3939+}
14401541const Kind = enum {
1642 /// Run the artifact as a normal executable.
···93119;
9412095121pub fn build(b: *Build) !void {
9696- if (!compat.is_compatible) compat.die();
97122 if (!validate_exercises()) std.os.exit(2);
9812399124 use_color_escapes = false;
-65
src/compat.zig
···11-/// Compatibility support for very old versions of Zig and recent versions before
22-/// commit efa25e7d5 (Merge pull request #14498 from ziglang/zig-build-api).
33-///
44-/// Versions of Zig from before 0.6.0 cannot do the version check and will just
55-/// fail to compile, but 0.5.0 was a long time ago, it is unlikely that anyone
66-/// who attempts these exercises is still using it.
77-const std = @import("std");
88-const builtin = @import("builtin");
99-1010-const debug = std.debug;
1111-1212-// Very old versions of Zig used warn instead of print.
1313-const print = if (@hasDecl(debug, "print")) debug.print else debug.warn;
1414-1515-// When changing this version, be sure to also update README.md in two places:
1616-// 1) Getting Started
1717-// 2) Version Changes
1818-const needed_version_str = "0.11.0-dev.4246";
1919-2020-fn isCompatible() bool {
2121- if (!@hasDecl(builtin, "zig_version") or !@hasDecl(std, "SemanticVersion")) {
2222- return false;
2323- }
2424-2525- const needed_version = std.SemanticVersion.parse(needed_version_str) catch unreachable;
2626- const version = builtin.zig_version;
2727- const order = version.order(needed_version);
2828-2929- return order != .lt;
3030-}
3131-3232-pub fn die() noreturn {
3333- const error_message =
3434- \\ERROR: Sorry, it looks like your version of zig is too old. :-(
3535- \\
3636- \\Ziglings requires development build
3737- \\
3838- \\ {s}
3939- \\
4040- \\or higher. Please download a development ("master") build from
4141- \\
4242- \\ https://ziglang.org/download/
4343- \\
4444- \\
4545- ;
4646-4747- print(error_message, .{needed_version_str});
4848-4949- // Use exit code 2, to differentiate from a normal Zig compiler error.
5050- std.os.exit(2);
5151-}
5252-5353-// A separate function is required because very old versions of Zig doesn't
5454-// support labeled block expressions.
5555-pub const is_compatible: bool = isCompatible();
5656-5757-/// This is the type to be used only for the build function definition, since
5858-/// the type must be compatible with the build runner.
5959-///
6060-/// Don't use std.Build.Builder, since it is deprecated and may be removed in
6161-/// future.
6262-pub const Build = if (is_compatible) std.Build else std.build.Builder;
6363-6464-/// This is the type to be used for accessing the build namespace.
6565-pub const build = if (is_compatible) std.Build else std.build;