Arwalk / zig-protobuf

a protobuf 3 implementation for zig.
MIT License
188 stars 20 forks source link

Unable to find module when adding to `build.zig` #37

Closed stephenafamo closed 5 months ago

stephenafamo commented 5 months ago

Trying to follow the instructions in the README, but I zig seems unable to find the module.

I have tried with both zig v0.11.0 and 0.12.0-dev.2587+a1b607acb

❯ zig build --help
thread 3057254 panic: unable to find module 'protobuf'
/Users/stephen/.local/bin/zig/lib/std/debug.zig:434:22: 0x10013fc5b in panicExtra__anon_18444 (build)
    std.builtin.panic(msg, trace, ret_addr);
                     ^
/Users/stephen/.local/bin/zig/lib/std/debug.zig:409:15: 0x10010cb47 in panic__anon_17783 (build)
    panicExtra(null, null, format, args);
              ^
/Users/stephen/.local/bin/zig/lib/std/Build.zig:1786:18: 0x1000dae4f in module (build)
            panic("unable to find module '{s}'", .{name});
                 ^
/Users/stephen/code/learn/zig/build.zig:54:46: 0x10009bc87 in build (build)
                .module = protobuf_dep.module("protobuf"),
                                             ^
/Users/stephen/.local/bin/zig/lib/std/Build.zig:1982:33: 0x10007ce37 in runBuild__anon_8404 (build)
        .Void => build_zig.build(b),
                                ^
/Users/stephen/.local/bin/zig/lib/build_runner.zig:310:29: 0x100078b3b in main (build)
        try builder.runBuild(root);
                            ^
/Users/stephen/.local/bin/zig/lib/std/start.zig:585:37: 0x10007e47b in main (build)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x18c0e50df in ??? (???)
???:?:?: 0x56307fffffffffff in ??? (???)
error: the following build command crashed:
/Users/stephen/code/learn/zig/zig-cache/o/fca68244e4a64f1c935cc61c53853d6b/build /Users/stephen/.local/bin/zig/zig /Users/stephen/code/learn/zig /Users/stephen/code/learn/zig/zig-cache /Users/stephen/.cache/zig --seed 0x5b7babad -Z132fe72e70486721 --help
stephenafamo commented 5 months ago

This is the only similar issue I could find https://github.com/ziglang/zig/issues/18282

Arwalk commented 5 months ago

Hey there @stephenafamo , could you share us your code? Any repo we could help with?

The readme was slightly out of date, i updated it earlier and successfully built something with it, following the instructions, though i haven't tried on the latest zig.

stephenafamo commented 5 months ago

So, I tried to recreate it on a fresh project created with zig init with the current nightly, and I got a different error

❯ zig build --help
/Users/stephen/.cache/zig/p/12203b87a1274a0041a0aca82c2306035b7a4129bddc6a0ae86f9d942787f898530b/build.zig:233:31: error: no field named 'zig_exe' in struct 'Build'
            try argv.append(b.zig_exe);
                              ^~~~~~~
/Users/stephen/.local/bin/zig/lib/std/Build.zig:1:1: note: struct declared here
const std = @import("std.zig");
^~~~~
referenced by:
    create: /Users/stephen/.cache/zig/p/12203b87a1274a0041a0aca82c2306035b7a4129bddc6a0ae86f9d942787f898530b/build.zig:171:27
    build: /Users/stephen/.cache/zig/p/12203b87a1274a0041a0aca82c2306035b7a4129bddc6a0ae86f9d942787f898530b/build.zig:127:46
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

For this error I know the fix (since I cloned the package locally in my original project).
This line should be changed to:

            try argv.append(b.graph.zig_exe);
Arwalk commented 5 months ago

So, I tried to recreate it on a fresh project created with zig init with the current nightly, and I got a different error

❯ zig build --help
/Users/stephen/.cache/zig/p/12203b87a1274a0041a0aca82c2306035b7a4129bddc6a0ae86f9d942787f898530b/build.zig:233:31: error: no field named 'zig_exe' in struct 'Build'
            try argv.append(b.zig_exe);
                              ^~~~~~~
/Users/stephen/.local/bin/zig/lib/std/Build.zig:1:1: note: struct declared here
const std = @import("std.zig");
^~~~~
referenced by:
    create: /Users/stephen/.cache/zig/p/12203b87a1274a0041a0aca82c2306035b7a4129bddc6a0ae86f9d942787f898530b/build.zig:171:27
    build: /Users/stephen/.cache/zig/p/12203b87a1274a0041a0aca82c2306035b7a4129bddc6a0ae86f9d942787f898530b/build.zig:127:46
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

For this error I know the fix (since I cloned the package locally in my original project). This line should be changed to:

            try argv.append(b.graph.zig_exe);

Ok, i checked on latest zig and indeed, the line you mentioned needed to be changed. Thanks!

Latest master should properly be usable now. Can I count on you to check on your side and close the issue if everything's fine?

Thanks again.

stephenafamo commented 5 months ago

Yes. I can confirm, everything works now.

Small quirk I encountered about zon. When upgrading a package to a new commit, if the hash is cached, the old commit will still be used even the dependency's URL was updated.

davo417 commented 4 months ago

Hello, sabe problem here with zig 0.12.0-dev.3161+377ecc6af. It can't find protobuf module and also complains that the project does not have a build.zig.zon file so zig fetch --save does not work.