Questions
I was looking into how std_options
works, so I pulled up std.zig
:
const root = @import("root");
/// Stdlib-wide options that can be overridden by the root file.
pub const options: Options = if (@hasDecl(root, "std_options")) root.std_options else .{};
- This suggests there’s some sort of circular dependency. My code invokes
std
, butstd
invokes my code. How is this resolved? - How is
root
defined?
More on Q2. Let’s say I compile a zig library, and link my code against that library. Does std
get compiled twice? Once for the library, and once for my top-level code? Or is std
compiled once against the top level code?
Background
I’m using a 3rd party library and running tests with the zig build system (zig build test
not zig test
). In my tests I set it up so that the library will fail, and my code handles the failure. However, this third party library invokes std.log
with an error. I don’t want it to do this during my tests, because I handle the error. For my test, I was trying to suppress log output by setting:
pub const std_options = {
// Logging function I defined which throws away the input.
.logFn = noopLog,
};
My custom logging function never gets called, which led me to suspect that std_options
doesn’t change std
globally as I initially thought.