Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable windows/arm64 go build with bazel #3072

Merged
merged 7 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go/private/platforms.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ GOOS_GOARCH = (
("windows", "386"),
("windows", "amd64"),
("windows", "arm"),
("windows", "arm64"),
)

RACE_GOOS_GOARCH = {
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions go/private/sdk.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -277,6 +283,10 @@ def _detect_host_platform(ctx):

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try ctx.os.arch?

Suggested change
goos, goarch = "windows", "amd64"
if _get_env_var(ctx, "PROCESSOR_ARCHITECTURE") == "ARM64":
goarch = "arm64"
elif _get_env_var(ctx, "PROCESSOR_ARCHITEW6432") == "ARM64":
goarch = "arm64"
goos = "windows"
if ctx.os.arch == "<some archecture>":
goarch = "arm64"
else:
goarch = "amd64"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better! Seems to work

niyas-sait marked this conversation as resolved.
Show resolved Hide resolved
elif ctx.os.name == "freebsd":
goos, goarch = "freebsd", "amd64"
else:
Expand Down