How to access environment variables in build system?

I have an environment variable (OVMF_FD) that contains the path to a file on my system.

In the past, I could have done something like:

const ovmf_path = try std.process.getEnvVarOwned(b.allocator, "OVMF_FD");
const qemu_cmd = b.addSystemCommand(&.{
    "qemu-system-x86_64",
    "-bios",
    ovmf_path,
    ...
});

So how do this in 0.16? Because the build function doesn’t give me an instance of the env map like main does, so I’m unsure how to access it.

Thanks for the help!

I think this is the way to do it:

pub fn build(b: *std.Build) void {
    b.graph.environ_map.get("OVMF_FD");
// ....

It’s not well documented, is it?

1 Like

It’s also not yet in its final form, which will need a way to declare what relationship the environment variable is intended to have with the cache. For example, if the environment variable’s value changes, should that cause the configure script to be rerun or not? Does it contain a path to a file, which the script should depend on, but if the file contents are the same, then it should be a cache hit? etc

4 Likes