diff --git a/.github/workflows/aot-publish.yml b/.github/workflows/aot-publish.yml new file mode 100644 index 0000000..66c5746 --- /dev/null +++ b/.github/workflows/aot-publish.yml @@ -0,0 +1,37 @@ +name: Ahead-of-time compile & publish +on: + push: + branches: [ "main" ] + tags: ["v*"] + +jobs: + aot-compile: + name: AOT compile on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-14, windows-2022, ubuntu-24.04, ubuntu-24.04-arm] + steps: + - uses: actions/checkout@v4 + + - uses: graalvm/setup-graalvm@v1 + with: + java-version: '23' + distribution: 'graalvm' + github-token: ${{ secrets.GITHUB_TOKEN }} + native-image-job-reports: 'true' + + - name: Setup SBT + uses: sbt/setup-sbt@v1 + + - name: Build native image + run: sbt GraalVMNativeImage/packageBin + + - name: Upload binary + uses: actions/upload-artifact@v4 + with: + name: jelly-cli-${{ matrix.os }} + path: target/graalvm-native-image/jelly-cli + +# TODO: we just build and upload the artifact. +# We should also publish it to GitHub releases. diff --git a/.github/workflows/aot-test.yml b/.github/workflows/aot-test.yml new file mode 100644 index 0000000..cf29f18 --- /dev/null +++ b/.github/workflows/aot-test.yml @@ -0,0 +1,29 @@ +name: Ahead-of-time compilation test +on: + pull_request: + branches: [ "main" ] + +jobs: + build: + name: AOT test on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-14, windows-2022, ubuntu-24.04] + steps: + - uses: actions/checkout@v4 + + - uses: graalvm/setup-graalvm@v1 + with: + java-version: '23' + distribution: 'graalvm' + github-token: ${{ secrets.GITHUB_TOKEN }} + native-image-job-reports: 'true' + + - name: Setup SBT + uses: sbt/setup-sbt@v1 + + - name: Build native image + env: + DEV_BUILD: true + run: sbt GraalVMNativeImage/packageBin diff --git a/build.sbt b/build.sbt index 814f22b..6b322ae 100644 --- a/build.sbt +++ b/build.sbt @@ -8,10 +8,16 @@ resolvers += lazy val jenaV = "5.3.0" lazy val jellyV = "2.8.0+14-4181e89a-SNAPSHOT" +def isDevBuild: Boolean = + sys.env.get("DEV_BUILD").exists(s => s != "0" && s != "false") + lazy val root = (project in file(".")) - .enablePlugins(BuildInfoPlugin) + .enablePlugins( + BuildInfoPlugin, + GraalVMNativeImagePlugin, + ) .settings( - name := "cli", + name := "jelly-cli", libraryDependencies ++= Seq( "org.apache.jena" % "jena-core" % jenaV, "org.apache.jena" % "jena-arq" % jenaV, @@ -25,4 +31,9 @@ lazy val root = (project in file(".")) libraryDependencies, ), buildInfoPackage := "eu.neverblink.jelly.cli", + + // GraalVM settings + Compile / mainClass := Some("eu.neverblink.jelly.cli.App"), + // Do a fast build if it's a dev build + graalVMNativeImageOptions := (if (isDevBuild) Seq("-Ob") else Seq()) ) diff --git a/project/plugins.sbt b/project/plugins.sbt index 9961e9f..9abd225 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,3 +1,3 @@ addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.13.1") addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.9.3") -addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.3.1") +addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.11.1") diff --git a/src/main/scala/eu/neverblink/jelly/cli/command/Version.scala b/src/main/scala/eu/neverblink/jelly/cli/command/Version.scala index 8bd2eb9..5c265ae 100644 --- a/src/main/scala/eu/neverblink/jelly/cli/command/Version.scala +++ b/src/main/scala/eu/neverblink/jelly/cli/command/Version.scala @@ -17,10 +17,9 @@ object Version extends JellyCommand[VersionOptions]: val jellyV = BuildInfo.libraryDependencies .find(_.startsWith("eu.ostrzyciel.jelly:jelly-jena:")).get.split(":")(2) printLine( - f"""jelly-cli ${BuildInfo.version} + f"""jelly-cli ${BuildInfo.version} |---------------------------------------------- |Jelly-JVM $jellyV |Apache Jena $jenaV |JVM ${System.getProperty("java.vm.name")} ${System.getProperty("java.vm.version")} - | |""".stripMargin)