Hejsil / zig-clap

Command line argument parsing library
MIT License
939 stars 67 forks source link

Including as module in new app with zig 0.13.0 cannot build - Error about MakeOptions #134

Closed crrodger closed 3 months ago

crrodger commented 3 months ago

Hi, completely new to Zig and therefore also zig-clap so if this is just some rookie error please forgive me. Thanks for making this library available. I use the Rust clap crate a lot and looking forward to something similar.

Came across this headache when following the instructions on the main Github page. Just putting this on the radar as I am sure I will not be the only person who runs into this.

Using zig 0.13.0

I ran the command as suggested

zig fetch --save git+https://github.com/Hejsil/zig-clap

also added the two lines to my build.zig

const clap = b.dependency("clap", .{});
exe.root_module.addImport("clap", clap.module("clap"));

When I then build the app, which is really the standard zig init app plus the example code from one of the zig-clap simple examples, I get this error

..../.cache/zig/p/122026b67ce2974e3b2fcfd3e2e164b73ee60c55d13f3f60ca7db6c316c8f22a6bf8/build.zig:67:61: error: root struct of file 'Build.Step' has no member named 'MakeOptions'
            fn make(step: *std.Build.Step, _: std.Build.Step.MakeOptions) anyerror!void {
                                              ~~~~~~~~~~~~~~^~~~~~~~~~~~
/opt/homebrew/Cellar/zig/0.13.0/lib/zig/std/Build/Step.zig:1:1: note: struct declared here
id: Id,

I see in one of the recent commits there was a change to support zig 0.13.0 that changed the std.Progress.Node to std.Build.Step.MakeOptions.

If I edit this build.zig file in the zig cache (i.e. the results from the zig fetch above) and change the MakeOptions back to the original _: std.Progress.Node, it works.

There must have been a good reason this was done and guessing it relates to zig versions. I am using 0.13.0 which it sounds like the commit was trying to update for so not sure what is happening there.

Anyway, thanks again.

Hejsil commented 3 months ago

Well, the master version of zig-clap targets master zig. If you want to use a fixed release of zig, you should use a fixed release of zig-clap that targets that release.

One could argue that this should be made for clear in the README under the install section though

crrodger commented 3 months ago

Fair enough, thanks for the response.