feat: Created zig wrapper.

This commit is contained in:
2026-04-17 16:01:44 -04:00
parent 6a611150f5
commit ce135e9ce4
3 changed files with 37 additions and 20 deletions

2
.envrc
View File

@@ -1,3 +1,3 @@
use flake use flake
export PATH="./vendor/zig:$PATH" export PATH=".:./deps/zig:./deps/zls:$PATH"

1
.gitignore vendored
View File

@@ -2,6 +2,7 @@
.direnv .direnv
# dependencies # dependencies
deps
vendor vendor
# docs # docs

View File

@@ -3,32 +3,48 @@ const Io = std.Io;
const envr = @import("envr"); const envr = @import("envr");
pub fn main(init: std.process.Init) !void { const goBinary = "envr-go";
// Prints to stderr, unbuffered, ignoring potential errors.
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
pub fn main(init: std.process.Init) !void {
// This is appropriate for anything that lives as long as the process. // This is appropriate for anything that lives as long as the process.
const arena: std.mem.Allocator = init.arena.allocator(); const arena: std.mem.Allocator = init.arena.allocator();
// Accessing command line arguments:
const args = try init.minimal.args.toSlice(arena); const args = try init.minimal.args.toSlice(arena);
for (args) |arg| {
std.log.info("arg: {s}", .{arg}); // if (std.mem.eql(u8, args[1], "version")) {
// version(args[1..]);
// } else {
return fallbackToGo(init.io, args, arena);
// }
} }
// In order to do I/O operations need an `Io` instance. fn version(args: []const [:0]const u8) void {
const io = init.io; // std.debug.print("hello from Zig!\n", .{});
// Stdout is for the actual output of your application, for example if you // for (args[1..]) |arg| {
// are implementing gzip, then only the compressed bytes should be sent to // std.debug.print("arg: {s}\n", .{arg});
// stdout, not any debugging messages. // }
var stdout_buffer: [1024]u8 = undefined; //
var stdout_file_writer: Io.File.Writer = .init(.stdout(), io, &stdout_buffer);
const stdout_writer = &stdout_file_writer.interface;
try envr.printAnotherMessage(stdout_writer); _ = args;
try stdout_writer.flush(); // Don't forget to flush! std.debug.print("TODO: Implement\n", .{});
}
fn fallbackToGo(
io: Io,
args: []const [:0]const u8,
arena: std.mem.Allocator,
) std.process.ReplaceError {
// Remap args
var childArgs = try std.ArrayList([]const u8).initCapacity(arena, args.len);
childArgs.appendAssumeCapacity(goBinary);
for (args[1..]) |arg| {
childArgs.appendAssumeCapacity(arg);
}
return std.process.replace(io, .{ .argv = childArgs.items });
} }
test "simple test" { test "simple test" {