diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 0c7f4a9968d..bf269c4e065 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -34,6 +34,44 @@ concurrency: cancel-in-progress: true jobs: + nativeimage: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: 'true' + show-progress: 'false' + - name: Setup JDK + uses: actions/setup-java@v4 + with: + java-version: 21.0.2 + distribution: 'temurin' + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + gradle-home-cache-cleanup: true + - run: ./gradlew nativeCompile + - name: Upload to GitHub workflow artifacts store + uses: actions/upload-artifact@v4 + with: + name: JabRef-native-image-${{ matrix.os }} + path: build/native/nativeCompile + compression-level: 0 # no compression + - name: Check image (win) + if: (matrix.os == 'windows-latest') + run: | + cd build/native/nativeCompile + ./JabRef.exe --help + - name: Check image (linux, macOS) + if: (matrix.os != 'windows-latest') + run: | + cd build/native/nativeCompile + ./JabRef --help build: strategy: fail-fast: false diff --git a/build.gradle b/build.gradle index 1b3cb79e7bf..e532c5bae64 100644 --- a/build.gradle +++ b/build.gradle @@ -30,6 +30,8 @@ plugins { id 'idea' id 'org.openrewrite.rewrite' version '6.16.4' + + id 'org.graalvm.buildtools.native' version '0.10.2' } // Enable following for debugging @@ -56,7 +58,7 @@ java { // - .github/workflows/deployment-jdk-ea.yml#L53 languageVersion = JavaLanguageVersion.of(21) // See https://docs.gradle.org/current/javadoc/org/gradle/jvm/toolchain/JvmVendorSpec.html for a full list - // vendor = JvmVendorSpec.AMAZON + vendor = JvmVendorSpec.GRAAL_VM } } @@ -856,3 +858,42 @@ jmh { iterations = 10 fork = 2 } + +// Source: https://github.com/tinylog-org/tinylog/issues/145#issuecomment-603430594 +task generateConfiguration(type: Exec) { + group = "graal" + description = "Run application to generate the configuration for native image" + dependsOn assemble + commandLine project.gradle.gradleUserHomeDir.toPath().resolve("jdks/graalvm_community-21-amd64-windows/graalvm-community-openjdk-21.0.2+13.1/bin/java"), "-agentlib:native-image-agent=config-output-dir=" + project.buildDir.toPath().resolve("resources/main/META-INF/native-image"), "-cp", sourceSets.main.runtimeClasspath.getAsPath(), 'org.jabref.Launcher' + + doFirst { + mkdir project.buildDir.toPath().resolve("resources/main/META-INF/native-image") + } +} + + +graalvmNative { + // toolchainDetection = true + binaries { + main { + imageName = "JabRef" + mainClass = "org.jabref.Launcher" + buildArgs.add("-O4") + } + test { + buildArgs.add("-O0") + } + } + binaries.configureEach { + buildArgs.add("-H:+AddAllCharsets") + // buildArgs.add("-H:IncludeResources=*.bst|*.xml|*.csl|*.jks) + buildArgs.add("--allow-incomplete-classpath") + buildArgs.add("--verbose") + buildArgs.add("--initialize-at-run-time=org.tinylog,org.slf4j") + resources.autodetect() + javaLauncher.set(javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(21) + vendor = JvmVendorSpec.GRAAL_VM + }) + } +}