mirror of
https://codeberg.org/andyscott/ziglings.git
synced 2024-12-22 14:03:10 -05:00
Make "check and halt" the default for zig build NN (#15)
The "start with NN" action is now NN_start. Also formatting output for improved clarity (hopefully).
This commit is contained in:
parent
a216e19521
commit
654437c0bc
2 changed files with 24 additions and 18 deletions
28
README.md
28
README.md
|
@ -38,17 +38,17 @@ $ zig version
|
||||||
Clone this repository with Git:
|
Clone this repository with Git:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/ratfactor/ziglings
|
$ git clone https://github.com/ratfactor/ziglings
|
||||||
cd ziglings
|
$ cd ziglings
|
||||||
```
|
```
|
||||||
|
|
||||||
Then run `zig build` and follow the instructions to begin!
|
Then run `zig build` and follow the instructions to begin!
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
zig build
|
$ zig build
|
||||||
```
|
```
|
||||||
|
|
||||||
## A Note About Compiler Versions
|
## A Note About Versions
|
||||||
|
|
||||||
The Zig language is under very active development. Ziglings will attempt to
|
The Zig language is under very active development. Ziglings will attempt to
|
||||||
be current, but not bleeding-edge. However, sometimes fundamental changes
|
be current, but not bleeding-edge. However, sometimes fundamental changes
|
||||||
|
@ -61,25 +61,31 @@ Once you have a version of the Zig compiler that works with your copy of
|
||||||
Ziglings, they'll continue to work together forever. But if you update one,
|
Ziglings, they'll continue to work together forever. But if you update one,
|
||||||
keep in mind that you may need to also update the other.
|
keep in mind that you may need to also update the other.
|
||||||
|
|
||||||
## Manual Usage
|
## Advanced Usage
|
||||||
|
|
||||||
If you want to run a single file for testing, you can do so with this command:
|
It can be handy to check just a single exercise or _start_ from a single
|
||||||
|
exercise:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
zig run exercises/01_hello.zig
|
zig build 19
|
||||||
|
zig build 19_start
|
||||||
```
|
```
|
||||||
or, alternatively
|
|
||||||
|
You can also run without checking for correctness:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
zig build 01_test
|
zig build 01_test
|
||||||
```
|
```
|
||||||
|
|
||||||
To verify a single file, use
|
Or skip the build system entirely and interact directly with the compiler
|
||||||
|
if you're into that sort of thing:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
zig build 01_only
|
zig run exercises/01_hello.zig
|
||||||
```
|
```
|
||||||
|
|
||||||
To prepare an executable for debugging, install it to zig-cache/bin with
|
Calling all wizards: To prepare an executable for debugging, install it
|
||||||
|
to zig-cache/bin with:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
zig build 01_install
|
zig build 01_install
|
||||||
|
|
14
build.zig
14
build.zig
|
@ -324,7 +324,7 @@ 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);
|
verify_all.dependOn(&header_step.step);
|
||||||
b.default_step = verify_all;
|
b.default_step = verify_all;
|
||||||
|
|
||||||
|
@ -342,21 +342,21 @@ pub fn build(b: *Builder) void {
|
||||||
|
|
||||||
const key = ex.key();
|
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();
|
const run_step = build_step.run();
|
||||||
named_test.dependOn(&run_step.step);
|
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}));
|
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);
|
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);
|
named_verify.dependOn(&verify_step.step);
|
||||||
|
|
||||||
const chain_verify = b.allocator.create(Step) catch unreachable;
|
const chain_verify = b.allocator.create(Step) catch unreachable;
|
||||||
chain_verify.* = Step.initNoOp(.Custom, b.fmt("chain {s}", .{key}), b.allocator);
|
chain_verify.* = Step.initNoOp(.Custom, b.fmt("chain {s}", .{key}), b.allocator);
|
||||||
chain_verify.dependOn(&verify_step.step);
|
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(&header_step.step);
|
||||||
named_chain.dependOn(chain_verify);
|
named_chain.dependOn(chain_verify);
|
||||||
|
|
||||||
|
@ -390,7 +390,7 @@ const ZiglingStep = struct {
|
||||||
const self = @fieldParentPtr(@This(), "step", step);
|
const self = @fieldParentPtr(@This(), "step", step);
|
||||||
self.makeInternal() catch {
|
self.makeInternal() catch {
|
||||||
if (self.exercise.hint.len > 0) {
|
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 });
|
print("\n{s}Edit exercises/{s} and run this again.{s}", .{ red_text, self.exercise.main_file, reset_text });
|
||||||
|
@ -404,7 +404,7 @@ const ZiglingStep = struct {
|
||||||
|
|
||||||
const exe_file = try self.doCompile();
|
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;
|
const cwd = self.builder.build_root;
|
||||||
|
|
||||||
|
@ -471,7 +471,7 @@ const ZiglingStep = struct {
|
||||||
return error.InvalidOutput;
|
return error.InvalidOutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
print("{s}{s}{s}\n", .{ green_text, output, 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 :(
|
// The normal compile step calls os.exit, so we can't use it as a library :(
|
||||||
|
|
Loading…
Reference in a new issue