From b56a9a9713385925cef0adcc6e69fcc3806167f2 Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Mon, 20 Dec 2021 07:55:35 +0100 Subject: [PATCH 1/3] cli: Add Native Image build --- .github/workflows/build.yml | 27 +++++++++++++++++++ alpha-cli-app/build.gradle.kts | 12 +++++++++ .../native-image/resource-config.json | 13 +++++++++ 3 files changed, 52 insertions(+) create mode 100644 alpha-cli-app/src/main/resources/META-INF/native-image/resource-config.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1902bcbfe..88b597a91 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -58,3 +58,30 @@ jobs: - uses: codecov/codecov-action@v1 if: matrix.os == env.MAIN_OS && matrix.java == env.MAIN_JAVA continue-on-error: true + native-image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + fetch-depth: 0 + - name: Set up Graal + run: | + mkdir graalvm + wget -qO- 'https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-21.3.0/graalvm-ce-java17-linux-amd64-21.3.0.tar.gz' | tar xzf - --strip-components=1 -C graalvm + echo "${PWD}/graalvm/bin" >> $GITHUB_PATH + echo "JAVA_HOME=${PWD}/graalvm" >> $GITHUB_ENV + - run: sudo apt-get install -y build-essential libz-dev zlib1g-dev + - run: | + echo $LD_LIBRARY_PATH + sudo ldconfig + - run: gu install native-image + - uses: gradle/gradle-build-action@v2 + with: + arguments: build --stacktrace alpha-cli-app:nativeImage -x test + - run: ./alpha-cli-app/build/native-image/alpha --help + - run: ./alpha-cli-app/build/native-image/alpha -str 'a.' + - uses: actions/upload-artifact@v2 + with: + name: alpha + path: alpha-cli-app/build/native-image/alpha diff --git a/alpha-cli-app/build.gradle.kts b/alpha-cli-app/build.gradle.kts index a62227309..633d5cdf5 100644 --- a/alpha-cli-app/build.gradle.kts +++ b/alpha-cli-app/build.gradle.kts @@ -1,5 +1,6 @@ plugins { id("alpha.java-application-conventions") + id("org.mikeneck.graalvm-native-image") version "1.4.1" } dependencies { @@ -71,3 +72,14 @@ tasks.create("bundledJar") { tasks.test { useJUnitPlatform() } + +tasks.nativeImage { + mainClass = main + executableName = "alpha" + arguments( + "--no-fallback", + "-H:Log=registerResource", + "-H:+ReportExceptionStackTraces", + "--report-unsupported-elements-at-runtime", + ) +} diff --git a/alpha-cli-app/src/main/resources/META-INF/native-image/resource-config.json b/alpha-cli-app/src/main/resources/META-INF/native-image/resource-config.json new file mode 100644 index 000000000..3c9328fa7 --- /dev/null +++ b/alpha-cli-app/src/main/resources/META-INF/native-image/resource-config.json @@ -0,0 +1,13 @@ +{ + "resources": { + "includes": [ + { + "pattern": "^stringtemplates/aggregate-encodings.stg$" + }, + { + "pattern": "^simplelogger.properties$" + } + ] + }, + "bundles": [] +} From c64202ca802f3ac56e2c288e45d22d99b8731435 Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Mon, 20 Dec 2021 16:34:44 +0100 Subject: [PATCH 2/3] native: Use GraalVM Gradle Plugin --- .github/workflows/build.yml | 6 +++--- alpha-cli-app/build.gradle.kts | 28 ++++++++++++++++++---------- settings.gradle.kts | 9 ++++++++- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 88b597a91..3cbca7e3a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -78,9 +78,9 @@ jobs: - run: gu install native-image - uses: gradle/gradle-build-action@v2 with: - arguments: build --stacktrace alpha-cli-app:nativeImage -x test - - run: ./alpha-cli-app/build/native-image/alpha --help - - run: ./alpha-cli-app/build/native-image/alpha -str 'a.' + arguments: build --stacktrace alpha-cli-app:nativeCompile -x test + - run: ./alpha-cli-app/build/native/nativeCompile/alpha --help + - run: ./alpha-cli-app/build/native/nativeCompile/alpha -str 'a.' - uses: actions/upload-artifact@v2 with: name: alpha diff --git a/alpha-cli-app/build.gradle.kts b/alpha-cli-app/build.gradle.kts index 633d5cdf5..e68b7dd90 100644 --- a/alpha-cli-app/build.gradle.kts +++ b/alpha-cli-app/build.gradle.kts @@ -1,6 +1,6 @@ plugins { id("alpha.java-application-conventions") - id("org.mikeneck.graalvm-native-image") version "1.4.1" + id("org.graalvm.buildtools.native") version "0.9.8" } dependencies { @@ -73,13 +73,21 @@ tasks.test { useJUnitPlatform() } -tasks.nativeImage { - mainClass = main - executableName = "alpha" - arguments( - "--no-fallback", - "-H:Log=registerResource", - "-H:+ReportExceptionStackTraces", - "--report-unsupported-elements-at-runtime", - ) +graalvmNative { + binaries { + named("main") { + imageName.set("alpha") + mainClass.set(main) + buildArgs.addAll( + "--no-fallback", + "-H:Log=registerResource", + "-H:+ReportExceptionStackTraces", + "--report-unsupported-elements-at-runtime" + ) + javaLauncher.set(javaToolchains.launcherFor { + languageVersion.set(JavaLanguageVersion.of(17)) + vendor.set(JvmVendorSpec.matching("GraalVM")) + }) + } + } } diff --git a/settings.gradle.kts b/settings.gradle.kts index 28bf10ac3..4ffa44b28 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,2 +1,9 @@ +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() + } +} + rootProject.name = "alpha" -include("alpha-api", "alpha-cli-app", "alpha-core", "alpha-solver", "alpha-commons") \ No newline at end of file +include("alpha-api", "alpha-cli-app", "alpha-core", "alpha-solver", "alpha-commons") From 6366e791d89271250c1d675552a125b2094a2c64 Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Mon, 3 Jan 2022 14:11:10 +0100 Subject: [PATCH 3/3] ci: Use Graal Action for setup --- .github/workflows/build.yml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3cbca7e3a..e924acd4b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -65,20 +65,28 @@ jobs: with: submodules: recursive fetch-depth: 0 - - name: Set up Graal - run: | - mkdir graalvm - wget -qO- 'https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-21.3.0/graalvm-ce-java17-linux-amd64-21.3.0.tar.gz' | tar xzf - --strip-components=1 -C graalvm - echo "${PWD}/graalvm/bin" >> $GITHUB_PATH - echo "JAVA_HOME=${PWD}/graalvm" >> $GITHUB_ENV + - uses: actions/setup-java@v2 + with: + java-version: '17' + distribution: 'temurin' + - uses: graalvm/setup-graalvm@v1 + with: + version: '21.3.0' + java-version: '17' + components: 'native-image' + github-token: ${{ secrets.GITHUB_TOKEN }} + set-java-home: false + - run: echo "org.gradle.java.installations.fromEnv=GRAALVM_HOME" >> gradle.properties - run: sudo apt-get install -y build-essential libz-dev zlib1g-dev - run: | echo $LD_LIBRARY_PATH sudo ldconfig - - run: gu install native-image - uses: gradle/gradle-build-action@v2 with: - arguments: build --stacktrace alpha-cli-app:nativeCompile -x test + arguments: --quiet javaToolchains + - uses: gradle/gradle-build-action@v2 + with: + arguments: --stacktrace alpha-cli-app:nativeCompile --exclude-task test - run: ./alpha-cli-app/build/native/nativeCompile/alpha --help - run: ./alpha-cli-app/build/native/nativeCompile/alpha -str 'a.' - uses: actions/upload-artifact@v2