diff options
Diffstat (limited to 'build.zig')
-rw-r--r-- | build.zig | 41 |
1 files changed, 29 insertions, 12 deletions
@@ -236,6 +236,14 @@ const exercises = [_]Exercise{ .output = "Elephant A. Elephant B. Elephant C.", .hint = "Oh no! We forgot Elephant B!", }, + .{ + .main_file = "45_optionals.zig", + .output = "The Ultimate Answer: 42.", + }, + // optional fields (elephant tail - no longer need circular) + // super-simple struct method + // use struct method for elephant tails + // quiz: add elephant trunk (like tail)! }; /// Check the zig version to make sure it can compile the examples properly. @@ -263,7 +271,11 @@ pub fn build(b: *Builder) void { // very old versions of Zig used warn instead of print. const stderrPrintFn = if (@hasDecl(std.debug, "print")) std.debug.print else std.debug.warn; stderrPrintFn( - \\Error: Your version of zig is too old. Please download a master build from + \\ERROR: Sorry, it looks like your version of zig is too old. :-( + \\ + \\The README lists the minimum version and build number. + \\ + \\Please download a master build from \\https://ziglang.org/download/ \\ , .{}); @@ -316,39 +328,41 @@ pub fn build(b: *Builder) void { \\ , .{}); - const verify_all = b.step("ziglings", "Verify all ziglings"); + const verify_all = b.step("ziglings", "Check all ziglings"); verify_all.dependOn(&header_step.step); b.default_step = verify_all; var prev_chain_verify = verify_all; + const use_healed = b.option(bool, "healed", "Run exercises from patches/healed") orelse false; + for (exercises) |ex| { const base_name = ex.baseName(); const file_path = std.fs.path.join(b.allocator, &[_][]const u8{ - "exercises", ex.main_file, + if (use_healed) "patches/healed" else "exercises", ex.main_file, }) catch unreachable; const build_step = b.addExecutable(base_name, file_path); build_step.install(); - const verify_step = ZiglingStep.create(b, ex); + const verify_step = ZiglingStep.create(b, ex, use_healed); const key = ex.key(); - const named_test = b.step(b.fmt("{s}_test", .{key}), b.fmt("Run {s} without verifying output", .{ex.main_file})); + const named_test = b.step(b.fmt("{s}_test", .{key}), b.fmt("Run {s} without checking output", .{ex.main_file})); const run_step = build_step.run(); named_test.dependOn(&run_step.step); const named_install = b.step(b.fmt("{s}_install", .{key}), b.fmt("Install {s} to zig-cache/bin", .{ex.main_file})); named_install.dependOn(&build_step.install_step.?.step); - const named_verify = b.step(b.fmt("{s}_only", .{key}), b.fmt("Verify {s} only", .{ex.main_file})); + const named_verify = b.step(key, b.fmt("Check {s} only", .{ex.main_file})); named_verify.dependOn(&verify_step.step); const chain_verify = b.allocator.create(Step) catch unreachable; chain_verify.* = Step.initNoOp(.Custom, b.fmt("chain {s}", .{key}), b.allocator); chain_verify.dependOn(&verify_step.step); - const named_chain = b.step(key, b.fmt("Verify all solutions starting at {s}", .{ex.main_file})); + const named_chain = b.step(b.fmt("{s}_start", .{key}), b.fmt("Check all solutions starting at {s}", .{ex.main_file})); named_chain.dependOn(&header_step.step); named_chain.dependOn(chain_verify); @@ -367,13 +381,15 @@ const ZiglingStep = struct { step: Step, exercise: Exercise, builder: *Builder, + use_healed: bool, - pub fn create(builder: *Builder, exercise: Exercise) *@This() { + pub fn create(builder: *Builder, exercise: Exercise, use_healed: bool) *@This() { const self = builder.allocator.create(@This()) catch unreachable; self.* = .{ .step = Step.init(.Custom, exercise.main_file, builder.allocator, make), .exercise = exercise, .builder = builder, + .use_healed = use_healed, }; return self; } @@ -382,7 +398,7 @@ const ZiglingStep = struct { const self = @fieldParentPtr(@This(), "step", step); self.makeInternal() catch { if (self.exercise.hint.len > 0) { - print("\n{s}hint: {s}{s}", .{ bold_text, self.exercise.hint, reset_text }); + print("\n{s}HINT: {s}{s}", .{ bold_text, self.exercise.hint, reset_text }); } print("\n{s}Edit exercises/{s} and run this again.{s}", .{ red_text, self.exercise.main_file, reset_text }); @@ -396,7 +412,7 @@ const ZiglingStep = struct { const exe_file = try self.doCompile(); - print("Verifying {s}...\n", .{self.exercise.main_file}); + print("Checking {s}...\n", .{self.exercise.main_file}); const cwd = self.builder.build_root; @@ -463,7 +479,7 @@ const ZiglingStep = struct { return error.InvalidOutput; } - print("{s}** PASSED **{s}\n", .{ green_text, reset_text }); + print("{s}PASSED: {s}{s}\n", .{ green_text, output, reset_text }); } // The normal compile step calls os.exit, so we can't use it as a library :( @@ -482,7 +498,8 @@ const ZiglingStep = struct { zig_args.append(@tagName(builder.color)) catch unreachable; } - const zig_file = std.fs.path.join(builder.allocator, &[_][]const u8{ "exercises", self.exercise.main_file }) catch unreachable; + const zig_file = std.fs.path.join(builder.allocator, &[_][]const u8{ + if (self.use_healed) "patches/healed" else "exercises", self.exercise.main_file }) catch unreachable; zig_args.append(builder.pathFromRoot(zig_file)) catch unreachable; zig_args.append("--cache-dir") catch unreachable; |