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 25, 2024
1 parent 8c014fd commit c330329
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 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
20 changes: 12 additions & 8 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 @@ -434,14 +435,22 @@ def _remote_sdk(ctx, urls, strip_prefix, sha256):
# Docker on macOS with a bind mount).
#
# For .tar.gz files (available for most platforms), we work around this bug
# by using the system tar instead of ctx.download_and_extract.
# by using the system tar instead of ctx.download_and_extract. We could make
# this hermetic by using `@ape-tar//:entrypoint`/`@ape-gzip//:entrypoint`.
#
# For .zip files, we use ctx.download_and_extract but with rename_files,
# changing certain paths that trigger the bug. This is only available
# 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 Down Expand Up @@ -470,12 +479,7 @@ def _remote_sdk(ctx, urls, strip_prefix, sha256):
auth = auth,
)
else:
ctx.download_and_extract(
url = urls,
stripPrefix = strip_prefix,
sha256 = sha256,
auth = auth,
)
fail("No supported workaround for extracting Go SDK non-ASCII filenames. More recent versions of Bazel have correct support for unpacking the Go SDK.")

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

0 comments on commit c330329

Please sign in to comment.