From 5e8ab95a74637014b3e4a1a49c230eb6f1cd590b Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sat, 17 Sep 2022 08:49:24 -0700 Subject: [PATCH] {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 --- doc/known-issues.md | 12 ++++++++++++ libs/gpu-dawn/sdk.zig | 14 +++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/doc/known-issues.md b/doc/known-issues.md index 5969bd0b..2f93a2dc 100644 --- a/doc/known-issues.md +++ b/doc/known-issues.md @@ -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 +``` diff --git a/libs/gpu-dawn/sdk.zig b/libs/gpu-dawn/sdk.zig index bc3f4206..6af604b9 100644 --- a/libs/gpu-dawn/sdk.zig +++ b/libs/gpu-dawn/sdk.zig @@ -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,