#Import `build.zig.zon`
1 messages · Page 1 of 1 (latest)
There was a conversation about this in #zig earlier and the general consensus was that this is not possible
Good question, you probably want to check out ZonGen for this
That will parse the text into a tree that doesn't have to fit any specific result type
Hmm but you want to do it at comptime right?
What's your use case?
If by comptime you mean build time then ZonGen is what you want, I'll probably also add a feature to std.zon.parse at some point that lets you parse to a known type but stop on Zoir.Node similar to std.json
So that you can parse types that are partially known, but then have some dynamic fields
I'm still trying to understand the motivation for doing this instead of getting it from the build system API--I'm not saying it's not a valid use case, just trying to understand the goal
I'd imagine people wanting to get version from build.zig.zon and @import not working being slightly disappointing I guess
Hmm is version not expose through Build right now?
I didn't expect people to be trying to import build.zig.zon, but I guess I should have because it's the only ZON file everyone has on their machine right now
Oh I see
You're not trying to import it in your build script, you're trying to import it at comptime directly in source
I get it
Ah yes exactly this
For version and minimum zig version, used in build.zig and other places in source
Gotcha that makes sense. For now I'd recommend passing it through std.Build.addOptions, but people are probably already doing it that way and understandably were hoping this would make it more convenient
That is assuming it's exposed in Build I haven't actually checked this
If it's not it probably should be
There's no way to pass it through std.Build.addOptions, or rather; there's no way to retrieve the version/min-zig-version info itself to then pass along to rest of source through options. Every project I'm aware of simply copy-paste duplicates the literal version information in both build.zig.zon and in build.zig (or elsewhere in source).
It would just be nice to centralize that info into build.zig.zon and retrieve as necessary, so identical updates don't have to be made to multiple files