-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Native image binary doesn't run using plugin. Works with scala-cli. #19
Comments
I believe it has something to do with creating the native-config file like VirtusLab/scala-cli#830. Tried doing something like: diff --git a/plugin/src/io/github/alexarchambault/millnativeimage/NativeImage.scala b/plugin/src/io/github/alexarchambault/millnativeimage/NativeImage.scala
index 0ff85f3..41f06cb 100644
--- a/plugin/src/io/github/alexarchambault/millnativeimage/NativeImage.scala
+++ b/plugin/src/io/github/alexarchambault/millnativeimage/NativeImage.scala
@@ -356,12 +356,27 @@ object NativeImage {
def command(nativeImage: String, extraNativeImageArgs: Seq[String], destDir: Option[String], destName: String, classPath: String) = {
val destDirOptions = destDir.toList.map(d => s"-H:Path=$d")
+ val nativeConfigFile = os.temp(suffix = ".json")
+ os.write.over(
+ nativeConfigFile,
+ """[
+ | {
+ | "name": "sun.misc.Unsafe",
+ | "allDeclaredConstructors": true,
+ | "allPublicConstructors": true,
+ | "allDeclaredMethods": true,
+ | "allDeclaredFields": true
+ | }
+ |]
+ |""".stripMargin
+ )
Seq(nativeImage) ++
extraNativeImageArgs ++
nativeImageOptions ++
destDirOptions ++
Seq(
s"-H:Name=$destName",
+ s"-H:ReflectionConfigurationFiles=$nativeConfigFile",
"-cp",
classPath,
mainClass But something is still missing cause I'm getting:
Maybe @romanowski can give some tips :) |
Apparently it's not as trivial as I thought... from what I understood, scala-cli manipulates the bytecode to allow the unsafe declarations thru BytecodeProcessor and all... Maybe the plugin could import scala-cli and it would make things easier... dunno :) |
Yes, Scala CLI changes a bit implementation of lazy vals in Scala 3 so people does not need to apply config for each lazy val in their code (and all its dependencies). Lazy vals were reworked so it should be better in the future. As for the rewrites, we have an application in Scala CLI that changes the classpath that goes into graal native image generation. We publish it so sonatype so it should be possible to use it your build. |
Thanks a lot @romanowski ...
Maybe @alexarchambault have some pointer. |
Implemented in #20. |
This is solved by using Scala 3.3 which implements LazyVals correctly. |
I have a simple ZIO-http app and found-out that using scala-cli it can package the app with native image and it works fine.
Using the mill-native-image plugin, the binary fails with some LazyVal error... Dunno exactly what is different between both as the native-image options are the same.
The project sources are at: https://github.com/carlosedp/ziohttp
The mill project used scala-cli export function and I just added the plugin native image parameters.
To test it out, just clone the repo and run
nativepackage.sh
to use scala-cli (which worksfine). Using the plugin, runcd ziohttpproj && ./mill show ziohttp.nativeImage
, then run./out/ziohttp/nativeImage.dest/ziohttp.bin
. It fails with:Similar error Ref. scala/scala3#13985
The text was updated successfully, but these errors were encountered: