{gpu-dawn,docs}: add MACH_GITHUB_BASE_URL for using GitHub mirror sites

Users in the Chinese mainland find download speeds are too slow and need
an option to use GitHub download mirroring sites like fastgit.org, this
makes it possible to configure that using an environment variable.

See the documentation for more details.

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-09-17 08:49:24 -07:00
parent f1c74aabe2
commit 5e8ab95a74
2 changed files with 25 additions and 1 deletions

View file

@ -44,3 +44,15 @@ This is [a bug in Dawn](https://github.com/NixOS/nixpkgs/issues/150398), you can
```
LD_PRELOAD=/run/current-system/profile/lib/libvulkan.so zig-out/bin/gpu-hello-triangle
```
## Choosing a different GitHub download mirror (Chinese users)
**Background**: `zig build` on the first time around will download a 20-30MB file of Dawn (Google's WebGPU implementation) from https://github.com/hexops/mach-gpu-dawn/releases - the build system uses `curl` to do this automatically. You can of course build Dawn from source using the `-Ddawn-from-source=true` flag, but this will require a clone of the Dawn sources which are a larger download and takes a few minutes to build as it is a large C++ codebase.
Users in Chinese mainland may find that download speeds to github.com are too slow (hours to download a 30 MB file), and apparently it is common to use GitHub mirror sites like https://fastgit.org to download files from GitHub.
You can have Mach use such websites by setting an environment variable e.g.:
```sh
MACH_GITHUB_BASE_URL=https://download.fastgit.org
```

View file

@ -169,6 +169,15 @@ pub fn Sdk(comptime deps: anytype) type {
}
}
fn getGitHubBaseURLOwned(allocator: std.mem.Allocator) []const u8 {
if (std.process.getEnvVarOwned(allocator, "MACH_GITHUB_BASE_URL")) |base_url| {
std.log.info("mach: respecting MACH_GITHUB_BASE_URL: {s}\n", .{base_url});
return base_url;
} else |_| {
return "https://github.com";
}
}
pub fn linkFromBinary(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void {
const target = step.target_info.target;
const binaries_available = switch (target.os.tag) {
@ -321,11 +330,14 @@ pub fn Sdk(comptime deps: anytype) type {
// Compose the download URL, e.g.:
// https://github.com/hexops/mach-gpu-dawn/releases/download/release-6b59025/libdawn_x86_64-macos-none_debug.a.gz
const github_base_url = getGitHubBaseURLOwned(allocator);
defer allocator.free(github_base_url);
const lib_prefix = if (is_windows) "dawn_" else "libdawn_";
const lib_ext = if (is_windows) ".lib" else ".a";
const lib_file_name = if (is_windows) "dawn.lib" else "libdawn.a";
const download_url = try std.mem.concat(allocator, u8, &.{
"https://github.com/hexops/mach-gpu-dawn/releases/download/",
github_base_url,
"/hexops/mach-gpu-dawn/releases/download/",
version,
"/",
lib_prefix,