zigzap / zap

blazingly fast backends in zig
MIT License
2.23k stars 75 forks source link

Unable to find module 'zap' #45

Closed n1yn closed 1 year ago

n1yn commented 1 year ago

I'm relatively new to zig so it is likely that I'm doing things wrong.

Steps to reproduce

Follow the basic instructions to add zap to your project:

build.zig.zon:

.{ 
    .name = "zig-web-server", 
    .version = "0.0.1", 
    .dependencies = .{ 
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.1.14-pre.tar.gz",
            .hash = "12206956e1c8e1af5fd28e44d534e4e131299545fa0676e1edc04bf02eb2185e266a",
        } 
    } 
}

build.zig

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});

    const optimize = b.standardOptimizeOption(.{});

    const exe = b.addExecutable(.{
        .name = "zig-web-server",
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });

    const zap = b.dependency("zap", .{
        .target = target,
        .optimize = optimize,
    });
    exe.addModule("zap", zap.module("zap"));
    exe.linkLibrary(zap.artifact("facil.io"));

    b.installArtifact(exe);

    const run_cmd = b.addRunArtifact(exe);

    run_cmd.step.dependOn(b.getInstallStep());

    if (b.args) |args| {
        run_cmd.addArgs(args);
    }

    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);
}

What happens?

As soon as I run zig build run I get the following output:

thread 81654 panic: unable to find module 'zap'
/nix/store/bg6hyfzr1wzk795ii48mc1v15bswcvp3-zig-0.11.0/lib/zig/std/debug.zig:374:22: 0x387999 in panicExtra__anon_47118 (build)
    std.builtin.panic(msg, trace, ret_addr);
                     ^
/nix/store/bg6hyfzr1wzk795ii48mc1v15bswcvp3-zig-0.11.0/lib/zig/std/debug.zig:349:15: 0x35f089 in panic__anon_28781 (build)
    panicExtra(null, null, format, args);
              ^
/nix/store/bg6hyfzr1wzk795ii48mc1v15bswcvp3-zig-0.11.0/lib/zig/std/Build.zig:1556:18: 0x3350b7 in module (build)
            panic("unable to find module '{s}'", .{name});
                 ^
/home/jotunn/Projects/zig/zig-web-server/build.zig:19:36: 0x2f03af in build (build)
    exe.addModule("zap", zap.module("zap"));
                                   ^
/nix/store/bg6hyfzr1wzk795ii48mc1v15bswcvp3-zig-0.11.0/lib/zig/std/Build.zig:1638:33: 0x2df313 in runBuild__anon_7164 (build)
        .Void => build_zig.build(b),
                                ^
/nix/store/bg6hyfzr1wzk795ii48mc1v15bswcvp3-zig-0.11.0/lib/zig/build_runner.zig:297:29: 0x2db0e2 in main (build)
        try builder.runBuild(root);
                            ^
