diff --git a/buf/internal/toolchain.bzl b/buf/internal/toolchain.bzl index ab498e8..1cc60ff 100644 --- a/buf/internal/toolchain.bzl +++ b/buf/internal/toolchain.bzl @@ -80,54 +80,19 @@ def _register_toolchains(repo, cmd): ), ) -# Copied from rules_go: https://github.com/bazelbuild/rules_go/blob/bd44f4242b46e73fb2a81fc87ea4b52173bde84e/go/private/sdk.bzl#L240 -# -# NOTE: This doesn't check for windows/arm64 -# We can upgrade to repository_ctx.os.name and repository_ctx.os.arch once bazel 5.1 releases bazelbuild/bazel#14685 +# Copied from rules_go: https://github.com/bazelbuild/rules_go/blob/19ad920c6869a179d186a365d117ab82f38d0f3a/go/private/sdk.bzl#L517 def _detect_host_platform(ctx): - if ctx.os.name == "linux": - goos, goarch = "linux", "amd64" - res = ctx.execute(["uname", "-p"]) - if res.return_code == 0: - uname = res.stdout.strip() - if uname == "s390x": - goarch = "s390x" - elif uname == "i686": - goarch = "386" - - # uname -p is not working on Aarch64 boards - # or for ppc64le on some distros - res = ctx.execute(["uname", "-m"]) - if res.return_code == 0: - uname = res.stdout.strip() - if uname == "aarch64": - goarch = "arm64" - elif uname == "armv6l": - goarch = "arm" - elif uname == "armv7l": - goarch = "arm" - elif uname == "ppc64le": - goarch = "ppc64le" - - # Default to amd64 when uname doesn't return a known value. - - elif ctx.os.name == "mac os x": - goos, goarch = "darwin", "amd64" - - res = ctx.execute(["uname", "-m"]) - if res.return_code == 0: - uname = res.stdout.strip() - if uname == "arm64": - goarch = "arm64" - - # Default to amd64 when uname doesn't return a known value. - - elif ctx.os.name.startswith("windows"): - goos, goarch = "windows", "amd64" - elif ctx.os.name == "freebsd": - goos, goarch = "freebsd", "amd64" - else: - fail("Unsupported operating system: " + ctx.os.name) + goos = ctx.os.name + if goos == "mac os x": + goos = "darwin" + elif goos.startswith("windows"): + goos = "windows" + + goarch = ctx.os.arch + if goarch == "aarch64": + goarch = "arm64" + elif goarch == "x86_64": + goarch = "amd64" return goos, goarch