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.26k stars 1.63k forks source link

[GR-52996] NPE when using the minimal vs_BuildTools.exe with vswhere.exe in 24.1.0 #8669

Open sheng-ri opened 6 months ago

sheng-ri commented 6 months ago

Feature request

Is your feature request related to a problem? Please describe. For my personal reasons, I need to install msvc and windows sdk in other path, so when using cmd to run native-image, I need run vcvars64 before using native-image. Now i'm try Gradle plugin for GraalVM Native Image building, The previous method is useless.

Describe the solution you'd like. Specify a enviroment path to found vcvarsall or add a arg to specify it.

Describe who do you think will benefit the most. GraalVM users, developers of libraries and frameworks and those tho first try native-image.

Describe alternatives you've considered. for learning purposes,I found these way to solve problem.....

mkdir "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build>"
echo "F:\Visual Studio\VC\Auxiliary\Build\vcvars64.bat" %* > "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat"

Express whether you'd like to help contributing this feature I apologize, but I don't have the ability to contribute at the moment due to my limitations.

fniephaus commented 5 months ago

Thanks for the feature request! We've got some good news for you: As of https://github.com/oracle/graal/pull/8084, Native Image uses vswhere.exe to locate Visual Studio installations. This make the detection more reliable and it should also support custom installation locations. This feature will be available in the next EA 05 build of GraalVM and will ship with GraalVM for JDK 23.

Please feel free to give this a try and let us know if something is not working for you. Hope this helps!

sheng-ri commented 5 months ago

Thanks for your reply,After my testing there are still problems.

My env I only download the vs build tool. https://aka.ms/vs/17/release/vs_BuildTools.exe Then select msvc and windows 10 sdk. In this way, you can download msvc without visual studio editor.

Test result vswhere.exe -version 17.6 -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format json []

native-image -jar .\untitled-1.0-SNAPSHOT.jar test

        at java.base@23/java.util.Objects.requireNonNull(Objects.java:220)
        at java.base@23/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:215)
        at java.base@23/java.nio.file.Path.of(Path.java:148)
        at java.base@23/java.nio.file.Paths.get(Paths.java:69)
        at org.graalvm.nativeimage.driver/com.oracle.svm.driver.WindowsBuildEnvironmentUtil.findVCVarsallWithVSWhere(WindowsBuildEnvironmentUtil.java:114)
        at org.graalvm.nativeimage.driver/com.oracle.svm.driver.WindowsBuildEnvironmentUtil.propagateEnv(WindowsBuildEnvironmentUtil.java:53)
        at org.graalvm.nativeimage.driver/com.oracle.svm.driver.NativeImage.buildImage(NativeImage.java:1689)
        at org.graalvm.nativeimage.driver/com.oracle.svm.driver.NativeImage.completeImageBuild(NativeImage.java:1329)
        at org.graalvm.nativeimage.driver/com.oracle.svm.driver.NativeImage.build(NativeImage.java:1880)
        at org.graalvm.nativeimage.driver/com.oracle.svm.driver.NativeImage.performBuild(NativeImage.java:1845)
        at org.graalvm.nativeimage.driver/com.oracle.svm.driver.NativeImage.main(NativeImage.java:1827)
        at java.base@23/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
fniephaus commented 5 months ago

I'm not sure if vs_BuildTools.exe fulfills the requirements but we should handle the NPE. Thanks for bringing this up!