scalameta / sbt-native-image

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

simple example fails to build native image #12

Closed mtk closed 3 years ago

mtk commented 3 years ago

Describe the bug

An extremely simple example fails to generate a native executable.

To Reproduce Steps to reproduce the behavior:

create the following three files in an empty directory:

% cat build.sbt enablePlugins(NativeImagePlugin) mainClass.in(Compile) := Some("Prog") % cat Prog.scala object Prog { def main(args: Array[String]): Unit = println("hi!") } % cat project/build.properties sbt.version=1.3.13

start sbt and issue the 'nativeCompile' command:

% sbt [info] welcome to sbt 1.3.13 (Red Hat, Inc. Java 14.0.2) [info] loading settings for project global-plugins from sbt-native-packager.sbt,sbt-jmh.sbt,sbt-dotty.sbt,sbt-github-packages.sbt,sbt-scalafmt.sbt,sbt-coverage.sbt,sbt-missinglink.sbt,idea.sbt,sbt-native-image.sbt,sbt-metals.sbt,sbt-explicitDependences.sbt,sbt-updates.sbt,sbt-scalafix.sbt ... [info] loading global plugins from /home/mtk/.sbt/1.0/plugins [warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings. [info] loading project definition from /home/mtk/tmp/ni/project [warn] undefined keys githubOwner and githubRepository [warn] retaining pre-existing publication settings [warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings. [info] loading settings for project ni from build.sbt ... [info] set current project to ni (in build file:/home/mtk/tmp/ni/) [info] sbt server started at local:///home/mtk/.sbt/1.0/server/0b1762cb6463b64b1743/sock sbt:ni> nativeImage [warn] undefined keys githubOwner and githubRepository [warn] retaining pre-existing publication settings [info] Compiling 1 Scala source to /home/mtk/tmp/ni/target/scala-2.12/classes ... [info] /home/mtk/.cache/coursier/jvm/graalvm-java11@20.1.0/bin/native-image -cp /home/mtk/tmp/ni/target/native-image-internal/manifest.jar Prog /home/mtk/tmp/ni/target/native-image/ni Build on Server(pid: 255308, port: 33383)* [/home/mtk/tmp/ni/target/native-image/ni:255308] classlist: 5,418.49 ms, 0.96 GB [/home/mtk/tmp/ni/target/native-image/ni:255308] setup: 602.92 ms, 0.96 GB Error: substitution target for scala.meta.internal.svm_subs.Target_scala_runtime_Statics is not loaded. Use field onlyWith in the TargetClass annotation to make substitution only active when needed. 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' [error] (nativeImage) native-image command failed with exit code '1' [error] Total time: 10 s, completed Sep 12, 2020, 5:07:17 PM sbt:ni>

Expected behavior

a native image for the trivial program should have been created. or an error message that explains the problem in an understandable way?

Installation:

Additional context

the same result occurs if JDK 11 is used instead of 14.

olafurpg commented 3 years ago

Thank you for reporting! What happens if you add scalaVersion := "2.12.12" to your build.sbt file? I am able to reproduce with your build settings but I'm unable to reproduce with that setting added.

olafurpg commented 3 years ago

I opened #13 to make nativeImage work with any Scala version, including older versions like 2.12.10. A workaround is to use 2.12.12 in the meantime.

mtk commented 3 years ago

confirmed: works fine with 2.12.2! don't laugh, but that was exciting to see it work!