Created
October 10, 2020 08:00
-
-
Save loganlinn/d35a10e47dbcbe1b93e0bdfedf7fcab0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Implementation taken from: https://github.com/bazelbuild/rules_go/blob/312a801084712314ea7da6f1c226306af58eb097/go/private/sdk.bzl#L182-L218 | |
def detect_host_platform(ctx): | |
"""Returns string identifier for host platform.""" | |
if ctx.os.name == "linux": | |
host = "linux_amd64" | |
res = ctx.execute(["uname", "-p"]) | |
if res.return_code == 0: | |
uname = res.stdout.strip() | |
if uname == "s390x": | |
host = "linux_s390x" | |
elif uname == "i686": | |
host = "linux_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": | |
host = "linux_arm64" | |
elif uname == "armv6l": | |
host = "linux_arm" | |
elif uname == "armv7l": | |
host = "linux_arm" | |
elif uname == "ppc64le": | |
host = "linux_ppc64le" | |
# Default to amd64 when uname doesn't return a known value. | |
elif ctx.os.name == "mac os x": | |
host = "darwin_amd64" | |
elif ctx.os.name.startswith("windows"): | |
host = "windows_amd64" | |
elif ctx.os.name == "freebsd": | |
host = "freebsd_amd64" | |
else: | |
fail("Unsupported operating system: " + ctx.os.name) | |
return host |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment