]> Repositories - zlox.git/commitdiff
Switch to Zig Build System
authorAyo Reis <hey@ayoreis.com>
Sun, 15 Feb 2026 16:39:31 +0000 (16:39 +0000)
committerAyo Reis <hey@ayoreis.com>
Sun, 15 Feb 2026 16:39:31 +0000 (16:39 +0000)
.gitignore [new file with mode: 0644]
README.md
build.zig [new file with mode: 0644]
build.zig.zon [new file with mode: 0644]
src/Scanner.zig [moved from Scanner.zig with 99% similarity]
src/Token.zig [moved from Token.zig with 100% similarity]
src/main.zig [moved from lox.zig with 100% similarity]
src/token_type.zig [moved from token_type.zig with 100% similarity]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..db3cb54
--- /dev/null
@@ -0,0 +1,2 @@
+/.zig-cache/
+/zig-out/
index 1de96d00dfa87c9c77b4dc6a1009e2e72adcc7fd..84b40e2ce2a0f9b2643efc420f46b71f20be2001 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,7 +1,3 @@
 # Zlox
 
 An implementation of the [Lox language](https://craftinginterpreters.com/the-lox-language.html) in Zig.
 # Zlox
 
 An implementation of the [Lox language](https://craftinginterpreters.com/the-lox-language.html) in Zig.
-
-```shell
-zig run lox.zig
-```
diff --git a/build.zig b/build.zig
new file mode 100644 (file)
index 0000000..c7ccf9a
--- /dev/null
+++ b/build.zig
@@ -0,0 +1,23 @@
+const std = @import("std");
+
+pub fn build(b: *std.Build) void {
+    const exe = b.addExecutable(.{
+        .name = "zlox",
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("src/main.zig"),
+            .target = b.standardTargetOptions(.{}),
+            .optimize = b.standardOptimizeOption(.{}),
+        }),
+    });
+
+    b.installArtifact(exe);
+
+    const run_step = b.step("run", "Run the app");
+    const run_cmd = b.addRunArtifact(exe);
+    run_step.dependOn(&run_cmd.step);
+    run_cmd.step.dependOn(b.getInstallStep());
+
+    if (b.args) |args| {
+        run_cmd.addArgs(args);
+    }
+}
diff --git a/build.zig.zon b/build.zig.zon
new file mode 100644 (file)
index 0000000..b44d9fa
--- /dev/null
@@ -0,0 +1,12 @@
+.{
+    .name = .zlox,
+    .version = "0.0.0",
+    .fingerprint = 0xd8b023c660b945d7,
+    .minimum_zig_version = "0.15.2",
+
+    .paths = .{
+        "build.zig",
+        "build.zig.zon",
+        "src",
+    },
+}
similarity index 99%
rename from Scanner.zig
rename to src/Scanner.zig
index 622c98ed5b147002166adb656a3153daef1eb949..c542e45ba058f167dc1f1f6a82af45bff8f4ad40 100644 (file)
@@ -7,7 +7,7 @@ const Token = @import("Token.zig");
 const Literal = Token.Literal;
 const Scanner = @This();
 const TokenType = @import("token_type.zig").TokenType;
 const Literal = Token.Literal;
 const Scanner = @This();
 const TokenType = @import("token_type.zig").TokenType;
-const lox = @import("lox.zig");
+const lox = @import("main.zig");
 
 source: []const u8,
 tokens: std.ArrayList(Token) = .empty,
 
 source: []const u8,
 tokens: std.ArrayList(Token) = .empty,
similarity index 100%
rename from Token.zig
rename to src/Token.zig
similarity index 100%
rename from lox.zig
rename to src/main.zig
similarity index 100%
rename from token_type.zig
rename to src/token_type.zig