#Import `build.zig.zon`

1 messages · Page 1 of 1 (latest)

lavish chasm
#

With #20271 being merged (thank you @round prairie !), is there any guidance on how to import build.zig.zon during comptime in build.zig? The requirement to have a known result type is causing issues, not sure how to specify the dependencies field.

fallow linden
#

There was a conversation about this in #zig earlier and the general consensus was that this is not possible

round prairie
#

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

odd mesa
round prairie
#

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

odd mesa
#

I'd imagine people wanting to get version from build.zig.zon and @import not working being slightly disappointing I guess

round prairie
#

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

lavish chasm
#

For version and minimum zig version, used in build.zig and other places in source

round prairie
#

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

lavish chasm
# round prairie Gotcha that makes sense. For now I'd recommend passing it through `std.Build.add...

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

round prairie
#

Yeah that makes a lot of sense

#

I'm surprised it's not available via Build (but obviously even if it was that'd be a bunch of extra steps for what could be a one liner)