summary refs log tree commit diff
diff options
context:
space:
mode:
authorBaitinq <manuelpalenzuelamerino@gmail.com>2025-01-21 20:32:09 +0100
committerBaitinq <manuelpalenzuelamerino@gmail.com>2025-01-21 20:32:09 +0100
commit2d86904721ba32050d498b4dd03c6bca22091fc2 (patch)
treec9a1c3315a7ec20953fd374f45fc8117b911b883
parentBug: Fix bug with priority of parsing expressions (diff)
downloadinterpreter-2d86904721ba32050d498b4dd03c6bca22091fc2.tar.gz
interpreter-2d86904721ba32050d498b4dd03c6bca22091fc2.tar.bz2
interpreter-2d86904721ba32050d498b4dd03c6bca22091fc2.zip
Misc: Add `zig build example` step
-rw-r--r--build.zig24
1 files changed, 23 insertions, 1 deletions
diff --git a/build.zig b/build.zig
index 50c7bc4..b7e63d6 100644
--- a/build.zig
+++ b/build.zig
@@ -3,7 +3,7 @@ const std = @import("std");
 // Although this function looks imperative, note that its job is to
 // declaratively construct a build graph that will be executed by an external
 // runner.
-pub fn build(b: *std.Build) void {
+pub fn build(b: *std.Build) !void {
     // Standard target options allows the person running `zig build` to choose
     // what target to build for. Here we do not override the defaults, which
     // means any target is allowed, and the default is native. Other options
@@ -83,4 +83,26 @@ pub fn build(b: *std.Build) void {
     // running the unit tests.
     const test_step = b.step("test", "Run unit tests");
     test_step.dependOn(&run_exe_unit_tests.step);
+
+    // Example step - used for testing againt all the example programs
+    const examples_step = b.step("examples", "Run examples");
+    examples_step.dependOn(&exe.step);
+
+    const examples_dir = "examples";
+    var dir = std.fs.cwd().openDir(examples_dir, .{ .iterate = true }) catch |err| {
+        std.debug.print("Failed to open examples directory: {}\n", .{err});
+        return;
+    };
+    defer dir.close();
+
+    var iter = dir.iterate();
+    while (try iter.next()) |entry| {
+        if (entry.kind == .file) {
+            const example_path = b.fmt("{s}/{s}", .{ examples_dir, entry.name });
+            const run_example = b.addSystemCommand(&.{ "zig", "build", "run", "--", example_path });
+            run_example.setName(b.fmt("{s}", .{example_path}));
+            run_example.expectExitCode(0);
+            examples_step.dependOn(&run_example.step);
+        }
+    }
 }