#getting env vars failing
1 messages · Page 1 of 1 (latest)
what is the code that fails?
const rpc = try getEnvVarOwned(allocator, "mainnet_rpc");
and mainnet_rpc is set an an env var. Can confirm with an echo $mainnet_rpc
I guess the obvious questions are:
Are you sure you have the case correct?
Are you sure that the zig program is running in a context that has the environment variable set?
its possible this is a result of not linking libc. could you try again with libc linked?
there's an issue for this https://github.com/ziglang/zig/issues/4524
I am running using zig build test if that helps
so in your build.zig, i think you'll need something like
test_exe.linkLibC();
did you try this? i'm not saying its a solution, just trying to help find the problem.
maybe try running this
// /tmp/tmp.zig
const std = @import("std");
// pub fn main() !void {
test {
const foo = try std.process.getEnvVarOwned(std.heap.page_allocator, "FOO");
std.debug.print("foo={s}\n", .{foo});
}
$ FOO="BAR" zig test /tmp/tmp.zig
Test [1/1] test_0... foo=BAR
All 1 tests passed.
and if that fails, try
$ FOO="BAR" zig test /tmp/tmp.zig -lc
Hmm this actually works even without -lc
I wonder if its since I am doing it from zig build test (which I need to use since my project has deps that are imported using the package manager and setup in the build file)
is it returning an error or just not printing anything?
another thing to check, are the tests just getting cached? you can see if its getting cached w/ $ zig build test --summary all
and to prevent it in your build.zig
const run_unit_tests = b.addRunArtifact(unit_tests);
run_unit_tests.has_side_effects = true;
It returns the variable not found error. It's also not a cache issue as I made changes to trigger a rebuild, but I didn't know I could do this in the build file which is cool.