/nix/store/bg6hyfzr1wzk795ii48mc1v15bswcvp3-zig-0.11.0/lib/zig/std/start.zig:574:37: 0x2c69ee in posixCallMainAndExit (build)
            const result = root.main() catch |err| {
                                    ^
/nix/store/bg6hyfzr1wzk795ii48mc1v15bswcvp3-zig-0.11.0/lib/zig/std/start.zig:243:5: 0x2c64d1 in _start (build)
    asm volatile (switch (native_arch) {
    ^
???:?:?: 0x5 in ??? (???)
Unwind information for `???:0x5` was not available, trace may be incomplete

It complains about being unable to find the zap module.

Any help is welcome.

renerocksai commented 1 year ago

It looks right. How did you install zig? You can try clearing your global zig cache, usually in ~/.cache/zig. Maybe, for some reason, downloading the deps got messed up?

renerocksai commented 1 year ago

Weird. You got the hash wrong in build.zig.zon. The correct one is: 122067d12bc7abb93f7ce623f61b94cadfdb180cef12da6559d092e6b374202acda3

renerocksai commented 1 year ago

Feel free to reopen if the correct hash doesn't solve your problem

n1yn commented 1 year ago

Well I don't even get to the point of building if I use the provided hash:

Fetch Packages [1/1] zap... /home/jotunn/Projects/zig/zig-web-server/build.zig.zon:7:21: error: hash mismatch: expected: 122067d12bc7abb93f7ce623f61b94cadfdb180cef12da6559d092e6b374202acda3, found: 12202d26b8c618b661ac5c9f96c11926f931fbea6afd302b7e71df9b3d256e79db91
            .hash = "122067d12bc7abb93f7ce623f61b94cadfdb180cef12da6559d092e6b374202acda3",

That's the reason I set the hash to 12202d26b8c618b661ac5c9f96c11926f931fbea6afd302b7e71df9b3d256e79db91. Then I get the following:

Fetch Packages [2/2] zap.facil.io... /home/jotunn/.cache/zig/p/12202d26b8c618b661ac5c9f96c11926f931fbea6afd302b7e71df9b3d256e79db91/build.zig.zon:8:21: error: hash mismatch: expected: 12200301960bbde64052db068cf31a64091ce1f671898513d9b8d9e2be5b0e4b13a3, found: 12206956e1c8e1af5fd28e44d534e4e131299545fa0676e1edc04bf02eb2185e266a
            .hash = "12200301960bbde64052db068cf31a64091ce1f671898513d9b8d9e2be5b0e4b13a3",

Then I change the hash to 12206956e1c8e1af5fd28e44d534e4e131299545fa0676e1edc04bf02eb2185e266a to get at least something. And that's the point it complains for not finding the zap module.

renerocksai commented 1 year ago

Then please wget or curl -v the url you have in build.zig.zon and verify it downloads the .tar.gz. I used the .deps from the readme just now to confirm both url and hash are correct. I can only imagine you're behind some weird proxy or something that messes with fetching the package. Hang on, I'll try the deps you provided, maybe there's something I overlooked.

renerocksai commented 1 year ago

When I use your build.zig.zon's dependencies, I get:

  .dependencies = .{ 
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.1.14-pre.tar.gz",
            .hash = "12206956e1c8e1af5fd28e44d534e4e131299545fa0676e1edc04bf02eb2185e266a",
        } 
    } 
zig build 
Fetch Packages [1/1] zap... /home/rs/code/github.com/nim-artificial-intelligence/digital-nudges-shop/build.zig.zon:8:21: error: hash mismatch: expected: 12206956e1c8e1af5fd28e44d534e4e131299545fa0676e1edc04bf02eb2185e266a, found: 122067d12bc7abb93f7ce623f61b94cadfdb180cef12da6559d092e6b374202acda3
            .hash = "12206956e1c8e1af5fd28e44d534e4e131299545fa0676e1edc04bf02eb2185e266a",
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When I use:

     .dependencies = .{
         // zap v0.1.14-pre
         .zap = .{
             .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.1.14-pre.tar.gz",
             .hash = "122067d12bc7abb93f7ce623f61b94cadfdb180cef12da6559d092e6b374202acda3",
         }
     }

it works again.

This is an issue not of zap. It's more one with the zig package manager, but I really think it's your setup. Would be interested to see what you get when you do a wget -v https://github.com/zigzap/zap/archive/refs/tags/v0.1.14-pre.tar.gz I get:

 wget -v https://github.com/zigzap/zap/archive/refs/tags/v0.1.14-pre.tar.gz
--2023-09-25 21:26:37--  https://github.com/zigzap/zap/archive/refs/tags/v0.1.14-pre.tar.gz
Resolving github.com (github.com)... 140.82.121.4
Connecting to github.com (github.com)|140.82.121.4|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/zigzap/zap/tar.gz/refs/tags/v0.1.14-pre [following]
--2023-09-25 21:26:37--  https://codeload.github.com/zigzap/zap/tar.gz/refs/tags/v0.1.14-pre
Resolving codeload.github.com (codeload.github.com)... 140.82.121.9
Connecting to codeload.github.com (codeload.github.com)|140.82.121.9|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: ‘v0.1.14-pre.tar.gz.1’

v0.1.14-pre.tar.gz.1                 [ <=>                                                       ]   1.74M  10.8MB/s    in 0.2s

2023-09-25 21:26:37 (10.8 MB/s) - ‘v0.1.14-pre.tar.gz.1’ saved [1826678]
renerocksai commented 1 year ago

Well I don't even get to the point of building if I use the provided hash:

Fetch Packages [1/1] zap... /home/jotunn/Projects/zig/zig-web-server/build.zig.zon:7:21: error: hash mismatch: expected: 122067d12bc7abb93f7ce623f61b94cadfdb180cef12da6559d092e6b374202acda3, found: 12202d26b8c618b661ac5c9f96c11926f931fbea6afd302b7e71df9b3d256e79db91
            .hash = "122067d12bc7abb93f7ce623f61b94cadfdb180cef12da6559d092e6b374202acda3",

That's the reason I set the hash to 12202d26b8c618b661ac5c9f96c11926f931fbea6afd302b7e71df9b3d256e79db91. Then I get the following:

Fetch Packages [2/2] zap.facil.io... /home/jotunn/.cache/zig/p/12202d26b8c618b661ac5c9f96c11926f931fbea6afd302b7e71df9b3d256e79db91/build.zig.zon:8:21: error: hash mismatch: expected: 12200301960bbde64052db068cf31a64091ce1f671898513d9b8d9e2be5b0e4b13a3, found: 12206956e1c8e1af5fd28e44d534e4e131299545fa0676e1edc04bf02eb2185e266a
            .hash = "12200301960bbde64052db068cf31a64091ce1f671898513d9b8d9e2be5b0e4b13a3",

Then I change the hash to 12206956e1c8e1af5fd28e44d534e4e131299545fa0676e1edc04bf02eb2185e266a to get at least something. And that's the point it complains for not finding the zap module.

Above we see that whatever messes with the download, changes the hash of the zap dependency. When you fix the hash, it downloads zap correctly but then fails to fetch the dependency contained within zap's build.zig.zon that it just unpacked.

In that case, a workaround is: try building zap itself. That will try to fetch zap's dependency and fail. You can fix zap's build.zig.zon with the hash from the error message and try again. It shouldn't complain anymore. Then, facil.io should be in you zig package cache and maybe the package manager won't try to fetch it again when you try to build your project.

I asked how you installed zig. Now I ask about your setup: are you using some proxy / vpn / ... that could play man-in-the-middle?