Skip to content

Commit eeea8d3

Browse files
committed
feat: try first to download the source archive instead of using git for github.com
This prevents anonymous fetch to be blocked especially in company networks when remote caches are down: ``` Finished `release` profile [optimized] target(s) in 41.59s ERROR: error running 'git fetch origin refs/heads/*:refs/remotes/origin/* refs/tags/*:refs/tags/*' while working with @rules_rs++crate+frc__github.com_JetBrains_alacritty_41b81372: fatal: could not read Username for 'https://github.com': No such device or address fatal: expected flush after ref listing Process exited with code 8 Process exited with code 8 (Step: bazel.cmd fetch (Bazel)) Step bazel.cmd fetch (Bazel) failed ```
1 parent 8133604 commit eeea8d3

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

rs/private/git_cargo_workspace_repository.bzl

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,35 @@ crate(
6060
package_metadata_bazel_additive_build_file_content = cargo.bazel_metadata.get("additive_build_file_content", ""),
6161
))
6262

63+
_GITHUB_PREFIX = "https://github.com/"
64+
65+
def _download_github_tarball(rctx):
66+
"""Downloads the crate sources from the GitHub archive.
67+
68+
Returns `False` when the caller must fall back to `git`.
69+
"""
70+
repo_path = rctx.attr.remote.removeprefix(_GITHUB_PREFIX).removesuffix(".git")
71+
rctx.download_and_extract(
72+
url = "https://github.com/%s/archive/%s.tar.gz" % (repo_path, rctx.attr.commit),
73+
type = "tar.gz",
74+
stripPrefix = "%s-%s" % (repo_path.split("/")[-1], rctx.attr.commit),
75+
canonical_id = "%s@%s" % (rctx.attr.remote, rctx.attr.commit),
76+
# No checksum: GitHub does not promise a byte-stable archive. The commit pins the content.
77+
)
78+
79+
# A GitHub archive holds no submodule.
80+
if rctx.path(".gitmodules").exists:
81+
rctx.report_progress("%s uses a submodule, falling back to git" % repo_path)
82+
return False
83+
84+
return True
85+
6386
def _git_cargo_workspace_repository_impl(rctx):
64-
git_repo(rctx, rctx.path("."))
87+
# The archive goes through the Bazel downloader. The downloader retries a failed request and it
88+
# obeys `--downloader_config`. The `git` subprocess does neither. `git_repo` deletes the
89+
# directory first, so it can still take over after the archive lands.
90+
if not rctx.attr.remote.startswith(_GITHUB_PREFIX) or not _download_github_tarball(rctx):
91+
git_repo(rctx, rctx.path("."))
6592

6693
patch(rctx)
6794
rctx.delete(rctx.path(".git"))

0 commit comments

Comments
 (0)