oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.27k stars 1.63k forks source link

native-image fails to set up Windows build environment #9180

Closed trebron2 closed 3 months ago

trebron2 commented 3 months ago

My Visual Studio installation is located on drive D but linked via junction to drive C (practically same use case as issue #7528). Therefore, "vswhere -version 17.6 -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath" (both in "Developer Command Prompt for VS 2022" and "x64 Native Tools Command Prompt") returns the standard installation directory C:\Program Files\Microsoft Visual Studio\2022\Community.

VS

installationName: VisualStudio/17.10.3+35013.160 installationVersion: 17.10.35013.160 productId: Microsoft.VisualStudio.Product.Community

As expected, in the command window environment VSINSTALLDIR is set to C:\Program Files\Microsoft Visual Studio\2022\Community\ and where.exe finds compiler cl.exe (Microsoft (R) C/C++ Optimizing Compiler Version 19.40.33811 for x64).

However, running native-image for both graalvm-jdk-22.0.1+8.1 and graalvm-jdk-23+24.1 fails with error "Failed to automatically set up Windows build environment ... make sure that Visual Studio 2022 version 17.6.0 / 17.1.0 or later is installed ..." without any further information.

native-image 23 2024-09-17 GraalVM Runtime Environment Oracle GraalVM 23-dev+24.1 (build 23+24-jvmci-b01) Substrate VM Oracle GraalVM 23-dev+24.1 (build 23+24, serial gc, compressed references)

native-image 22.0.1 2024-04-16 GraalVM Runtime Environment Oracle GraalVM 22.0.1+8.1 (build 22.0.1+8-jvmci-b01) Substrate VM Oracle GraalVM 22.0.1+8.1 (build 22.0.1+8, serial gc, compressed references)

Processor AMD A10-7850K Radeon R7, 12 Compute Cores 4C+8G 3.70 GHz System type 64-bit operating system, x64-based processor Edition Windows 10 Pro Version 22H2 OS build 19045.4529

Karm commented 3 months ago

Hello @trebron2 ,

1) Locate vcvars64 script, perhaps at C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\ or wherever you have your Visual Studio.

2) Call that script, either directly in command prompt or via call in a script or you might check this in CI where things get slightly more complicated regarding propagating env variables: see.

3) You should have all relevant env vars set now to do an amd64 Windows build and you can call your native-image as you please.

trebron2 commented 3 months ago

Thanks for the quick response ...

A few minutes ago I've found out that there was an issue with the maximum length of the Path environment variable and by chance adding the graal-vm bin-directory to the path caused havoc. Therefore, even WindowsBuildEnvironmentUtil.isCCompilerOnPath() failed.

As soon as the Path problem had been resolved everything worked.