Skip to content

Commit

Permalink
Make native-image generation work with any Scala version (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
olafurpg authored Sep 13, 2020
1 parent d3b3af1 commit 55487b0
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 4 deletions.
6 changes: 2 additions & 4 deletions plugin/src/main/scala/sbtnativeimage/NativeImagePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import sbt._
import sbt.plugins.JvmPlugin
import sbt.complete.DefaultParsers._
import java.nio.file.Paths
import scala.util.Try

object NativeImagePlugin extends AutoPlugin {
override def requires = JvmPlugin
Expand Down Expand Up @@ -79,10 +80,7 @@ object NativeImagePlugin extends AutoPlugin {
out.toFile
}
override lazy val projectSettings: Seq[Def.Setting[_]] = List(
libraryDependencies ++= {
if (scalaVersion.value.startsWith("2.11")) Nil
else List("org.scalameta" %% "svm-subs" % nativeImageVersion.value)
},
libraryDependencies += "org.scalameta" % "svm-subs" % "101.0.0",
target.in(NativeImage) :=
target.in(Compile).value / "native-image",
target.in(NativeImageInternal) :=
Expand Down
3 changes: 3 additions & 0 deletions plugin/src/sbt-test/sbt-native-image/cross-build/Prog.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Prog {
def main(args: Array[String]): Unit = println(List(1, 2, 3).toString)
}
15 changes: 15 additions & 0 deletions plugin/src/sbt-test/sbt-native-image/cross-build/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
enablePlugins(NativeImagePlugin)
nativeImageOptions += "--no-fallback"
crossScalaVersions := List(
"2.11.10",
"2.12.10",
"2.12.12",
"2.13.1",
"2.13.3"
)
mainClass.in(Compile) := Some("Prog")
TaskKey[Unit]("check") := {
val binary = nativeImage.value
val output = scala.sys.process.Process(List(binary.toString)).!!.trim
assert(output == "List(1, 2, 3)", s"obtained: $output")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package example

import java.nio.file.Files
import java.nio.file.Paths
import java.nio.charset.StandardCharsets

object Hello2 {
def main(args: Array[String]): Unit = {
val text = List(1, 2, 3).toString() + "\n"
Files.write(
Paths.get("hello2.obtained"),
text.getBytes(StandardCharsets.UTF_8)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.3.13
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("org.scalameta" % "sbt-native-image" % sys.props("plugin.version"))
1 change: 1 addition & 0 deletions plugin/src/sbt-test/sbt-native-image/cross-build/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> +check

0 comments on commit 55487b0

Please sign in to comment.