A minimal Zig library for sourcing a .env file at build time.
- Add as a dependency to your zig project
zig fetch --save "git+https://github.com/voidKandy/btzdotenv"- Use in your
build.zigfile
// First you need add a run artifact to some executable
const run_cmd = b.addRunArtifact(exe);
@import("btzdotenv").loadDotEnv(run_cmd);- Access your variable through
std.process
var env_map = try std.process.getEnvMap(self.allocator);
defer env_map.deinit();
const client_id = env_map.get("CLIENT_ID").?;
const client_secret = env_map.get("CLIENT_SECRET").?;Many dotenv libraries require you to load and manage environment variables through a separate object, which can lead to redundant calls or confusion about variable sources.
This tiny library simplifies the process: it parses a .env file and injects the key/value pairs directly into the environment of a single process.