How I can use env var in comptime?

I already tried use std.process.getEnvVarOwned but this function not work in comptime. std.os.environ returns “{ }”, so i can’t use that.

this sounds to me like an X-Y problem—what problems are you hoping to solve by using environment variables?

1 Like

Configuration options from environment variables can be created in build.zig and used with @import.
See this thread: Can someone explain more on @import("config") in the build system doc


Be careful doing this! If you do this, it adds a build-time dependency onto your system, which can make your software less reproducible and more difficult to build from source. Generally, it’s better if people don’t need to have their environment set up correctly in order to build a Zig project.