ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
31.87k stars 2.33k forks source link

add http/socks5 proxy support for package manager #15048

Open binarycraft007 opened 1 year ago

binarycraft007 commented 1 year ago

Not all people have unrestricted network access to package source, for example: github is censored by some countries, it would be good to add proxy support for package manager so that user under restricted network can fetch package successfully.

nektro commented 1 year ago

personally more interested in this so that Zig supports Tor

Tesseract22 commented 11 months ago

What is the progress on this? I am also suffering from censorship of github. Besides directly setting a proxy on zig package manager, is there a way to manually download the dependencies and have the package manager skip over the downloading part?

snoire commented 11 months ago

Besides directly setting a proxy on zig package manager, is there a way manually to download the dependencies and have the package manager skips over the downloading part?

You can download the dependency into ~/.cache/zig/p, unzip it, and rename the folder to the hash value. Then zig build will use the local copies instead of trying to download.

tizee commented 10 months ago

Here is my workaround for the proxy issue. After building my patched zig from source, I could use zig build --build-proxy http://127.0.0.1:1080 to fetch pacakages via proxy.

I'm still confused that there are two zig build commands. One is for fetch packages and another is for build runner.

https://github.com/tizee/zig/tree/feature/http-socks5-proxy-support

alberic89 commented 10 months ago

zig build should detect and use http_proxy and https_proxy environment variables. My entire network is behind a proxy that doesn't let anything else through, and I assume this is also the case in many universities and work offices. It's a shame not to be able to use the Zig build system simply because it can't read the signposts of the internet route.

abrasumente233 commented 9 months ago

My temporary workaround is to manually download the package, host it locally and change the dependency URL accordingly:

{
  .binned_allocator = .{
    .url = "http://localhost:8080/8372900fcc09e38d7b0b6bbaddad3904-6c3321e0969ff2463f8335da5601986cf2108690.tar.gz",
    .hash = "1220363c7e27b2d3f39de6ff6e90f9537a0634199860fea237a55ddb1e1717f5d6a5",
  },
}

If anyone wants to implement http_proxy, https_proxy and no_proxy properly, it should be relatively easy, since zig's http client already supports proxies, and there is Go's proxy parsing and matching reference implementation: https://cs.opensource.google/go/x/net/+/refs/tags/v0.15.0:http/httpproxy/proxy.go

konosubakonoakua commented 5 months ago

any update?

Jack-Ji commented 2 months ago
#!/bin/bash

set -e

if [ $# -ne 1 ] && [ ! -e build.zig.zon ]; then
  echo "Couldn't find build.zig.zon file, please give path to it, or change current dir to a decent zig project"
  echo "  usage: zfetch.sh [build.zig.zon]"
  exit -1
fi

do_fetch() {
  for d in `grep -o 'https://.*tar\.gz' $1`; do
    wget $d
    tarfile=${d##*/}
    hash=`zig fetch --debug-hash $tarfile | tail -n 1`
    rm $tarfile
    if [ -e ~/.cache/zig/p/$hash/build.zig.zon ]; then
      do_fetch ~/.cache/zig/p/$hash/build.zig.zon
    fi
  done
}

zonfile=$1
if [ -z "$1" ]; then
  zonfile=build.zig.zon
fi

do_fetch $zonfile

A dirty script to workaround the issue.

konosubakonoakua commented 3 weeks ago

or manually manage plugins like this project. https://github.com/Srekel/tides-of-revival/blob/2aec79d644bbf5358ff502952386e138ebbf247f/sync_external.py#L63