From 64f88982c15201608b85bd6ba8c9856340dc9e9f Mon Sep 17 00:00:00 2001 From: Mark Zhitomirski Date: Sun, 2 Jul 2023 16:43:41 +0400 Subject: [PATCH] Update for changes to zig 0.11.0 build system etc. tested with 0.11.0 also - fix @ptrCast (with `zig fmt` help) - move const out of while loop - define const prompt = "> " --- build.zig | 8 ++++++-- src/main.zig | 12 ++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/build.zig b/build.zig index 0158a11..f0b24a5 100644 --- a/build.zig +++ b/build.zig @@ -17,9 +17,13 @@ pub fn build(b: *std.build.Builder) void { .target = target, .optimize = optimize, }); - exe.install(); - const run_cmd = exe.run(); + // This declares intent for the executable to be installed into the + // standard location when the user invokes the "install" step (the default + // step when running `zig build`). + b.installArtifact(exe); + + const run_cmd = b.addRunArtifact(exe); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| { run_cmd.addArgs(args); diff --git a/src/main.zig b/src/main.zig index c6fbfcd..c20d576 100644 --- a/src/main.zig +++ b/src/main.zig @@ -10,12 +10,12 @@ pub fn main() !u8 { } fn shellLoop(stdin: std.fs.File.Reader, stdout: std.fs.File.Writer) !void { - while (true) { - const max_input = 1024; - const max_args = 10; + const max_input = 1024; + const max_args = 10; + const prompt = "> "; - // Prompt - try stdout.print("> ", .{}); + while (true) { + try stdout.print(prompt, .{}); // Read STDIN into buffer var input_buffer: [max_input]u8 = undefined; @@ -39,7 +39,7 @@ fn shellLoop(stdin: std.fs.File.Reader, stdout: std.fs.File.Writer) !void { while (i <= input_str.len) : (i += 1) { if (input_buffer[i] == 0x20 or input_buffer[i] == 0xa) { input_buffer[i] = 0; // turn space or line feed into null byte as sentinel - args_ptrs[n] = @ptrCast(*align(1) const [*:0]u8, &input_buffer[ofs..i :0]).*; + args_ptrs[n] = @as(*align(1) const [*:0]u8, @ptrCast(&input_buffer[ofs..i :0])).*; n += 1; ofs = i + 1; }