scalameta / sbt-native-image

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

Issues migrating from scala-native-packager #16

Open jakobmerrild opened 3 years ago

jakobmerrild commented 3 years ago

Describe the bug We're trying to use this plugin rather than scala-native-packager but native-image seems to exit unexpectedly.

After configuring the plugin with nativeImageOptions ++= List("--no-fallback") and running the nativeImage command it fails with the following output:

[info] /Users/<redacted>/Library/Caches/Coursier/jvm/graalvm-java11@20.2.0/Contents/Home/bin/native-image -cp /Users/<redacted>/git/nuclearfamly/famlyi18n/target/native-image-internal/manifest.jar --no-fallback co.famly.i18n.interpolations.I18nExtractor /Users/<redacted>/git/nuclearfamly/famlyi18n/target/native-image/famlyi18n
[/Users/<redacted>/git/nuclearfamly/famlyi18n/target/native-image/famlyi18n:71608]    classlist:  17,077.02 ms,  0.94 GB
[/Users/<redacted>/git/nuclearfamly/famlyi18n/target/native-image/famlyi18n:71608]        (cap):   4,654.91 ms,  0.94 GB
[/Users/<redacted>/git/nuclearfamly/famlyi18n/target/native-image/famlyi18n:71608]        setup:   7,259.70 ms,  0.94 GB
[/Users/<redacted>/git/nuclearfamly/famlyi18n/target/native-image/famlyi18n:71608]     analysis:  31,106.84 ms,  1.92 GB
Error: Classes that should be initialized at run time got initialized during image building:
 scala.collection.immutable.VM was unintentionally initialized at build time. To see why scala.collection.immutable.VM got initialized use -H:+TraceClassInitialization

Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
Error: Image build request failed with exit status 1
[error] native-image command failed with exit code '1'

Adding the -H:xxx options changes the output as follows:

Error: Classes that should be initialized at run time got initialized during image building:
 scala.collection.immutable.VM was unintentionally initialized at build time. scala.collection.immutable.VM has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try marking this class for build-time initialization with --initialize-at-build-time=scala.collection.immutable.VM

com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
 scala.collection.immutable.VM was unintentionally initialized at build time. scala.collection.immutable.VM has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try marking this class for build-time initialization with --initialize-at-build-time=scala.collection.immutable.VM

    at com.oracle.svm.core.util.UserError.abort(UserError.java:68)
    at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.checkDelayedInitialization(ConfigurableClassInitialization.java:526)
    at com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.duringAnalysis(ClassInitializationFeature.java:227)
    at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$8(NativeImageGenerator.java:732)
    at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:70)
    at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:732)
    at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:555)
    at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:468)
    at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1407)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Error: Image build request failed with exit status 1

Installation:

Search terms

Migrate, sbt-native-packager

ckipp01 commented 3 years ago

For what it's worth, I hit on this same issue as you today @kalanzai. I too went down the path of using -H:+ReportExceptionStackTraces, which then lead me to try "--initialize-at-build-time=scala.collection.immutable.VM" which brought other issues.

After seeing the convo here, and seeing that @olafurpg mentioned the issue for and the solution for 2.12.12+, I out of sheer curiosity tried it with 2.12.11, and all went well. I'd be curios if you switching to 2.12.11 would also fix what you're seeing.

I'm not fully sure why or how I can help track down this issue, but I'm happy to provide anything that might help @olafurpg. I can reproduce this fairly easy (with a bare moped project), but am unsure how to trace the root cause/issue.

OS: macOS Catalina 10.15.7 ScalaVersion: 2.12.12 (However, this works when I switch to 2.12.11) sbt: tried 1.3.13 and 1.4.x GraalVMVersion: 20.2.0 Java Version: both 8 and 11