scalameta / sbt-native-image

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

Windows support #8

Closed nartamonov closed 3 years ago

nartamonov commented 4 years ago

It would be super helpful if plugin supports building native images for Windows. Right now it's not working, because coursier program inside internal directory is not in a Win32-executable format:

sbt:native-hello-world> nativeImage
[info] C:\Dev\native-hello-world\target\native-image-internal\coursier launch --jvm graalvm:20.1.0 org.graalvm.nativeimage:svm-driver:20.1.0 -- -cp C:\Dev\native-hello-world\target\native-image-internal\manifest.jar Main C:\Dev\native-hello-world\target\native-image\native-hello-world
[error] stack trace is suppressed; run last nativeImage for the full output
[error] (nativeImage) java.io.IOException: Cannot run program "C:\Dev\native-hello-world\target\native-image-internal\coursier" (in directory "C:\Dev\native-hello-world\target\native-image"): CreateProcess error=193, %1 is not a valid Win32 application
[error] Total time: 0 s, completed 3 сент. 2020 г., 15:26:07

Tested on Windows 10.

olafurpg commented 3 years ago

Thank you for reporting! I would love to support Windows and update the documentation to include instructions on how to generate Windows binaries from GitHub Actions.

I don't have a Windows computer myself, which makes it difficult to iterate on this functionality. The embedded coursier binary is a normal JVM application that should work on Windows but, if I understand correctly, the binary needs to be named "coursier.exe" for it to be executable? Otherwise, I am also not familiar with what system requirements (SDK installations?) are necessary to run GraalVM native-image on Windows. Any help would be greatly appreciated 🙏

olafurpg commented 3 years ago

I opened #9 to experiment with unblocking Windows support. I'm stuck on the following error message and I'm not sure what the best solution is

[error] java.io.FileNotFoundException: C:\Users\runneradmin\AppData\Local\Coursier\cache\v1\.structure.lock (The process cannot access the file because it is being used by another process)

cc/ @alexarchambault any idea how to work around this issue? I would love to avoid using a different cache directory. I suspect the problem happens because sbt library management has an open handle on the lock file.

alexarchambault commented 3 years ago

@olafurpg It seems going back to sbt 1.3.13 fixes this… I'm not sure why. (That makes sbt use lm-coursier-shaded 2.0.0-RC6-4 rather than 2.0.0-RC6-8, itself going from coursier 2.0.0-RC6-24 to 2.0.0-RC6-14.)

To thicken the plot, that seems to have been a problem only with the windows-2016 build, not the windows-latest one. I couldn't reproduce that problem on my Windows 10 machine.

olafurpg commented 3 years ago

@alexarchambault thank you 🙏 Good catch! Downgrading to 1.3.13 fixed the issue on windows-2016. I'm also unable to reproduce with 1.4.0-RC1 so I'm gonna assume the regression has been fixed. There are still some remaining issues related to the generated manifest jar but they're unrelated to Coursier or sbt :)

olafurpg commented 3 years ago

@nartamonov can you please try out the uploaded binary from the pending PR? See https://github.com/scalameta/sbt-native-image/pull/9#issuecomment-689122382

nartamonov commented 3 years ago

@olafurpg Sorry for the late reply, I've tested Windows support in 0.2.1. It seems it works fine except the fact that native-image 20.1.0 has some annoying bug oracle/graal#2522 which happens when you use localized MSVC build tools. Unfortunately the bug was fixed in native-image 0.2.2 only and that version is not supported currently by sbt-native-image because of #3. Hopefully upstream project will resolve shyiko/jabba#714 so I could upgrade to newer native-image. Anyway, thank you very much for Windows support!

alexarchambault commented 3 years ago

FYI, you can now fetch GraalVM 20.2.0 with the custom JVM index of coursier, with

$ cs java --jvm-index cs --jvm graalvm-java11:20.2.0 -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment GraalVM CE 20.2.0 (build 11.0.8+10-jvmci-20.2-b03)
OpenJDK 64-Bit Server VM GraalVM CE 20.2.0 (build 11.0.8+10-jvmci-20.2-b03, mixed mode, sharing)

It's not too widely advertized yet, and requires coursier >= 2.0.0-RC6-27.

nightscape commented 3 years ago

I've tried @alexarchambault's suggestion. Unfortunately, it still doesn't work because the plugin does not seem to use the --jvm-index cs option. @alexarchambault @olafurpg would it make sense to add that argument?