From e5759ec452703beae5d706b7e8c2d3163f86c469 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Sat, 24 Feb 2024 19:45:28 +0000 Subject: [PATCH] Remove Latin-1 workaround on Bazel 6.4.0+ 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]: https://github.com/bazelbuild/bazel/pull/18448 [6.4.0]: https://github.com/bazelbuild/bazel/pull/19765 --- MODULE.bazel | 2 +- go/private/sdk.bzl | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 6b4a274fd2..2d6e9e0d35 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -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") diff --git a/go/private/sdk.bzl b/go/private/sdk.bzl index 308891af38..0e12ba8c57 100644 --- a/go/private/sdk.bzl +++ b/go/private/sdk.bzl @@ -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) @@ -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( @@ -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. Bazel 6.4.0+ has correct support for unpacking the Go SDK.") def _local_sdk(ctx, path): for entry in ctx.path(path).readdir():