|
1 | 1 | const std = @import("std");
|
2 | 2 | const builtin = @import("builtin");
|
3 |
| -const Builder = std.build.Builder; |
4 |
| -const Step = std.build.Step; |
| 3 | +const compat = @import("src/compat.zig"); |
| 4 | + |
| 5 | +const Build = compat.Build; |
| 6 | +const Step = compat.build.Step; |
| 7 | + |
5 | 8 | const assert = std.debug.assert;
|
6 | 9 | const print = std.debug.print;
|
7 | 10 |
|
8 |
| -// When changing this version, be sure to also update README.md in two places: |
9 |
| -// 1) Getting Started |
10 |
| -// 2) Version Changes |
11 |
| -const needed_version = std.SemanticVersion.parse("0.11.0-dev.2157") catch unreachable; |
12 |
| - |
13 | 11 | const Exercise = struct {
|
14 | 12 | /// main_file must have the format key_name.zig.
|
15 | 13 | /// The key will be used as a shorthand to build
|
@@ -493,44 +491,8 @@ const exercises = [_]Exercise{
|
493 | 491 | },
|
494 | 492 | };
|
495 | 493 |
|
496 |
| -/// Check the zig version to make sure it can compile the examples properly. |
497 |
| -/// This will compile with Zig 0.6.0 and later. |
498 |
| -fn checkVersion() bool { |
499 |
| - if (!@hasDecl(builtin, "zig_version")) { |
500 |
| - return false; |
501 |
| - } |
502 |
| - |
503 |
| - const version = builtin.zig_version; |
504 |
| - const order = version.order(needed_version); |
505 |
| - return order != .lt; |
506 |
| -} |
507 |
| - |
508 |
| -pub fn build(b: *Builder) !void { |
509 |
| - // Use a comptime branch for the version check. |
510 |
| - // If this fails, code after this block is not compiled. |
511 |
| - // It is parsed though, so versions of zig from before 0.6.0 |
512 |
| - // cannot do the version check and will just fail to compile. |
513 |
| - // We could fix this by moving the ziglings code to a separate file, |
514 |
| - // but 0.5.0 was a long time ago, it is unlikely that anyone who |
515 |
| - // attempts these exercises is still using it. |
516 |
| - if (comptime !checkVersion()) { |
517 |
| - // very old versions of Zig used warn instead of print. |
518 |
| - const stderrPrintFn = if (@hasDecl(std.debug, "print")) std.debug.print else std.debug.warn; |
519 |
| - stderrPrintFn( |
520 |
| - \\ERROR: Sorry, it looks like your version of zig is too old. :-( |
521 |
| - \\ |
522 |
| - \\Ziglings requires development build |
523 |
| - \\ |
524 |
| - \\ {} |
525 |
| - \\ |
526 |
| - \\or higher. Please download a development ("master") build from |
527 |
| - \\ |
528 |
| - \\ https://ziglang.org/download/ |
529 |
| - \\ |
530 |
| - \\ |
531 |
| - , .{needed_version}); |
532 |
| - std.os.exit(0); |
533 |
| - } |
| 494 | +pub fn build(b: *Build) !void { |
| 495 | + if (!compat.is_compatible) compat.die(); |
534 | 496 |
|
535 | 497 | use_color_escapes = false;
|
536 | 498 | if (std.io.getStdErr().supportsAnsiEscapeCodes()) {
|
@@ -629,10 +591,10 @@ var reset_text: []const u8 = "";
|
629 | 591 | const ZiglingStep = struct {
|
630 | 592 | step: Step,
|
631 | 593 | exercise: Exercise,
|
632 |
| - builder: *Builder, |
| 594 | + builder: *Build, |
633 | 595 | use_healed: bool,
|
634 | 596 |
|
635 |
| - pub fn create(builder: *Builder, exercise: Exercise, use_healed: bool) *@This() { |
| 597 | + pub fn create(builder: *Build, exercise: Exercise, use_healed: bool) *@This() { |
636 | 598 | const self = builder.allocator.create(@This()) catch unreachable;
|
637 | 599 | self.* = .{
|
638 | 600 | .step = Step.init(Step.Options{ .id = .custom, .name = exercise.main_file, .owner = builder, .makeFn = make }),
|
@@ -813,7 +775,7 @@ const PrintStep = struct {
|
813 | 775 | message: []const u8,
|
814 | 776 | file: std.fs.File,
|
815 | 777 |
|
816 |
| - pub fn create(owner: *std.Build, message: []const u8, file: std.fs.File) *PrintStep { |
| 778 | + pub fn create(owner: *Build, message: []const u8, file: std.fs.File) *PrintStep { |
817 | 779 | const self = owner.allocator.create(PrintStep) catch @panic("OOM");
|
818 | 780 | self.* = .{
|
819 | 781 | .step = Step.init(.{
|
|
0 commit comments