Skip to content

Commit

Permalink
SBT: update native build to JDK21
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Nov 18, 2024
1 parent c18c0b7 commit a24b75b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,25 @@ jobs:
- os: macOS-latest
artifact: scalafmt-macos
env:
NATIVE_IMAGE_STATIC: false
NATIVE_IMAGE_STATIC: none
- os: ubuntu-latest
libc: default
artifact: scalafmt-linux-glibc
env:
NATIVE_IMAGE_STATIC: true
NATIVE_IMAGE_STATIC: nolibc
- os: ubuntu-latest
libc: musl
artifact: scalafmt-linux-musl
env:
NATIVE_IMAGE_STATIC: true
NATIVE_IMAGE_MUSL: true
NATIVE_IMAGE_STATIC: musl
env: ${{ matrix.env }}
steps:
- uses: actions/checkout@v4
- name: Set up GraalVM
uses: graalvm/setup-graalvm@v1
with:
version: '22.3.0'
java-version: '11'
components: 'native-image'
java-version: '21'
distribution: 'graalvm-community'
native-image-musl: ${{ matrix.libc == 'musl' }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: sbt/setup-sbt@v1
Expand Down
18 changes: 11 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,19 @@ lazy val cli = crossProject(JVMPlatform, NativePlatform)
),
scalacOptions ++= scalacJvmOptions.value,
Compile / mainClass := Some("org.scalafmt.cli.Cli"),
nativeImageVersion := "22.3.0",
nativeImageInstalled := isCI,
nativeImageOptions ++= {
val isMusl = sys.env.get("NATIVE_IMAGE_MUSL").exists(_.toBoolean)
if (isMusl) Seq("--libc=musl") else Nil
},
nativeImageOptions ++= {
val isStatic = sys.env.get("NATIVE_IMAGE_STATIC").exists(_.toBoolean)
if (isStatic) Seq("--static") else Nil
// https://www.graalvm.org/22.3/reference-manual/native-image/guides/build-static-executables/
// https://www.graalvm.org/latest/reference-manual/native-image/guides/build-static-executables/
sys.env.get("NATIVE_IMAGE_STATIC") match {
case Some("nolibc") => Seq(
"-H:+UnlockExperimentalVMOptions",
"-H:+StaticExecutableWithDynamicLibC",
"-H:-UnlockExperimentalVMOptions",
)
case Some("musl") => Seq("--static", "--libc=musl")
case _ => Nil
}
},
).nativeSettings(scalaNativeConfig).dependsOn(core, dynamic)
.enablePlugins(NativeImagePlugin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ Args=--no-server \
--enable-http \
--enable-https \
--install-exit-handlers \
--initialize-at-build-time \
--initialize-at-run-time=org.scalafmt.util.AbsoluteFile \
--strict-image-heap \
-march=native \
--initialize-at-build-time="org.scalafmt" \
--initialize-at-build-time="org.scalameta" \
--initialize-at-build-time="scala.meta" \
--report-unsupported-elements-at-runtime \
-H:EnableURLProtocols=http,https \
-H:+UnlockExperimentalVMOptions \
-H:+RemoveSaturatedTypeFlows \
-H:+ReportExceptionStackTraces
-H:+ReportExceptionStackTraces \
-H:-UnlockExperimentalVMOptions

0 comments on commit a24b75b

Please sign in to comment.