Hey everyone!
With the release 0.14.0, I want to take advantage of the new x86 backend for Linux. My first stab at incorporating it was this:
const exe = b.addExecutable(.{
.name = "my-exe",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.use_llvm = false,
});
Simple enough. But then, I thought “What if one of my users wanted compile from a machine that wasn’t x86 Linux?”
I could add an option to allow the user to set the use_llvm
boolean to opt in to the feature, but that feels so manual. My next thought was “How could I use the build system to automatically deduce if my target machine supports use_llvm
?”
After digging through the code, I found target.query.cpu_arch.?.isX86()
to determine the architecture. But I’m stumped on how to find out the OS.
How can I find the OS at build time?