From 614e3b23ccd0b698d133985c7d12d38c9483df55 Mon Sep 17 00:00:00 2001 From: Niyas Sait Date: Fri, 18 Feb 2022 10:05:24 +0000 Subject: [PATCH 1/7] enable windows/arm64 go build with bazel --- go/private/platforms.bzl | 2 ++ go/private/sdk.bzl | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/go/private/platforms.bzl b/go/private/platforms.bzl index ee2c7accba..21a62e90da 100644 --- a/go/private/platforms.bzl +++ b/go/private/platforms.bzl @@ -83,6 +83,7 @@ GOOS_GOARCH = ( ("windows", "386"), ("windows", "amd64"), ("windows", "arm"), + ("windows", "arm64"), ) RACE_GOOS_GOARCH = { @@ -135,6 +136,7 @@ CGO_GOOS_GOARCH = { ("solaris", "amd64"): None, ("windows", "386"): None, ("windows", "amd64"): None, + ("windows", "arm64"): None, } def _generate_constraints(names, bazel_constraints): diff --git a/go/private/sdk.bzl b/go/private/sdk.bzl index 7c73c116ee..727b5c69ef 100644 --- a/go/private/sdk.bzl +++ b/go/private/sdk.bzl @@ -276,7 +276,15 @@ def _detect_host_platform(ctx): # Default to amd64 when uname doesn't return a known value. elif ctx.os.name.startswith("windows"): - goos, goarch = "windows", "amd64" + if "PROCESSOR_ARCHITECTURE" in ctx.os.environ and \ + ctx.os.environ["PROCESSOR_ARCHITECTURE"] == "ARM64": + goarch = "arm64" + elif "PROCESSOR_ARCHITEW6432" in ctx.os.environ and \ + ctx.os.environ["PROCESSOR_ARCHITEW6432"] == "ARM64": + goarch = "arm64" + else: + goarch = "amd64" + goos = "windows" elif ctx.os.name == "freebsd": goos, goarch = "freebsd", "amd64" else: From 758971c520505ad20b3febe09bcd17923b6257be Mon Sep 17 00:00:00 2001 From: Niyas Sait Date: Fri, 18 Feb 2022 10:40:11 +0000 Subject: [PATCH 2/7] add _get_env_var to simplify getting env variable --- go/private/sdk.bzl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/go/private/sdk.bzl b/go/private/sdk.bzl index 727b5c69ef..f83c46bfeb 100644 --- a/go/private/sdk.bzl +++ b/go/private/sdk.bzl @@ -237,6 +237,12 @@ def _sdk_build_file(ctx, platform): }, ) +def _get_env_var(ctx, name, default=""): + if name in ctx.os.environ: + return ctx.os.environ[name] + else: + return default + def _detect_host_platform(ctx): if ctx.os.name == "linux": goos, goarch = "linux", "amd64" @@ -276,11 +282,9 @@ def _detect_host_platform(ctx): # Default to amd64 when uname doesn't return a known value. elif ctx.os.name.startswith("windows"): - if "PROCESSOR_ARCHITECTURE" in ctx.os.environ and \ - ctx.os.environ["PROCESSOR_ARCHITECTURE"] == "ARM64": + if _get_env_var(ctx, "PROCESSOR_ARCHITECTURE") == "ARM64": goarch = "arm64" - elif "PROCESSOR_ARCHITEW6432" in ctx.os.environ and \ - ctx.os.environ["PROCESSOR_ARCHITEW6432"] == "ARM64": + elif _get_env_var(ctx, "PROCESSOR_ARCHITEW6432") == "ARM64": goarch = "arm64" else: goarch = "amd64" From 3f56d2e07762c0c56f9f301a6505fb40312440dc Mon Sep 17 00:00:00 2001 From: Niyas Sait Date: Fri, 18 Feb 2022 17:05:41 +0000 Subject: [PATCH 3/7] minor refactoring to match darwin part --- go/private/sdk.bzl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/go/private/sdk.bzl b/go/private/sdk.bzl index f83c46bfeb..d535e90923 100644 --- a/go/private/sdk.bzl +++ b/go/private/sdk.bzl @@ -282,13 +282,11 @@ def _detect_host_platform(ctx): # Default to amd64 when uname doesn't return a known value. elif ctx.os.name.startswith("windows"): + goos, goarch = "windows", "amd64" if _get_env_var(ctx, "PROCESSOR_ARCHITECTURE") == "ARM64": goarch = "arm64" elif _get_env_var(ctx, "PROCESSOR_ARCHITEW6432") == "ARM64": goarch = "arm64" - else: - goarch = "amd64" - goos = "windows" elif ctx.os.name == "freebsd": goos, goarch = "freebsd", "amd64" else: From 241594937498559df21eeafcb2c17f20e04e0dcf Mon Sep 17 00:00:00 2001 From: Niyas Sait Date: Wed, 16 Mar 2022 11:28:52 +0000 Subject: [PATCH 4/7] Fix linting error --- go/private/sdk.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/private/sdk.bzl b/go/private/sdk.bzl index d535e90923..906259ef66 100644 --- a/go/private/sdk.bzl +++ b/go/private/sdk.bzl @@ -237,7 +237,7 @@ def _sdk_build_file(ctx, platform): }, ) -def _get_env_var(ctx, name, default=""): +def _get_env_var(ctx, name, default = ""): if name in ctx.os.environ: return ctx.os.environ[name] else: From 92d0012c909daa0a8f9bfdb9b1dc3d14dec4edbf Mon Sep 17 00:00:00 2001 From: Niyas Sait Date: Tue, 22 Mar 2022 18:41:14 +0000 Subject: [PATCH 5/7] use ctx.os.arch to get architecture --- go/private/sdk.bzl | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/go/private/sdk.bzl b/go/private/sdk.bzl index 906259ef66..4acdc2eade 100644 --- a/go/private/sdk.bzl +++ b/go/private/sdk.bzl @@ -237,12 +237,6 @@ def _sdk_build_file(ctx, platform): }, ) -def _get_env_var(ctx, name, default = ""): - if name in ctx.os.environ: - return ctx.os.environ[name] - else: - return default - def _detect_host_platform(ctx): if ctx.os.name == "linux": goos, goarch = "linux", "amd64" @@ -282,11 +276,11 @@ def _detect_host_platform(ctx): # Default to amd64 when uname doesn't return a known value. elif ctx.os.name.startswith("windows"): - goos, goarch = "windows", "amd64" - if _get_env_var(ctx, "PROCESSOR_ARCHITECTURE") == "ARM64": - goarch = "arm64" - elif _get_env_var(ctx, "PROCESSOR_ARCHITEW6432") == "ARM64": + goos = "windows" + if ctx.os.arch == "aarch64": goarch = "arm64" + else: + goarch = "amd64" elif ctx.os.name == "freebsd": goos, goarch = "freebsd", "amd64" else: From 765b2b0e81e2504e8024b60690a262b2e914493a Mon Sep 17 00:00:00 2001 From: Niyas Sait Date: Wed, 23 Mar 2022 12:37:41 +0000 Subject: [PATCH 6/7] Revert "use ctx.os.arch to get architecture" This reverts commit 92d0012c909daa0a8f9bfdb9b1dc3d14dec4edbf. --- go/private/sdk.bzl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/go/private/sdk.bzl b/go/private/sdk.bzl index 4acdc2eade..906259ef66 100644 --- a/go/private/sdk.bzl +++ b/go/private/sdk.bzl @@ -237,6 +237,12 @@ def _sdk_build_file(ctx, platform): }, ) +def _get_env_var(ctx, name, default = ""): + if name in ctx.os.environ: + return ctx.os.environ[name] + else: + return default + def _detect_host_platform(ctx): if ctx.os.name == "linux": goos, goarch = "linux", "amd64" @@ -276,11 +282,11 @@ def _detect_host_platform(ctx): # Default to amd64 when uname doesn't return a known value. elif ctx.os.name.startswith("windows"): - goos = "windows" - if ctx.os.arch == "aarch64": + goos, goarch = "windows", "amd64" + if _get_env_var(ctx, "PROCESSOR_ARCHITECTURE") == "ARM64": + goarch = "arm64" + elif _get_env_var(ctx, "PROCESSOR_ARCHITEW6432") == "ARM64": goarch = "arm64" - else: - goarch = "amd64" elif ctx.os.name == "freebsd": goos, goarch = "freebsd", "amd64" else: From 852f119909affe8eba001235e73d11831c1976ca Mon Sep 17 00:00:00 2001 From: Niyas Sait Date: Wed, 23 Mar 2022 17:40:59 +0000 Subject: [PATCH 7/7] remove _get_env_var and directly use ctx.os.environ --- go/private/sdk.bzl | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/go/private/sdk.bzl b/go/private/sdk.bzl index 906259ef66..4189d81989 100644 --- a/go/private/sdk.bzl +++ b/go/private/sdk.bzl @@ -237,12 +237,6 @@ def _sdk_build_file(ctx, platform): }, ) -def _get_env_var(ctx, name, default = ""): - if name in ctx.os.environ: - return ctx.os.environ[name] - else: - return default - def _detect_host_platform(ctx): if ctx.os.name == "linux": goos, goarch = "linux", "amd64" @@ -282,11 +276,11 @@ def _detect_host_platform(ctx): # Default to amd64 when uname doesn't return a known value. elif ctx.os.name.startswith("windows"): - goos, goarch = "windows", "amd64" - if _get_env_var(ctx, "PROCESSOR_ARCHITECTURE") == "ARM64": - goarch = "arm64" - elif _get_env_var(ctx, "PROCESSOR_ARCHITEW6432") == "ARM64": + 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: