From 968436c8be110143611bb4bdc6d00210f1c580bc Mon Sep 17 00:00:00 2001 From: voidKandy Date: Wed, 29 Oct 2025 12:30:10 -0700 Subject: [PATCH 1/4] migrated to zig 0.15 --- build.zig | 17 +++++++++-------- build.zig.zon | 3 ++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/build.zig b/build.zig index 0e916a4..658dca6 100644 --- a/build.zig +++ b/build.zig @@ -6,12 +6,14 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); - const exe = b.addExecutable(.{ - .name = "zdotenv", - .root_source_file = b.path("src/main.zig"), - .target = target, - .optimize = optimize, - }); + const main_module = + b.createModule(.{ + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + }); + + const exe = b.addExecutable(.{ .name = "zdotenv", .root_module = main_module }); // For setting env vars using C exe.linkLibC(); @@ -20,8 +22,7 @@ pub fn build(b: *std.Build) void { // Module setup _ = b.addModule("zdotenv", .{ .root_source_file = b.path("src/main.zig") }); var lib_tests = b.addTest(.{ - .root_source_file = b.path("src/main.zig"), - .optimize = optimize, + .root_module = main_module, }); const test_step = b.step("test", "Run library tests"); diff --git a/build.zig.zon b/build.zig.zon index 3674729..b3f32f5 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -6,7 +6,8 @@ // // It is redundant to include "zig" in this name because it is already // within the Zig package namespace. - .name = "zdotenv", + .name = .zdotenv, + .fingerprint = 0xb52a51eb5af5b8cc, // This is a [Semantic Version](https://semver.org/). // In a future version of Zig it will be used for package deduplication. From d3344f945aa6dfe7ac3771615b94367e8b5aed25 Mon Sep 17 00:00:00 2001 From: voidKandy Date: Wed, 29 Oct 2025 12:39:30 -0700 Subject: [PATCH 2/4] fixed deprecated use of previous File IO --- src/parser.zig | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/parser.zig b/src/parser.zig index db7bb5f..ae43132 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -18,7 +18,10 @@ pub const Parser = struct { // parse is a simple parsing function. Its simple on purpose, this process should not be lofty or complex. No AST's or complex symbol resolution. Just take the Key and Value from the K=V from an .env and avoid comments (#) pub fn parse(self: *Self) !std.StringHashMap([]const u8) { var buf: [1024 * 2 * 2]u8 = undefined; - while (try self.file.reader().readUntilDelimiterOrEof(&buf, '\n')) |line| { + var reader = self.file.reader(&buf).interface; + + while (reader.takeDelimiterExclusive('\n')) |line| { + // while (try reader.readUntilDelimiterOrEof(&buf, '\n')) |line| { // Skip comments (i.e. #) if (std.mem.startsWith(u8, line, "#")) continue; if (std.mem.eql(u8, line, "")) continue; @@ -36,6 +39,9 @@ pub const Parser = struct { const d_val = try self.allocator.dupe(u8, value); try self.env_values.put(d_key, d_val); + } else |err| { + if (err != error.EndOfStream) + return err; } return self.env_values; From a8468beca58c8eb29776dc688da652fb5466cb53 Mon Sep 17 00:00:00 2001 From: voidKandy Date: Fri, 31 Oct 2025 11:08:07 -0700 Subject: [PATCH 3/4] corrected bug with file reader --- src/parser.zig | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/parser.zig b/src/parser.zig index ae43132..1a5db23 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -18,9 +18,13 @@ pub const Parser = struct { // parse is a simple parsing function. Its simple on purpose, this process should not be lofty or complex. No AST's or complex symbol resolution. Just take the Key and Value from the K=V from an .env and avoid comments (#) pub fn parse(self: *Self) !std.StringHashMap([]const u8) { var buf: [1024 * 2 * 2]u8 = undefined; - var reader = self.file.reader(&buf).interface; + var reader = self.file.reader(&buf); - while (reader.takeDelimiterExclusive('\n')) |line| { + while (reader.interface.takeDelimiterExclusive('\n')) |line| { + std.log.warn( + \\line: + \\ {s} + , .{line}); // while (try reader.readUntilDelimiterOrEof(&buf, '\n')) |line| { // Skip comments (i.e. #) if (std.mem.startsWith(u8, line, "#")) continue; From cd14f7a3d3014b395069e9b4a9a0da504aa58c66 Mon Sep 17 00:00:00 2001 From: voidKandy Date: Fri, 31 Oct 2025 11:09:05 -0700 Subject: [PATCH 4/4] removed redundant logging --- src/parser.zig | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/parser.zig b/src/parser.zig index 1a5db23..9b7268e 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -21,11 +21,6 @@ pub const Parser = struct { var reader = self.file.reader(&buf); while (reader.interface.takeDelimiterExclusive('\n')) |line| { - std.log.warn( - \\line: - \\ {s} - , .{line}); - // while (try reader.readUntilDelimiterOrEof(&buf, '\n')) |line| { // Skip comments (i.e. #) if (std.mem.startsWith(u8, line, "#")) continue; if (std.mem.eql(u8, line, "")) continue;