Cloudef / zig2nix

Flake for packaging, building and running Zig projects.
MIT License
81 stars 1 forks source link

Consider using zig compiler itself to do the build.zig.zon conversion. #1

Open Cloudef opened 10 months ago

Cloudef commented 10 months ago

While zon2json works right now for any build.zig.zon files I've thrown at it. The ast walker itself isn't really complete. Zon files itself are literally zig structs, so they may contain actual zig expressions I don't intend to maintain a zig interpreter so consider instead making zon2json a program that depends on zig compiler that generates a program that does something like:

const zon = <insert .zon contents here>;
std.io.getStdout().writer().print("{s}", std.json.fmt(zon, .{}));

This would make sure zon files are always handled properly. cons might be speed, but zig should cache the outputs.

At some point it might become possible to import zon files as well: https://github.com/ziglang/zig/issues/14531

ref: https://github.com/ziglang/zig/issues/15552

Cloudef commented 10 months ago

Might be interesting as well https://github.com/ziglang/zig/pull/17731

It doesn't say anything about expressions and I assume this will be the official zon spec. I'll update the zon2json to use this once it's landed.

dermetfan commented 10 months ago

Are you aware of https://github.com/nix-community/zon2nix?

Cloudef commented 10 months ago

@dermetfan Yes it is actually one of the reasons I started doing this, because it could not handle recursive dependencies, and can't handle recent .zon formats.