Skip to content

Commit

Permalink
Getting architecture from JRE (bazelbuild#3282)
Browse files Browse the repository at this point in the history
  • Loading branch information
linzhp authored Sep 10, 2022
1 parent 4068712 commit cf20167
Showing 1 changed file with 10 additions and 46 deletions.
56 changes: 10 additions & 46 deletions go/private/sdk.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -258,53 +258,17 @@ def _sdk_build_file(ctx, platform, version):
)

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 = ctx.os.name
if goos == "mac os x":
goos = "darwin"
elif goos.startswith("windows"):
goos = "windows"
if ctx.os.environ.get("PROCESSOR_ARCHITECTURE") == "ARM64" or ctx.os.environ.get("PROCESSOR_ARCHITEW6432") == "ARM64":
goarch = "arm64"
else:
goarch = "amd64"
elif ctx.os.name == "freebsd":
goos, goarch = "freebsd", "amd64"
else:
fail("Unsupported operating system: " + ctx.os.name)

goarch = ctx.os.arch
if goarch == "aarch64":
goarch = "arm64"
elif goarch == "x86_64":
goarch = "amd64"

return goos, goarch

Expand Down

0 comments on commit cf20167

Please sign in to comment.