Skip to content

Commit

Permalink
Remove Latin-1 workaround on Bazel 6.4.0+
Browse files Browse the repository at this point in the history
The fix for Latin-1 encoded files was landed in [6.4.0] after
being landed on Bazel [master].

We can conditionally use the old, unhermetic, `tar` workaround
on modern Bazel versions.

[master]: bazelbuild/bazel#18448
[6.4.0]: bazelbuild/bazel#19765
  • Loading branch information
mattyclarkson committed Feb 26, 2024
1 parent 8c014fd commit ea2048c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module(

# The custom repo_name is used to prevent our bazel_features polyfill for WORKSPACE builds from
# conflicting with the real bazel_features repo.
bazel_dep(name = "bazel_features", version = "1.1.1", repo_name = "io_bazel_rules_go_bazel_features")
bazel_dep(name = "bazel_features", version = "1.6.0", repo_name = "io_bazel_rules_go_bazel_features")
bazel_dep(name = "bazel_skylib", version = "1.2.0")
bazel_dep(name = "platforms", version = "0.0.4")
bazel_dep(name = "rules_proto", version = "4.0.0")
Expand Down
17 changes: 14 additions & 3 deletions go/private/sdk.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ load("//go/private:common.bzl", "executable_path")
load("//go/private:nogo.bzl", "go_register_nogo")
load("//go/private/skylib/lib:versions.bzl", "versions")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "patch", "read_user_netrc", "use_netrc")
load("@io_bazel_rules_go_bazel_features//:features.bzl", "bazel_features")

MIN_SUPPORTED_VERSION = (1, 14, 0)

Expand Down Expand Up @@ -441,7 +442,14 @@ def _remote_sdk(ctx, urls, strip_prefix, sha256):
# in Bazel 6.0.0+ (bazelbuild/bazel#16052). The only situation where
# .zip files are needed seems to be a macOS host using a Windows toolchain
# for remote execution.
if urls[0].endswith(".tar.gz"):
if bazel_features.external_deps.extract_supports_unicode_filenames:
ctx.download_and_extract(
url = urls,
stripPrefix = strip_prefix,
sha256 = sha256,
auth = auth,
)
elif urls[0].endswith(".tar.gz"):
if strip_prefix != "go":
fail("strip_prefix not supported")
ctx.download(
Expand All @@ -455,7 +463,7 @@ def _remote_sdk(ctx, urls, strip_prefix, sha256):
fail("error extracting Go SDK:\n" + res.stdout + res.stderr)
ctx.delete("go_sdk.tar.gz")
elif (urls[0].endswith(".zip") and
host_goos != "windows" and
host_goos == "darwin" and
# Development versions of Bazel have an empty version string. We assume that they are
# more recent than the version that introduced rename_files.
versions.is_at_least("6.0.0", versions.get() or "6.0.0")):
Expand All @@ -469,13 +477,16 @@ def _remote_sdk(ctx, urls, strip_prefix, sha256):
},
auth = auth,
)
else:
elif (urls[0].endswith(".zip") and
host_goos != "darwin"):
ctx.download_and_extract(
url = urls,
stripPrefix = strip_prefix,
sha256 = sha256,
auth = auth,
)
else:
fail("No supported workaround for extracting Go SDK non-ASCII filenames. Bazel 6.4.0+ has correct support for unpacking the Go SDK. {}".format(urls[0]))

def _local_sdk(ctx, path):
for entry in ctx.path(path).readdir():
Expand Down

0 comments on commit ea2048c

Please sign in to comment.