scalameta / sbt-native-image

Plugin to generate native-image binaries with sbt
248 stars 22 forks source link

Native image ready! BUT Error: Image build request failed with exit status 1 #29

Closed phdoerfler closed 3 years ago

phdoerfler commented 3 years ago

Describe the bug

It says the native image was ready even though there was an error:

Installing new component: Native Image (org.graalvm.native-image, version 20.2.0)
[info] C:\Users\fearis\AppData\Local\Coursier\cache\jvm\graalvm-java11@20.2.0\bin\native-image.cmd -cp C:\Users\fearis\Documents\workspace\CloseProcess\target\scala-2.13\classes;C:\Users\fearis\AppData\Local\Coursier\cache\v1\https\repo1.maven.org\maven2\org\scala-lang\scala-library\2.13.5\scala-library-2.13.5.jar;C:\Users\fearis\AppData\Local\Coursier\cache\v1\https\repo1.maven.org\maven2\org\scalameta\svm-subs\101.0.0\svm-subs-101.0.0.jar io.doerfler.ReaperMain C:\Users\fearis\Documents\workspace\CloseProcess\target\native-image\closeprocess
[C:\Users\fearis\Documents\workspace\CloseProcess\target\native-image\closeprocess:3360]    classlist:   2,269.72 ms,  0.96 GB
[C:\Users\fearis\Documents\workspace\CloseProcess\target\native-image\closeprocess:3360]        setup:     506.26 ms,  0.96 GB
Error: Default native-compiler executable 'cl.exe' not found via environment variable PATH
Error: To prevent native-toolchain checking provide command-line option -H:-CheckToolchain
Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
Error: Image build request failed with exit status 1
[info] Native image ready!
[info] C:\Users\fearis\Documents\workspace\CloseProcess\target\native-image\closeprocess

To Reproduce Steps to reproduce the behavior:

build.sbt

scalaVersion := "2.13.5"
enablePlugins(NativeImagePlugin)

plugins.sbt

addSbtPlugin("org.scalameta" % "sbt-native-image" % "0.3.0")

Run task nativeImage in sbt.

The tasks succeeds but fails to produce a binary. The reported path where said binary supposedly resides does not exist.

Expected behavior

I expect no error but if there is one I expect the task to fail and not be successful in the eyes of sbt.

Screenshots

image

Installation:

phdoerfler commented 3 years ago

@olafurpg Do you require any more info on this?

terdong commented 3 years ago

@olafurpg Do you require any more info on this?

I think, you should install "visual studio 2019 build tools" or another build tools such as MinGW, Cygwin. There is "cl.exe" in there. If "visual studio 2019" has been installed in your pc, you do not need to install "visual studio 2019 build tools".

phdoerfler commented 3 years ago

(fwiw: As far as I am concerned this issue is not so much about "How to run native-image on Windows?" but rather that about the plugin reporting a success where there isn't.)

This being said: @terdong Thanks for the suggestion! Sounds like even more ways for obtaining cl.exe and / or required header files (more on that later)! Including your suggestions this is what I've come up with so far:

In fact I have (after filing this issue) installed the Visual Studio Redistributable which also contains cl.exe. However, I then ran into the problem of missing header files. I haven't had time to investigate this matter further but it seems that the Windows SDK would provide them. Worthy of note: They can apparently be installed selectively so they won't take up too much space.

I'd love for this plugin to automatically download (to somewhere local) cl.exe and required header files to further the out-of-the-box experience and if a miracle happened and I had some spare time on my hands I'd work on a pull request but that ain't likely in the next months.

olafurpg commented 3 years ago

Thank you for reporting!

(fwiw: As far as I am concerned this issue is not so much about "How to run native-image on Windows?" but rather that about the plugin reporting a success where there isn't.)

This plugin reports the exit code from native-image so there's not much we can on this side to address that particular issue.

I'd love for this plugin to automatically download (to somewhere local) cl.exe and required header files to further the out-of-the-box experience and if a miracle happened and I had some spare time on my hands I'd work on a pull request but that ain't likely in the next months.

I'm happy to review/merge a PR that adds extra installation steps on Windows. The plugin automatically installs the correct JVM version, which seems to be sufficient to build binaries on the provided Windows images on GitHub Actions.

Closing this issue with "working as intended" since it's not clear how this plugin should be able to detect a problem when native-image returns a successful exit code.