Use official graalvm native-image gradle plugin

This commit is contained in:
AsamK 2021-09-12 19:08:47 +02:00
parent cbff7217c1
commit 627a587952
3 changed files with 19 additions and 43 deletions

View file

@ -98,9 +98,9 @@ This is still experimental and will not work in all situations.
2. [Install prerequisites](https://www.graalvm.org/reference-manual/native-image/#prerequisites) 2. [Install prerequisites](https://www.graalvm.org/reference-manual/native-image/#prerequisites)
3. Execute Gradle: 3. Execute Gradle:
./gradlew assembleNativeImage ./gradlew nativeCompile
The binary is available at *build/native-image/signal-cli* The binary is available at *build/native/nativeCompile/signal-cli*
## FAQ and Troubleshooting ## FAQ and Troubleshooting
For frequently asked questions and issues have a look at the [wiki](https://github.com/AsamK/signal-cli/wiki/FAQ) For frequently asked questions and issues have a look at the [wiki](https://github.com/AsamK/signal-cli/wiki/FAQ)

View file

@ -3,6 +3,7 @@ plugins {
application application
eclipse eclipse
`check-lib-versions` `check-lib-versions`
id("org.graalvm.buildtools.native") version "0.9.5"
} }
version = "0.9.0" version = "0.9.0"
@ -16,6 +17,15 @@ application {
mainClass.set("org.asamk.signal.Main") mainClass.set("org.asamk.signal.Main")
} }
graalvmNative {
binaries {
this["main"].run {
configurationFileDirectories.from(file("graalvm-config-dir"))
buildArgs.add("--allow-incomplete-classpath")
}
}
}
repositories { repositories {
mavenLocal() mavenLocal()
mavenCentral() mavenCentral()
@ -63,42 +73,3 @@ tasks.withType<JavaExec> {
args = groovy.util.Eval.me(appArgs) as MutableList<String> args = groovy.util.Eval.me(appArgs) as MutableList<String>
} }
} }
val assembleNativeImage by tasks.registering {
dependsOn("assemble")
var graalVMHome = ""
doFirst {
graalVMHome = System.getenv("GRAALVM_HOME")
?: throw GradleException("Required GRAALVM_HOME environment variable not set.")
}
doLast {
val nativeBinaryOutputPath = "$buildDir/native-image"
val nativeBinaryName = "signal-cli"
mkdir(nativeBinaryOutputPath)
exec {
workingDir = File(".")
commandLine(
"$graalVMHome/bin/native-image",
"-H:Path=$nativeBinaryOutputPath",
"-H:Name=$nativeBinaryName",
"-H:JNIConfigurationFiles=graalvm-config-dir/jni-config.json",
"-H:DynamicProxyConfigurationFiles=graalvm-config-dir/proxy-config.json",
"-H:ResourceConfigurationFiles=graalvm-config-dir/resource-config.json",
"-H:ReflectionConfigurationFiles=graalvm-config-dir/reflect-config.json",
"--no-fallback",
"--allow-incomplete-classpath",
"--report-unsupported-elements-at-runtime",
"--enable-url-protocols=http,https",
"--enable-https",
"--enable-all-security-services",
"-cp",
sourceSets.main.get().runtimeClasspath.asPath,
application.mainClass.get()
)
}
}
}

View file

@ -11,17 +11,22 @@ if [ ! -z "$GRAALVM_HOME" ]; then
export JAVA_HOME=$GRAALVM_HOME export JAVA_HOME=$GRAALVM_HOME
export SIGNAL_CLI_OPTS='-agentlib:native-image-agent=config-merge-dir=graalvm-config-dir/' export SIGNAL_CLI_OPTS='-agentlib:native-image-agent=config-merge-dir=graalvm-config-dir/'
fi fi
export SIGNAL_CLI="$PWD/build/install/signal-cli/bin/signal-cli"
NUMBER_1="$1" NUMBER_1="$1"
NUMBER_2="$2" NUMBER_2="$2"
TEST_PIN_1=456test_pin_foo123 TEST_PIN_1=456test_pin_foo123
NATIVE=1
PATH_TEST_CONFIG="$PWD/build/test-config" PATH_TEST_CONFIG="$PWD/build/test-config"
PATH_MAIN="$PATH_TEST_CONFIG/main" PATH_MAIN="$PATH_TEST_CONFIG/main"
PATH_LINK="$PATH_TEST_CONFIG/link" PATH_LINK="$PATH_TEST_CONFIG/link"
if [ "$NATIVE" -eq 1 ]; then
SIGNAL_CLI="$PWD/build/native/nativeCompile/signal-cli"
else
./gradlew installDist ./gradlew installDist
SIGNAL_CLI="$PWD/build/install/signal-cli/bin/signal-cli"
fi
run() { run() {
set -x set -x