From b56a9a9713385925cef0adcc6e69fcc3806167f2 Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Mon, 20 Dec 2021 07:55:35 +0100 Subject: [PATCH] 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": [] +}