From f233a78b77373eb3ee29cf6f769174502e117bc1 Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Sun, 16 Jul 2023 17:17:50 +0400 Subject: [PATCH 01/10] Give some love to the project - Remove sbt 1.0.0 support - Update Scala version - Update sbt and sbt plugins - Remove deprecated sbt syntax usages - Update Scalafix and improve its configuration - Install Scala Steward to help us maintain this project - Fix Scalafix issues in code --- .github/workflows/scala-steward.yml | 16 +++ .scalafix.conf | 25 ++++- build.sbt | 14 +-- .../sbtnativeimage/NativeImagePlugin.scala | 100 +++++++++--------- project/build.properties | 2 +- project/plugins.sbt | 16 +-- 6 files changed, 108 insertions(+), 65 deletions(-) create mode 100644 .github/workflows/scala-steward.yml diff --git a/.github/workflows/scala-steward.yml b/.github/workflows/scala-steward.yml new file mode 100644 index 0000000..83edb99 --- /dev/null +++ b/.github/workflows/scala-steward.yml @@ -0,0 +1,16 @@ +name: Scala Steward + +# This workflow will launch everyday at 00:00 +on: + schedule: + - cron: '0 0 * * *' + workflow_dispatch: {} + +jobs: + scala-steward: + timeout-minutes: 30 + runs-on: ubuntu-latest + name: Scala Steward + steps: + - name: Scala Steward + uses: scala-steward-org/scala-steward-action@v2.59.0 diff --git a/.scalafix.conf b/.scalafix.conf index b6b7aab..84a4444 100644 --- a/.scalafix.conf +++ b/.scalafix.conf @@ -1,7 +1,30 @@ rules = [ - OrganizeImports, + DisableSyntax + ExplicitResultTypes + LeakingImplicitClassVal + NoAutoTupling + NoValInForComprehension + ProcedureSyntax + RemoveUnused + OrganizeImports ] +RemoveUnused { + imports = false // See https://github.com/scalacenter/scalafix/blob/v0.11.0/docs/rules/OrganizeImports.md#configuration +} + +Disable { + ifSynthetic = [ + "scala/Option.option2Iterable" + "scala/Predef.any2stringadd" + ] +} + +DisableSyntax.noReturns = true +DisableSyntax.noXml = true +DisableSyntax.noFinalize = true +DisableSyntax.noValPatterns = true + ExplicitResultTypes.rewriteStructuralTypesToNamedSubclass = false OrganizeImports.groupedImports = Explode diff --git a/build.sbt b/build.sbt index c8a40c7..35079c8 100644 --- a/build.sbt +++ b/build.sbt @@ -1,4 +1,7 @@ -def scala212 = "2.12.12" +def scala212 = "2.12.18" + +Global / onChangedBuildSource := ReloadOnSourceChanges + inThisBuild( List( organization := "org.scalameta", @@ -15,8 +18,6 @@ inThisBuild( ) ), scalaVersion := scala212, - scalafixDependencies += - "com.github.liancheng" %% "organize-imports" % "0.5.0", scalacOptions ++= List("-Ywarn-unused-import"), scalafixCaching := true, semanticdbEnabled := true @@ -24,7 +25,7 @@ inThisBuild( ) crossScalaVersions := Nil -skip.in(publish) := true +publish / skip := true commands += Command.command("fixAll") { s => @@ -42,7 +43,6 @@ lazy val plugin = project .settings( moduleName := "sbt-native-image", sbtPlugin := true, - sbtVersion.in(pluginCrossBuild) := "1.0.0", crossScalaVersions := List(scala212), buildInfoPackage := "sbtnativeimage", buildInfoKeys := Seq[BuildInfoKey](version), @@ -55,8 +55,8 @@ lazy val plugin = project lazy val example = project .in(file("example")) .settings( - skip.in(publish) := true, - mainClass.in(Compile) := Some("example.Hello"), + publish / skip := true, + Compile / mainClass := Some("example.Hello"), test := { val binary = nativeImage.value val output = scala.sys.process.Process(List(binary.toString)).!!.trim diff --git a/plugin/src/main/scala/sbtnativeimage/NativeImagePlugin.scala b/plugin/src/main/scala/sbtnativeimage/NativeImagePlugin.scala index 815cfb9..7bc5c68 100644 --- a/plugin/src/main/scala/sbtnativeimage/NativeImagePlugin.scala +++ b/plugin/src/main/scala/sbtnativeimage/NativeImagePlugin.scala @@ -140,12 +140,14 @@ object NativeImagePlugin extends AutoPlugin { override lazy val projectSettings: Seq[Def.Setting[_]] = List( libraryDependencies += "org.scalameta" % "svm-subs" % "101.0.0", - target.in(NativeImage) := target.in(Compile).value / "native-image", - target.in(NativeImageTest) := target.in(Test).value / "native-image-test", - target.in(NativeImageInternal) := - target.in(Compile).value / "native-image-internal", - target.in(NativeImageTestInternal) := - target.in(Test).value / "native-image-test-internal", + NativeImage / target := + (Compile / target).value / "native-image", + NativeImageTest / target := + (Test / target).value / "native-image-test", + NativeImageInternal / target := + (Compile / target).value / "native-image-internal", + NativeImageTestInternal / target := + (Test / target).value / "native-image-test-internal", nativeImageReady := { val s = streams.value @@ -163,15 +165,18 @@ object NativeImagePlugin extends AutoPlugin { nativeImageJvm := "graalvm-java11", nativeImageJvmIndex := "cs", nativeImageVersion := "20.2.0", - name.in(NativeImage) := name.value, - name.in(NativeImageTest) := name.in(Test).value, - mainClass.in(NativeImage) := mainClass.in(Compile).value, - mainClass.in(NativeImageTest) := mainClass.in(Test).value, - nativeImageOptions := List(), + NativeImage / name := name.value, + NativeImageTest / name := + (Test / name).value, + NativeImage / mainClass := + (Compile / mainClass).value, + NativeImageTest / mainClass := + (Test / mainClass).value, + nativeImageOptions := List.empty, nativeImageTestOptions := nativeImageOptions.value, - nativeImageTestRunOptions := List(), + nativeImageTestRunOptions := List.empty, nativeImageCoursier := { - val dir = target.in(NativeImageInternal).value + val dir = (NativeImageInternal / target).value val out = copyResource("coursier", dir) if (Properties.isWin) { copyResource("coursier.bat", dir) @@ -282,9 +287,9 @@ object NativeImagePlugin extends AutoPlugin { s"-agentlib:native-image-agent=$agentConfig=${nativeImageAgentOutputDir.value}" val tpr = thisProjectRef.value val settings = Seq( - fork in (tpr, Compile, run) := true, - javaHome in (tpr, Compile, run) := Some(graalHome), - javaOptions in (tpr, Compile, run) += agentOption + tpr / Compile / run / fork := true, + tpr / Compile / run / javaHome := Some(graalHome), + tpr / Compile / run / javaOptions += agentOption ) val state0 = state.value val extracted = Project.extract(state0) @@ -297,7 +302,7 @@ object NativeImagePlugin extends AutoPlugin { arguments.mkString(" ") Project .extract(newState) - .runInputTask(run in (tpr, Compile), input, newState) + .runInputTask(tpr / Compile / run, input, newState) }, nativeImageTestRunAgent := { val _ = nativeImageTestCommand.value @@ -311,12 +316,12 @@ object NativeImagePlugin extends AutoPlugin { val agentOption = s"-agentlib:native-image-agent=$agentConfig=${nativeImageTestAgentOutputDir.value}" - val options = (javaOptions in (Test, run)).value ++ Seq(agentOption) + val options = (Test / run / javaOptions).value ++ Seq(agentOption) - val __ = compile.in(Test).value - val main = mainClass.in(NativeImageTest).value - val cp = fullClasspath.in(Test).value.map(_.data) - val manifest = target.in(NativeImageTestInternal).value / "manifest.jar" + val __ = (Test / compile).value + val main = (NativeImageTest / mainClass).value + val cp = (Test / fullClasspath).value.map(_.data) + val manifest = (NativeImageTestInternal / target).value / "manifest.jar" manifest.getParentFile().mkdirs() createManifestJar(manifest, cp) val nativeClasspath = manifest.absolutePath @@ -331,7 +336,7 @@ object NativeImagePlugin extends AutoPlugin { throw new MessageOnlyException( "no mainClass is specified for tests. " + "To fix this problem, update build.sbt to include the settings " + - "`mainClass.in(Test) := Some(\"com.MainTestClass\")`" + "`Test / mainClass := Some(\"com.MainTestClass\")`" ) ) command ++= nativeImageTestRunOptions.value @@ -344,12 +349,12 @@ object NativeImagePlugin extends AutoPlugin { } }, nativeImageOutput := - target.in(NativeImage).value / name.in(NativeImage).value, + (NativeImage / target).value / (NativeImage / name).value, nativeImageTestOutput := - target.in(NativeImageTest).value / name.in(NativeImageTest).value, + (NativeImageTest / target).value / (NativeImageTest / name).value, nativeImageCopy := { val binary = nativeImage.value - val out = fileParser(baseDirectory.in(ThisBuild).value).parsed + val out = fileParser((ThisBuild / baseDirectory).value).parsed Files.copy( binary.toPath(), out.toPath(), @@ -384,17 +389,17 @@ object NativeImagePlugin extends AutoPlugin { } }, nativeImage := { - val _ = compile.in(Compile).value - val main = mainClass.in(NativeImage).value + val _ = (Compile / compile).value + val main = (NativeImage / mainClass).value val binaryName = nativeImageOutput.value - val cp = fullClasspath.in(Compile).value.map(_.data) + val cp = (Compile / fullClasspath).value.map(_.data) // NOTE(olafur): we pass in a manifest jar instead of the full classpath // for two reasons: // * large classpaths quickly hit on the "argument list too large" // error, especially on Windows. // * we print the full command to the console and the manifest jar makes // it more readable and easier to copy-paste. - val manifest = target.in(NativeImageInternal).value / "manifest.jar" + val manifest = (NativeImageInternal / target).value / "manifest.jar" manifest.getParentFile().mkdirs() createManifestJar(manifest, cp) val nativeClasspath = manifest.absolutePath @@ -410,14 +415,14 @@ object NativeImagePlugin extends AutoPlugin { throw new MessageOnlyException( "no mainClass is specified. " + "To fix this problem, update build.sbt to include the settings " + - "`mainClass.in(Compile) := Some(\"com.MainClass\")`" + "`Compile / mainClass := Some(\"com.MainClass\")`" ) ) command += binaryName.absolutePath // Start native-image linker. streams.value.log.info(command.mkString(" ")) - val cwd = target.in(NativeImage).value + val cwd = (NativeImage / target).value cwd.mkdirs() val exit = Process(command, cwd = Some(cwd)).! if (exit != 0) { @@ -431,17 +436,17 @@ object NativeImagePlugin extends AutoPlugin { binaryName }, nativeImageTest := { - val _ = compile.in(Test).value - val main = mainClass.in(NativeImageTest).value + val _ = (Test / compile).value + val main = (NativeImageTest / mainClass).value val binaryName = nativeImageTestOutput.value - val cp = fullClasspath.in(Test).value.map(_.data) + val cp = (Test / fullClasspath).value.map(_.data) // NOTE(olafur): we pass in a manifest jar instead of the full classpath // for two reasons: // * large classpaths quickly hit on the "argument list too large" // error, especially on Windows. // * we print the full command to the console and the manifest jar makes // it more readable and easier to copy-paste. - val manifest = target.in(NativeImageTestInternal).value / "manifest.jar" + val manifest = (NativeImageTestInternal / target).value / "manifest.jar" manifest.getParentFile().mkdirs() createManifestJar(manifest, cp) val nativeClasspath = manifest.absolutePath @@ -457,14 +462,14 @@ object NativeImagePlugin extends AutoPlugin { throw new MessageOnlyException( "no mainClass is specified for tests. " + "To fix this problem, update build.sbt to include the settings " + - "`mainClass.in(Test) := Some(\"com.MainTestClass\")`" + "`Test / mainClass := Some(\"com.MainTestClass\")`" ) ) command += binaryName.absolutePath // Start native-image linker. streams.value.log.info(command.mkString(" ")) - val cwd = target.in(NativeImageTest).value + val cwd = (NativeImageTest / target).value cwd.mkdirs() val exit = Process(command, cwd = Some(cwd)).! if (exit != 0) { @@ -519,8 +524,7 @@ object NativeImagePlugin extends AutoPlugin { //this happens if the dependency jar resides on a different drive then the manifest, i.e. C:\Coursier\Cache and D:\myapp\target //copy dependency next to manifest as fallback case _: IllegalArgumentException => - import java.nio.file.Files - import java.nio.file.StandardCopyOption + import java.nio.file.{Files, StandardCopyOption} Files.copy( dependencyPath, manifestPath.resolve(path.getName), @@ -546,15 +550,15 @@ object NativeImagePlugin extends AutoPlugin { private def alertUser(streams: std.TaskStreams[_], message: String): Unit = { streams.log.info(message) - if (isCI) - return - try { - if (Properties.isMac) { - Process(List("say", message)).! + if (!isCI) { + try { + if (Properties.isMac) { + Process(List("say", message)).! + } + // NOTE(olafur): feel free to add support for Linux/Windows. + } catch { + case NonFatal(_) => } - // NOTE(olafur): feel free to add support for Linux/Windows. - } catch { - case NonFatal(_) => } } } diff --git a/project/build.properties b/project/build.properties index 7de0a93..875b706 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.4.4 +sbt.version=1.9.2 diff --git a/project/plugins.sbt b/project/plugins.sbt index 96148c6..ce65de8 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,13 +1,13 @@ -addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.11") -addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.4") -addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.27") +addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12") +addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.0") libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value -unmanagedSourceDirectories.in(Compile) += - baseDirectory.in(ThisBuild).value.getParentFile / "plugin" / "src" / "main" / +Compile / unmanagedSourceDirectories += + (ThisBuild / baseDirectory).value.getParentFile / "plugin" / "src" / "main" / "scala" -unmanagedResourceDirectories.in(Compile) += - baseDirectory.in(ThisBuild).value.getParentFile / "plugin" / "src" / "main" / +Compile / unmanagedResourceDirectories += + (ThisBuild / baseDirectory).value.getParentFile / "plugin" / "src" / "main" / "resources" From a177ab52845d088572106935a61ecf680079d129 Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Sun, 16 Jul 2023 18:15:13 +0400 Subject: [PATCH 02/10] try to avoid CI failures --- .github/workflows/ci.yml | 5 +++++ .github/workflows/native.yml | 5 +++++ .jvmopts-ci | 6 ++++++ 3 files changed, 16 insertions(+) create mode 100644 .jvmopts-ci diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a36d17f..4bc39ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,6 +19,11 @@ jobs: - uses: olafurpg/setup-scala@v13 with: java-version: "adopt@1.${{ matrix.java }}" + - name: Use CI sbt jvmopts + shell: bash + run: | + mv .jvmopts-ci .jvmopts + cat .jvmopts - name: Setup Windows C++ toolchain uses: ilammy/msvc-dev-cmd@v1 if: ${{ matrix.os == 'windows-latest' }} diff --git a/.github/workflows/native.yml b/.github/workflows/native.yml index 6a91c92..f0486aa 100644 --- a/.github/workflows/native.yml +++ b/.github/workflows/native.yml @@ -37,6 +37,11 @@ jobs: distribution: temurin java-version: 8 cache: sbt + - name: Use CI sbt jvmopts + shell: bash + run: | + mv .jvmopts-ci .jvmopts + cat .jvmopts - run: git fetch --tags || true - name: Setup Windows C++ toolchain uses: ilammy/msvc-dev-cmd@v1 diff --git a/.jvmopts-ci b/.jvmopts-ci new file mode 100644 index 0000000..0f24832 --- /dev/null +++ b/.jvmopts-ci @@ -0,0 +1,6 @@ +-Xss4m +-Xms5G +-Xmx5G +-XX:ReservedCodeCacheSize=1024m +-XX:+TieredCompilation +-Dfile.encoding=UTF-8 From 1d5f26b252c657df571dc61cf1f62b70cc2dd29e Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Sun, 16 Jul 2023 18:22:26 +0400 Subject: [PATCH 03/10] Update example projects --- .../sbt-test/sbt-native-image/agent-test/build.sbt | 10 +++++----- plugin/src/sbt-test/sbt-native-image/agent/build.sbt | 4 ++-- .../sbt-test/sbt-native-image/basic-test/build.sbt | 10 +++++----- plugin/src/sbt-test/sbt-native-image/basic/build.sbt | 4 ++-- .../sbt-native-image/cross-build-test/build.sbt | 12 ++++++------ .../sbt-test/sbt-native-image/cross-build/build.sbt | 6 +++--- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/plugin/src/sbt-test/sbt-native-image/agent-test/build.sbt b/plugin/src/sbt-test/sbt-native-image/agent-test/build.sbt index 5dfbfaa..6df953d 100644 --- a/plugin/src/sbt-test/sbt-native-image/agent-test/build.sbt +++ b/plugin/src/sbt-test/sbt-native-image/agent-test/build.sbt @@ -1,13 +1,13 @@ lazy val example = project .settings( - scalaVersion := "2.12.12", - mainClass.in(Compile) := Some("example.Hello6"), + scalaVersion := "2.12.18", + Compile / mainClass := Some("example.Hello6"), nativeImageTestOptions ++= Seq( s"-H:ReflectionConfigurationFiles=${target.value / "native-image-configs" / "reflect-config.json"}", "--initialize-at-build-time=scala.collection.immutable.VM", ), - mainClass.in(Test) := Some("org.scalatest.tools.Runner"), - nativeImageTestRunOptions ++= Seq("-o", "-R", classDirectory.in(Test).value.absolutePath), + Test / mainClass := Some("org.scalatest.tools.Runner"), + nativeImageTestRunOptions ++= Seq("-o", "-R", (Test / classDirectory).value.absolutePath), nativeImageCommand := List( sys.env.getOrElse( "NATIVE_IMAGE_COMMAND", @@ -16,6 +16,6 @@ lazy val example = project "variable to point to the absolute path of this binary." ) ), - libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.14" % "test" + libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.16" % Test ) .enablePlugins(NativeImagePlugin) diff --git a/plugin/src/sbt-test/sbt-native-image/agent/build.sbt b/plugin/src/sbt-test/sbt-native-image/agent/build.sbt index 92426de..8906550 100644 --- a/plugin/src/sbt-test/sbt-native-image/agent/build.sbt +++ b/plugin/src/sbt-test/sbt-native-image/agent/build.sbt @@ -1,7 +1,7 @@ lazy val example = project .settings( - scalaVersion := "2.12.12", - mainClass.in(Compile) := Some("example.Hello3"), + scalaVersion := "2.12.18", + Compile / mainClass := Some("example.Hello3"), nativeImageOptions ++= Seq( "--no-fallback", s"-H:ReflectionConfigurationFiles=${ target.value / "native-image-configs" / "reflect-config.json" }" diff --git a/plugin/src/sbt-test/sbt-native-image/basic-test/build.sbt b/plugin/src/sbt-test/sbt-native-image/basic-test/build.sbt index a310d29..8f471d7 100644 --- a/plugin/src/sbt-test/sbt-native-image/basic-test/build.sbt +++ b/plugin/src/sbt-test/sbt-native-image/basic-test/build.sbt @@ -1,7 +1,7 @@ lazy val example = project .settings( - scalaVersion := "2.12.12", - mainClass.in(Compile) := Some("example.Hello4"), + scalaVersion := "2.12.18", + Compile / mainClass := Some("example.Hello4"), nativeImageCommand := List( sys.env.getOrElse( "NATIVE_IMAGE_COMMAND", @@ -13,8 +13,8 @@ lazy val example = project nativeImageTestOptions ++= Seq( "--initialize-at-build-time=scala.collection.immutable.VM" ), - mainClass.in(Test) := Some("org.scalatest.tools.Runner"), - nativeImageTestRunOptions ++= Seq("-o", "-R", classDirectory.in(Test).value.absolutePath), - libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.14" % "test" + Test / mainClass := Some("org.scalatest.tools.Runner"), + nativeImageTestRunOptions ++= Seq("-o", "-R", (Test / classDirectory).value.absolutePath), + libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.16" % Test ) .enablePlugins(NativeImagePlugin) diff --git a/plugin/src/sbt-test/sbt-native-image/basic/build.sbt b/plugin/src/sbt-test/sbt-native-image/basic/build.sbt index e816d89..12d0b43 100644 --- a/plugin/src/sbt-test/sbt-native-image/basic/build.sbt +++ b/plugin/src/sbt-test/sbt-native-image/basic/build.sbt @@ -1,7 +1,7 @@ lazy val example = project .settings( - scalaVersion := "2.12.12", - mainClass.in(Compile) := Some("example.Hello2"), + scalaVersion := "2.12.18", + Compile / mainClass := Some("example.Hello2"), nativeImageCommand := List( sys.env.getOrElse( "NATIVE_IMAGE_COMMAND", diff --git a/plugin/src/sbt-test/sbt-native-image/cross-build-test/build.sbt b/plugin/src/sbt-test/sbt-native-image/cross-build-test/build.sbt index ceb6292..2f0bf6e 100644 --- a/plugin/src/sbt-test/sbt-native-image/cross-build-test/build.sbt +++ b/plugin/src/sbt-test/sbt-native-image/cross-build-test/build.sbt @@ -3,16 +3,16 @@ lazy val example = project crossScalaVersions := List( "2.11.10", "2.12.10", - "2.12.12", + "2.12.18", "2.13.1", - "2.13.3" + "2.13.11" ), - mainClass.in(Compile) := Some("example.Hello5"), + Compile / mainClass := Some("example.Hello5"), nativeImageTestOptions ++= Seq( "--initialize-at-build-time=scala.collection.immutable.VM" ), - mainClass.in(Test) := Some("org.scalatest.tools.Runner"), - nativeImageTestRunOptions ++= Seq("-o", "-R", classDirectory.in(Test).value.absolutePath), + Test / mainClass := Some("org.scalatest.tools.Runner"), + nativeImageTestRunOptions ++= Seq("-o", "-R", (Test / classDirectory).value.absolutePath), nativeImageCommand := List( sys.env.getOrElse( "NATIVE_IMAGE_COMMAND", @@ -21,6 +21,6 @@ lazy val example = project "variable to point to the absolute path of this binary." ) ), - libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.14" % "test" + libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.16" % Test ) .enablePlugins(NativeImagePlugin) diff --git a/plugin/src/sbt-test/sbt-native-image/cross-build/build.sbt b/plugin/src/sbt-test/sbt-native-image/cross-build/build.sbt index ceecc41..02c1957 100644 --- a/plugin/src/sbt-test/sbt-native-image/cross-build/build.sbt +++ b/plugin/src/sbt-test/sbt-native-image/cross-build/build.sbt @@ -3,11 +3,11 @@ nativeImageOptions += "--no-fallback" crossScalaVersions := List( "2.11.10", "2.12.10", - "2.12.12", + "2.12.18", "2.13.1", - "2.13.3" + "2.13.11" ) -mainClass.in(Compile) := Some("Prog") +Compile / mainClass := Some("Prog") TaskKey[Unit]("check") := { val binary = nativeImage.value val output = scala.sys.process.Process(List(binary.toString)).!!.trim From 4ba6939b99451239860a0b6364c8f09a04ebbdc7 Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Sun, 16 Jul 2023 18:38:26 +0400 Subject: [PATCH 04/10] clean --- .github/workflows/ci.yml | 5 ----- .github/workflows/native.yml | 5 ----- .jvmopts-ci | 6 ------ 3 files changed, 16 deletions(-) delete mode 100644 .jvmopts-ci diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4bc39ea..a36d17f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,11 +19,6 @@ jobs: - uses: olafurpg/setup-scala@v13 with: java-version: "adopt@1.${{ matrix.java }}" - - name: Use CI sbt jvmopts - shell: bash - run: | - mv .jvmopts-ci .jvmopts - cat .jvmopts - name: Setup Windows C++ toolchain uses: ilammy/msvc-dev-cmd@v1 if: ${{ matrix.os == 'windows-latest' }} diff --git a/.github/workflows/native.yml b/.github/workflows/native.yml index f0486aa..6a91c92 100644 --- a/.github/workflows/native.yml +++ b/.github/workflows/native.yml @@ -37,11 +37,6 @@ jobs: distribution: temurin java-version: 8 cache: sbt - - name: Use CI sbt jvmopts - shell: bash - run: | - mv .jvmopts-ci .jvmopts - cat .jvmopts - run: git fetch --tags || true - name: Setup Windows C++ toolchain uses: ilammy/msvc-dev-cmd@v1 diff --git a/.jvmopts-ci b/.jvmopts-ci deleted file mode 100644 index 0f24832..0000000 --- a/.jvmopts-ci +++ /dev/null @@ -1,6 +0,0 @@ --Xss4m --Xms5G --Xmx5G --XX:ReservedCodeCacheSize=1024m --XX:+TieredCompilation --Dfile.encoding=UTF-8 From f8cee7ad2cd0b5200075602553960e8b4e821314 Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Sun, 16 Jul 2023 18:59:04 +0400 Subject: [PATCH 05/10] Try fix scripted tests --- plugin/src/sbt-test/sbt-native-image/cross-build-test/build.sbt | 2 +- .../sbt-native-image/cross-build-test/project/build.properties | 1 - plugin/src/sbt-test/sbt-native-image/cross-build/build.sbt | 2 +- .../sbt-native-image/cross-build/project/build.properties | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) delete mode 100644 plugin/src/sbt-test/sbt-native-image/cross-build-test/project/build.properties delete mode 100644 plugin/src/sbt-test/sbt-native-image/cross-build/project/build.properties diff --git a/plugin/src/sbt-test/sbt-native-image/cross-build-test/build.sbt b/plugin/src/sbt-test/sbt-native-image/cross-build-test/build.sbt index 2f0bf6e..f1bf403 100644 --- a/plugin/src/sbt-test/sbt-native-image/cross-build-test/build.sbt +++ b/plugin/src/sbt-test/sbt-native-image/cross-build-test/build.sbt @@ -1,7 +1,7 @@ lazy val example = project .settings( crossScalaVersions := List( - "2.11.10", + "2.11.12", "2.12.10", "2.12.18", "2.13.1", diff --git a/plugin/src/sbt-test/sbt-native-image/cross-build-test/project/build.properties b/plugin/src/sbt-test/sbt-native-image/cross-build-test/project/build.properties deleted file mode 100644 index 0837f7a..0000000 --- a/plugin/src/sbt-test/sbt-native-image/cross-build-test/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.3.13 diff --git a/plugin/src/sbt-test/sbt-native-image/cross-build/build.sbt b/plugin/src/sbt-test/sbt-native-image/cross-build/build.sbt index 02c1957..f521f1c 100644 --- a/plugin/src/sbt-test/sbt-native-image/cross-build/build.sbt +++ b/plugin/src/sbt-test/sbt-native-image/cross-build/build.sbt @@ -1,7 +1,7 @@ enablePlugins(NativeImagePlugin) nativeImageOptions += "--no-fallback" crossScalaVersions := List( - "2.11.10", + "2.11.12", "2.12.10", "2.12.18", "2.13.1", diff --git a/plugin/src/sbt-test/sbt-native-image/cross-build/project/build.properties b/plugin/src/sbt-test/sbt-native-image/cross-build/project/build.properties deleted file mode 100644 index 0837f7a..0000000 --- a/plugin/src/sbt-test/sbt-native-image/cross-build/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.3.13 From 7f29c8e2a9848f2b5b53e15e0e383ffcb3e7cf86 Mon Sep 17 00:00:00 2001 From: Chris Kipp Date: Tue, 18 Jul 2023 11:26:05 +0200 Subject: [PATCH 06/10] deps: bump default nativeImageVersion to 22.3.0 This also bumps some stuff in the CI, even though we'll rip it out after. --- .github/workflows/ci.yml | 6 +++--- .../src/main/scala/sbtnativeimage/NativeImagePlugin.scala | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a36d17f..747eb9e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false matrix: os: [macOS-latest, ubuntu-latest, windows-latest] - java: [8] + java: [11] steps: - uses: actions/checkout@v3 - uses: olafurpg/setup-scala@v13 @@ -27,8 +27,8 @@ jobs: shell: bash run: | export JABBA=/home/runner/bin/jabba - $JABBA install graalvm@20.2.0 - export GRAALVM_HOME=$($JABBA which --home graalvm@20.2.0) + $JABBA install graalvm@22.3.0 + export GRAALVM_HOME=$($JABBA which --home graalvm@22.3.0) $GRAALVM_HOME/bin/gu install native-image export NATIVE_IMAGE_COMMAND=$GRAALVM_HOME/bin/native-image sbt test plugin/scripted diff --git a/plugin/src/main/scala/sbtnativeimage/NativeImagePlugin.scala b/plugin/src/main/scala/sbtnativeimage/NativeImagePlugin.scala index 7bc5c68..5bb4ed2 100644 --- a/plugin/src/main/scala/sbtnativeimage/NativeImagePlugin.scala +++ b/plugin/src/main/scala/sbtnativeimage/NativeImagePlugin.scala @@ -164,7 +164,7 @@ object NativeImagePlugin extends AutoPlugin { }, nativeImageJvm := "graalvm-java11", nativeImageJvmIndex := "cs", - nativeImageVersion := "20.2.0", + nativeImageVersion := "22.3.0", NativeImage / name := name.value, NativeImageTest / name := (Test / name).value, From 8a0cb20c4fb483d4e4652acacb28e64a811fe2aa Mon Sep 17 00:00:00 2001 From: Chris Kipp Date: Wed, 19 Jul 2023 11:11:02 +0200 Subject: [PATCH 07/10] refactor: update tests to use 2.13.11 --- plugin/src/sbt-test/sbt-native-image/agent-test/build.sbt | 2 +- plugin/src/sbt-test/sbt-native-image/agent/build.sbt | 2 +- plugin/src/sbt-test/sbt-native-image/basic-test/build.sbt | 2 +- plugin/src/sbt-test/sbt-native-image/basic/build.sbt | 2 +- .../sbt-test/sbt-native-image/basic/project/build.properties | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 plugin/src/sbt-test/sbt-native-image/basic/project/build.properties diff --git a/plugin/src/sbt-test/sbt-native-image/agent-test/build.sbt b/plugin/src/sbt-test/sbt-native-image/agent-test/build.sbt index 6df953d..028fe09 100644 --- a/plugin/src/sbt-test/sbt-native-image/agent-test/build.sbt +++ b/plugin/src/sbt-test/sbt-native-image/agent-test/build.sbt @@ -1,6 +1,6 @@ lazy val example = project .settings( - scalaVersion := "2.12.18", + scalaVersion := "2.13.11", Compile / mainClass := Some("example.Hello6"), nativeImageTestOptions ++= Seq( s"-H:ReflectionConfigurationFiles=${target.value / "native-image-configs" / "reflect-config.json"}", diff --git a/plugin/src/sbt-test/sbt-native-image/agent/build.sbt b/plugin/src/sbt-test/sbt-native-image/agent/build.sbt index 8906550..0a61b63 100644 --- a/plugin/src/sbt-test/sbt-native-image/agent/build.sbt +++ b/plugin/src/sbt-test/sbt-native-image/agent/build.sbt @@ -1,6 +1,6 @@ lazy val example = project .settings( - scalaVersion := "2.12.18", + scalaVersion := "2.13.11", Compile / mainClass := Some("example.Hello3"), nativeImageOptions ++= Seq( "--no-fallback", diff --git a/plugin/src/sbt-test/sbt-native-image/basic-test/build.sbt b/plugin/src/sbt-test/sbt-native-image/basic-test/build.sbt index 8f471d7..197baa1 100644 --- a/plugin/src/sbt-test/sbt-native-image/basic-test/build.sbt +++ b/plugin/src/sbt-test/sbt-native-image/basic-test/build.sbt @@ -1,6 +1,6 @@ lazy val example = project .settings( - scalaVersion := "2.12.18", + scalaVersion := "2.13.11", Compile / mainClass := Some("example.Hello4"), nativeImageCommand := List( sys.env.getOrElse( diff --git a/plugin/src/sbt-test/sbt-native-image/basic/build.sbt b/plugin/src/sbt-test/sbt-native-image/basic/build.sbt index 12d0b43..7835ec8 100644 --- a/plugin/src/sbt-test/sbt-native-image/basic/build.sbt +++ b/plugin/src/sbt-test/sbt-native-image/basic/build.sbt @@ -1,6 +1,6 @@ lazy val example = project .settings( - scalaVersion := "2.12.18", + scalaVersion := "2.13.11", Compile / mainClass := Some("example.Hello2"), nativeImageCommand := List( sys.env.getOrElse( diff --git a/plugin/src/sbt-test/sbt-native-image/basic/project/build.properties b/plugin/src/sbt-test/sbt-native-image/basic/project/build.properties new file mode 100644 index 0000000..875b706 --- /dev/null +++ b/plugin/src/sbt-test/sbt-native-image/basic/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.9.2 From e8bfe1d465492020ecdb63e336dc3a731fe20b98 Mon Sep 17 00:00:00 2001 From: Chris Kipp Date: Wed, 19 Jul 2023 11:11:36 +0200 Subject: [PATCH 08/10] refactor: remove local scala-steward config We'll use the org one instead --- .github/workflows/scala-steward.yml | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 .github/workflows/scala-steward.yml diff --git a/.github/workflows/scala-steward.yml b/.github/workflows/scala-steward.yml deleted file mode 100644 index 83edb99..0000000 --- a/.github/workflows/scala-steward.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Scala Steward - -# This workflow will launch everyday at 00:00 -on: - schedule: - - cron: '0 0 * * *' - workflow_dispatch: {} - -jobs: - scala-steward: - timeout-minutes: 30 - runs-on: ubuntu-latest - name: Scala Steward - steps: - - name: Scala Steward - uses: scala-steward-org/scala-steward-action@v2.59.0 From 101b85e4897dbb2ae0c35db2266eba9ea1022b33 Mon Sep 17 00:00:00 2001 From: Chris Kipp Date: Wed, 19 Jul 2023 11:20:55 +0200 Subject: [PATCH 09/10] refactor: start using setup-graal --- .github/workflows/ci.yml | 48 +++++++++++++++++++++--------------- .github/workflows/native.yml | 8 +++++- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 747eb9e..e94bf06 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,9 +2,9 @@ name: CI on: push: branches: - - master - main pull_request: + jobs: native-image: name: Compile @@ -13,33 +13,41 @@ jobs: fail-fast: false matrix: os: [macOS-latest, ubuntu-latest, windows-latest] - java: [11] + java: ['17.0.7'] + steps: - uses: actions/checkout@v3 - - uses: olafurpg/setup-scala@v13 + - uses: graalvm/setup-graalvm@v1 with: - java-version: "adopt@1.${{ matrix.java }}" - - name: Setup Windows C++ toolchain - uses: ilammy/msvc-dev-cmd@v1 - if: ${{ matrix.os == 'windows-latest' }} + java-version: ${{ matrix.java }} + cache: sbt + components: native-image + - name: sbt test plugin/scripted - if: ${{ matrix.os == 'ubuntu-latest' }} - shell: bash + if: ${{ matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' }} + env: + NATIVE_IMAGE_COMMAND: native-image run: | - export JABBA=/home/runner/bin/jabba - $JABBA install graalvm@22.3.0 - export GRAALVM_HOME=$($JABBA which --home graalvm@22.3.0) - $GRAALVM_HOME/bin/gu install native-image - export NATIVE_IMAGE_COMMAND=$GRAALVM_HOME/bin/native-image + # Copied from https://github.com/graalvm/setup-graalvm#quickstart-template + echo "GRAALVM_HOME: $GRAALVM_HOME" + echo "JAVA_HOME: $JAVA_HOME" + java --version + native-image --version sbt test plugin/scripted - - name: sbt test - shell: bash - if: ${{ matrix.os == 'windows-latest' }} - run: | - sbt example/nativeImage + + # - name: sbt test + # shell: bash + # if: ${{ matrix.os == 'windows-latest' }} + # run: | + # sbt example/nativeImage + check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: olafurpg/setup-scala@v13 + - uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + cache: 'sbt' - run: sbt checkAll diff --git a/.github/workflows/native.yml b/.github/workflows/native.yml index 6a91c92..4347114 100644 --- a/.github/workflows/native.yml +++ b/.github/workflows/native.yml @@ -2,11 +2,11 @@ name: Native Image on: push: branches: - - master - main pull_request: release: types: [published] + jobs: native-image: runs-on: ${{ matrix.os }} @@ -29,6 +29,7 @@ jobs: # define Java options for both official sbt and sbt-extras JAVA_OPTS: -Xms2048M -Xmx2048M -Xss6M -XX:ReservedCodeCacheSize=256M -Dfile.encoding=UTF-8 JVM_OPTS: -Xms2048M -Xmx2048M -Xss6M -XX:ReservedCodeCacheSize=256M -Dfile.encoding=UTF-8 + steps: - uses: actions/checkout@v3 - name: Setup JDK @@ -37,19 +38,24 @@ jobs: distribution: temurin java-version: 8 cache: sbt + - run: git fetch --tags || true + - name: Setup Windows C++ toolchain uses: ilammy/msvc-dev-cmd@v1 if: ${{ matrix.os == 'windows-latest' }} + - name: Build shell: bash run: | echo $(pwd) sbt clean example/nativeImage + - uses: actions/upload-artifact@v2 with: path: ${{ matrix.local_path }} name: ${{ matrix.uploaded_filename }} + - name: Upload release if: github.event_name == 'release' uses: actions/upload-release-asset@v1.0.2 From b8012a50cd9ed775ac390753b9d84c291e958a13 Mon Sep 17 00:00:00 2001 From: Chris Kipp Date: Wed, 19 Jul 2023 15:15:05 +0200 Subject: [PATCH 10/10] fix: get rid of stray folder screwing up test --- .../example/src/main/scala/example/Hello2.scala | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 plugin/src/sbt-test/sbt-native-image/cross-build/example/src/main/scala/example/Hello2.scala diff --git a/plugin/src/sbt-test/sbt-native-image/cross-build/example/src/main/scala/example/Hello2.scala b/plugin/src/sbt-test/sbt-native-image/cross-build/example/src/main/scala/example/Hello2.scala deleted file mode 100644 index a29bfcd..0000000 --- a/plugin/src/sbt-test/sbt-native-image/cross-build/example/src/main/scala/example/Hello2.scala +++ /dev/null @@ -1,15 +0,0 @@ -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) - ) - } -}