I’m trrying to add a new bool to a struct definition. I have a global option that turns on or off some feature, but I want it to be more granular. So I was going to add bools to a struct and then test if it exists and if it does it can override the global value. This is turn on and off various runtime debugging info that has been added at build time so the caller (the dev building) cannot specify the full set that is spread across many files.
I don’t have a good solution to offer. All I can think of is a shell script that scans every Zig file for an export under a particular name, then generates a Zig file that imports that symbol from all matching files, merging them into a feature set that you can then use in your build file.
The first 2 have size zero but still can be read like normal fields, you just have to make sure that you guard things with if(comptime ...) checks so you don’t attempt to write to the comptime fields (at least you can’t set a different value than they already have, setting the same value is a no-op), other then that this allows you to switch between these different types and the type determines whether it will need space and whether its value can be changed at run-time.
tl;dr Instead of making the field optional, it is easier to switch between a zero sized type and a non-zero sized type.
the list of tags isn’t known upfront: here is was I currently do with something similar to turn assertions on and off in release modes. I @import the asserts struct from a project file, but requires some manual work each time (ie, I can’t just make it a library and the file has to exist too so each new project I use this in has to create the Assert struct with the nassert decl – I can’t find a way to basically mimic #if !defined(NASSERT) && !defined(ASSERT_GROUP_ASD) ...