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 native support for Windows on arm64 #14340

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 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
10 changes: 10 additions & 0 deletions .bazelci/build_bazel_binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,13 @@ platforms:
build_targets:
- "//src:bazel.exe"
- "//src:bazel_nojdk.exe"
windows_arm64:
meteorcloudy marked this conversation as resolved.
Show resolved Hide resolved
build_flags:
- "--copt=-w"
- "--host_copt=-w"
- "-c"
- "opt"
build_targets:
- "//src:bazel.exe"
- "//src:bazel_nojdk.exe"
- "--cpu=arm64_windows"
7 changes: 7 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ http_file(
urls = ["https://mirror.bazel.build/openjdk/azul-zulu11.37.17-ca-jdk11.0.6/zulu11.37.17-ca-jdk11.0.6-win_x64.zip"],
)

http_file(
name = "openjdk_win_arm64_vanilla",
downloaded_file_path = "zulu-win-arm64.zip",
sha256 = "811d7e7591bac4f081dfb00ba6bd15b6fc5969e1f89f0f327ef75147027c3877",
urls = ["https://cdn.azul.com/zulu/bin/zulu17.30.15-ca-jdk17.0.1-win_aarch64.zip"],
niyas-sait marked this conversation as resolved.
Show resolved Hide resolved
)

