Categories: Build Tools and Procedures, OpenJDK

Building Windows AArch64 OpenJDK using Visual Studio Build Tools

The 8353009: Improve documentation for Windows AArch64 builds PR has a comment stating that “the BuildTools distribution of Visual Studio do not include aarch64-hosted compilers, so to be able to run native builds without the Prism emulation, you need to install the full Visual Studio, including the IDE.” This post describes how I determined this to be false.

I started by looking up how to install Visual Studio Build Tools. The first result I examined was Install Visual Studio Build Tools into a container to support a consistent build system, which at gave me the command line format for installing the build tools. These tools are available on the Visual Studio 2022 Release History page. I wanted a minimal set of components to install so I started with the ARM64 tools and the Windows 11 SDK:

vs_buildtools.exe --quiet --wait --norestart --nocache --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2022\BuildTools" --add Microsoft.VisualStudio.Component.VC.Tools.ARM64 --add Microsoft.VisualStudio.Component.Windows11SDK.22621

Running bash configure --with-boot-jdk=<PATH> failed with the error that it could not find a C compiler:

...
checking for cacerts file... default
checking for cacerts source... default
checking for --enable-unlimited-crypto... enabled, default
checking for jni library path... default
configure: Using default toolchain microsoft (Microsoft Visual Studio)
configure: Found Visual Studio installation at /cygdrive/c/progra~2/micros~2/2022/BuildTools using well-known name
configure: Found Microsoft Visual Studio 2022
configure: Trying to extract Visual Studio environment variables for aarch64
configure: using /cygdrive/c/progra~2/micros~2/2022/BuildTools/vc/auxiliary/build/vcvarsarm64.bat
configure: Setting extracted environment variables for aarch64
checking that Visual Studio variables have been correctly extracted... ok
checking for cl... [not found]
configure: error: Could not find a C compiler.
configure exiting with result code 1

The “cl” compiler name it is searching for came from the TOOLCHAIN_DETERMINE_TOOLCHAIN_TYPE macro in jdk/make/autoconf/toolchain.m4. The actual error message (Could not find a C compiler) comes from the TOOLCHAIN_FIND_COMPILER macro, which is invoked by the TOOLCHAIN_DETECT_TOOLCHAIN_CORE macro. The $COMPILER_NAME variable in the error message is the second argument in the TOOLCHAIN_FIND_COMPILER([CC], [C], $TOOLCHAIN_CC_BINARY) call. These macros are invoked from the top level configure.ac file.

The TOOLCHAIN_FIND_COMPILER macro calls the UTIL_LOOKUP_TOOLCHAIN_PROGS macro to find the C compiler. I verified that the last argument is “cl” with an AC_MSG_NOTICE. At this point, I compared the TOOLCHAIN_PATH in config.log with that on a different ARM64 machine with a full VS install. Sure enough, it didn’t contain the bin/hostarm64/arm64 path with the buildtools setup, even though the path exists on disk. TOOLCHAIN_PATH is coming from VS_PATH in toolchain_microsoft.m4. Here is the build\windows-aarch64-server-slowdebug\configure-support\vs-env-aarch64\set-vs-env.sh file.

PATH_BEFORE=$($BASH $TOPDIR/make/scripts/fixpath.sh -i import 'C:\windows\system32;C:\cygwin64\usr\local\bin;C:\cygwin64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Users\USER\AppData\Local\Microsoft\WindowsApps ') 
PATH_AFTER=$($BASH $TOPDIR/make/scripts/fixpath.sh -i import 'c:\PROGRA~2\MICROS~2\2022\BuildTools\MSBuild\Current\bin\Roslyn;C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\\arm64;C:\Program Files (x86)\Windows Kits\10\bin\\arm64;c:\PROGRA~2\MICROS~2\2022\BuildTools\\MSBuild\Current\Bin\amd64;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;c:\PROGRA~2\MICROS~2\2022\BuildTools\Common7\IDE\;c:\PROGRA~2\MICROS~2\2022\BuildTools\Common7\Tools\;C:\windows\system32;C:\cygwin64\usr\local\bin;C:\cygwin64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Users\USER\AppData\Local\Microsoft\WindowsApps ') 
VS_INCLUDE=$($BASH $TOPDIR/make/scripts/fixpath.sh -i import 'C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt;C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\um;C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared;C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt;C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt ') 
VS_LIB=$($BASH $TOPDIR/make/scripts/fixpath.sh -i import 'C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\ucrt\arm64;C:\Program Files (x86)\Windows Kits\10\\lib\10.0.22621.0\\um\arm64 ') 
VCINSTALLDIR=$($BASH $TOPDIR/make/scripts/fixpath.sh -i import ' ') 
VCToolsRedistDir=$($BASH $TOPDIR/make/scripts/fixpath.sh -i import ' ') 
WindowsSdkDir=$($BASH $TOPDIR/make/scripts/fixpath.sh -i import 'C:\Program Files (x86)\Windows Kits\10\ ') 
WINDOWSSDKDIR=$($BASH $TOPDIR/make/scripts/fixpath.sh -i import 'C:\Program Files (x86)\Windows Kits\10\ ') 

Notice that VS_PATH only has what VS_ENV_CMD added to the PATH! This was a clue that I need to take another step back – I realized that I couldn’t even run cl.exe in the developer command prompt! Then again, the command line for the terminal is:

cmd.exe /k "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\VsDevCmd.bat" -startdir=none -arch=arm64 -host_arch=x64

Changing the host architecture to arm64 did not help. I launched the VS installer and noticed that the “Desktop development with C++” workload was not installed so I must have been missing additional components.

Visual Studio Build Tools 2022 LTSC 17.12 Workloads

I didn’t want to install the whole workload though, just the necessary individual components. I noticed the C++ Build Tools core features component wasn’t installed so I selected it. The Windows Universal C Runtime component is automatically selected as well:

Visual Studio Build Tools 2022 LTSC 17.12 Individual Components

Once the installation completed, I could run cl.exe in the developer command prompt!

**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.12.7
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************

C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools>cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.42.34441 for ARM64
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]

C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools>

The VS installer log in %TEMP% contained these components:

Microsoft.VisualStudio.Component.Roslyn.Compiler,Microsoft.Component.MSBuild,Microsoft.VisualStudio.Component.CoreBuildTools,Microsoft.VisualStudio.Component.Windows10SDK,Microsoft.VisualStudio.Component.VC.CoreBuildTools,Microsoft.VisualStudio.Component.Windows11SDK.22621,Microsoft.VisualStudio.Component.VC.Tools.ARM64EC,Microsoft.VisualStudio.Component.VC.Tools.ARM64

This led me to the minimal set of components that I needed to build OpenJDK on a Windows AArch64 machine with the Visual Studio Build Tools:

vs_buildtools.exe --quiet --wait --norestart --nocache ^
--installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2022\BuildTools" ^
--add Microsoft.VisualStudio.Component.VC.CoreBuildTools ^
--add Microsoft.VisualStudio.Component.VC.Tools.ARM64 ^
--add Microsoft.VisualStudio.Component.Windows11SDK.22621

Copilot informed me that the caret was the way to split a command across multiple lines in the Windows Command Prompt. This was the final command I used to complete the 8353009: Improve documentation for Windows AArch64 builds PR.

Article info



Leave a Reply

Your email address will not be published. Required fields are marked *