How to use Zig on WSL?

When I installed anyzig on WSL and tried to use it, it couldn’t perform network operations correctly.

anyzig: .minimum_zig_version '0.14.0' pulled from '/home/verafahn/zig/anyzig/build.zig.zon'
anyzig: appdata '/home/verafahn/.local/share/anyzig'
anyzig: downloading 'https://ziglang.org/download/0.14.0/zig-linux-x86_64-0.14.0.tar.xz'...
error: bad HTTP response code: '400 Bad Request'

But I can get it correctly using the wget command, so I’m sure this is not my network problem.

you can check the build directory for all possible links: https://ziglang.org/download/index.json

When I tried to build a project with network dependencies using Zig, it encountered the following error:

/home/verafahn/zig/anyzig/build.zig.zon:8:20: error: unable to discover remote git server capabilities: EndOfStream
            .url = "git+https://github.com/ziglang/zig#5ad91a646a753cc3eecd8751e61cf458dadd9ac4",
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/verafahn/zig/anyzig/build.zig.zon:12:20: error: unable to discover remote git server capabilities: EndOfStream
            .url = "git+https://github.com/marler8997/zipcmdline#3dfca786a489d117e4b72ea10ffb4bbd9fc2dd72",
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

And this won’t happen on my physical machine.

How should this be resolved?

It looks like a proxy that intercept the requests.

Check if there are any environment variables named HTTP_PROXY or HTTPS_PROXY or anything similar, that set a proxy in one of the environments.

I ran into something similar, described here: windows zon issue · Issue #170 · foxnne/fizzy · GitHub

Briefly: Git redirects from the path we typically use to a more direct codeload route. To avoid redirection, just rearrange your URL to go directly to the codeload. E.g., I changed the commented-out URLs to the ones shown:

 .zigwin32 = .{
            // .url = "https://github.com/kristoff-it/zigwin32/archive/1102e9b82e8bd50913b6a78035bfb399ebd8cf97.tar.gz",
            .url = "https://codeload.github.com/kristoff-it/zigwin32/archive/tar.gz/1102e9b82e8bd50913b6a78035bfb399ebd8cf97",
            .hash = "zigwin32-25.0.28-preview-6BfVhYKN5AOvXPVJq4bGZ7C5dM3PbUra4xhKAKOFJGcF",
            .lazy = true,
        },
        .icons = .{
            // .url = "https://github.com/foxnne/zig-lib-icons/archive/db034786a1286ab28dc35aba534c098aa4f1a3aa.tar.gz",
            .url = "https://codeload.github.com/foxnne/zig-lib-icons/archive/tar.gz/db034786a1286ab28dc35aba534c098aa4f1a3aa",
            .hash = "icons-0.0.0-iJxA-VvGMwAgiKSXRe_Y0O7RpasdtEJhBfVx8IGGEBl_",
            .lazy = true,
        },

Maybe if you do something similar?

Maybe Zig redirect handling (on Windows/WSL) needs work, too?

I don’t seem to have made any changes. Anyzig has become usable now, but Zig’s dependencies still cannot be downloaded:

anyzig: .minimum_zig_version '0.14.0' pulled from '/home/verafahn/zig/anyzig/build.zig.zon'
anyzig: appdata '/home/verafahn/.local/share/anyzig'
anyzig: zig '0.14.0' already exists at '/home/verafahn/.cache/zig/p/N-V-__8AANS1ihIOtIbwStI19vHd9274HDAeXLQjJFgZzdsY'
/home/verafahn/zig/anyzig/build.zig.zon:8:20: error: unable to discover remote git server capabilities: TlsInitializationFailed
            .url = "git+https://github.com/ziglang/zig#5ad91a646a753cc3eecd8751e61cf458dadd9ac4",
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/verafahn/zig/anyzig/build.zig.zon:13:20: error: unable to discover remote git server capabilities: TlsInitializationFailed
            .url = "git+https://github.com/marler8997/zipcmdline#3dfca786a489d117e4b72ea10ffb4bbd9fc2dd72",

Maybe check the networking mode of WSL? I’m able to successfully use Zig on WSL with a recent Ubuntu version FWIW