http_file(
name = "openjdk_win_minimal",
downloaded_file_path = "zulu-win-minimal.zip",
Expand Down
1 change: 1 addition & 0 deletions distdir_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ DIST_DEPS = {
"patch_args": ["-p1"],
"patches": [
"//third_party/grpc:grpc_1.41.0.patch",
"//third_party/grpc:grpc_1.41.0.win_arm64.patch",
],
"used_in": [
"additional_distfiles",
Expand Down
4 changes: 3 additions & 1 deletion site/docs/windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ target architecture, set the `--cpu` build option for your target architecture:
* x64 (default): `--cpu=x64_windows` or no option
* x86: `--cpu=x64_x86_windows`
* ARM: `--cpu=x64_arm_windows`
* ARM64: `--cpu=x64_arm64_windows`
* ARM64: `--cpu=arm64_windows`

Note: `--cpu=x64_arm64_windows` to target ARM64 architecture is deprecated. Please use `--cpu=arm64_windows`

For example, to build targets for ARM architecture, run:

Expand Down
10 changes: 8 additions & 2 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ filegroup(
"//src/conditions:darwin_arm64": [
"@openjdk_macos_aarch64//file",
],
"//src/conditions:windows": [
"//src/conditions:windows_arm64": [
"@openjdk_win_arm64_vanilla//file", # TODO(#14339): replace with openjdk_win_arm64 when packages are uploaded to bazel mirror server
],
"//src/conditions:windows_x86_64": [
"@openjdk_win//file",
],
"//src/conditions:linux_aarch64": [
Expand All @@ -169,7 +172,10 @@ filegroup(
"//src/conditions:darwin_arm64": [
"@openjdk_macos_aarch64_minimal//file",
],
"//src/conditions:windows": [
"//src/conditions:windows_arm64": [
"@openjdk_win_arm64_vanilla//file", # TODO(#14339): replace with openjdk_win_arm64 when packages are uploaded to bazel mirror server
],
"//src/conditions:windows_x86_64": [
"@openjdk_win_minimal//file",
],
"//src/conditions:linux_aarch64": [
Expand Down
39 changes: 39 additions & 0 deletions src/conditions/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,45 @@ config_setting(
visibility = ["//visibility:public"],
)

config_setting(
name = "windows_x86_64",
constraint_values = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "windows_arm64_constraint",
constraint_values = [
"@platforms//os:windows",
"@platforms//cpu:arm64",
],
)

# TODO(https://github.com/bazelbuild/bazel/issues/7260)
# Remove the flag after toolchain cc resolution is fixed
config_setting(
meteorcloudy marked this conversation as resolved.
Show resolved Hide resolved
name = "windows_x64_arm64_flag",
values = {"cpu": "x64_arm64_windows"},
)

config_setting(
name = "windows_arm64_flag",
values = {"cpu": "arm64_windows"},
)

selects.config_setting_group(
name = "windows_arm64",
match_any = [
":windows_arm64_constraint",
":windows_arm64_flag",
":windows_x64_arm64_flag"
],
visibility = ["//visibility:public"],
)

config_setting(
name = "arm",
constraint_values = ["@platforms//cpu:arm"],
Expand Down
24 changes: 18 additions & 6 deletions src/conditions/BUILD.tools
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("//tools/windows:windows_config.bzl", "create_windows_host_config")

config_setting(
name = "freebsd",
constraint_values = ["@platforms//os:freebsd"],
Expand Down Expand Up @@ -118,20 +120,30 @@ config_setting(
visibility = ["//visibility:public"],
)

# TODO: figure out how to base this selection on constraints
config_setting(
name = "windows_msvc",
values = {"cpu": "x64_windows_msvc"},
visibility = ["//visibility:public"],
name = "windows_x64",
constraint_values = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
],
)
config_setting(
name = "windows_arm64",
constraint_values = [
"@platforms//os:windows",
"@platforms//cpu:arm64",
],
)

# TODO: figure out how to base this selection on constraints
config_setting(
name = "host_windows",
values = {"host_cpu": "x64_windows"},
name = "windows_msvc",
values = {"cpu": "x64_windows_msvc"},
visibility = ["//visibility:public"],
)

create_windows_host_config()

config_setting(
name = "remote",
values = {"define": "EXECUTOR=remote"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ public String convert(String input) throws OptionsParsingException {
switch (CPU.getCurrent()) {
case X86_64:
return "x64_windows";
case AARCH64:
return "arm64_windows";
default:
// We only support x64 Windows for now.
// We only support x64 and arm64 Windows for now.
return "unknown";
}
case LINUX:
Expand Down
20 changes: 19 additions & 1 deletion src/test/py/bazel/bazel_windows_cpp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ def testBuildArmCppBinaryWithMsvcCL(self):
self.AssertExitCode(exit_code, 0, stderr)
self.assertIn('arm\\cl.exe', '\n'.join(stderr))

def testBuildArm64CppBinaryWithMsvcCL(self):
def testBuildArm64CppBinaryWithMsvcCLAndCpuX64Arm64Windows(self):
self.CreateWorkspaceWithDefaultRepos('WORKSPACE')
self.ScratchFile('BUILD', [
'cc_binary(',
Expand Down Expand Up @@ -1033,6 +1033,24 @@ def testBuildCppBinaryWithMsysGCC(self):
self.AssertFileContentContains(
os.path.join(bazel_output, paramfile % 'opt'), '-Wl,--gc-sections')

def testBuildArm64CppBinaryWithMsvcCLAndCpuArm64Windows(self):
self.CreateWorkspaceWithDefaultRepos('WORKSPACE')
self.ScratchFile('BUILD', [
'cc_binary(',
' name = "main",',
' srcs = ["main.cc"],',
')',
])
self.ScratchFile('main.cc', [
'int main() {',
' return 0;',
'}',
])
exit_code, _, stderr = self.RunBazel(
['build', '-s', '--cpu=arm64_windows', '//:main'])
self.AssertExitCode(exit_code, 0, stderr)
self.assertIn('arm64\\cl.exe', ''.join(stderr))


if __name__ == '__main__':
unittest.main()
3 changes: 3 additions & 0 deletions tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ filegroup(
"//tools/objc:srcs",
"//tools/osx:srcs",
"//tools/osx/crosstool:srcs",
"//tools/windows:srcs",
"//tools/test:srcs",
"//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:srcs",
"//tools/test/CoverageOutputGenerator/javatests/com/google/devtools/coverageoutputgenerator:srcs",
Expand Down Expand Up @@ -55,6 +56,7 @@ filegroup(
"//tools/jdk:srcs",
"//tools/launcher:srcs",
"//tools/def_parser:srcs",
"//tools/windows:srcs",
"//tools/platforms:srcs",
"//tools/objc:srcs",
"//tools/python:embedded_tools",
Expand All @@ -80,6 +82,7 @@ filegroup(
"//tools/cpp:bzl_srcs",
"//tools/jdk:bzl_srcs",
"//tools/osx:bzl_srcs",
"//tools/windows:bzl_srcs",
"//tools/python:bzl_srcs",
"//tools/sh:bzl_srcs",
],
Expand Down
Loading