Skip to content

Commit

Permalink
gradle: add native-image plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
pjonsson committed Dec 27, 2023
1 parent 5401f51 commit 999d953
Show file tree
Hide file tree
Showing 3 changed files with 538 additions and 1 deletion.
41 changes: 40 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// sudo apt install libfreetype-dev
plugins {
id 'application'
id 'com.diffplug.spotless' version '6.23.3'
id 'net.ltgt.errorprone' version '3.1.0'
id 'org.graalvm.buildtools.native' version '0.9.28'
}

group = 'org.contikios.cooja'
Expand Down Expand Up @@ -97,6 +99,42 @@ application {
'--enable-preview', '--enable-native-access', 'ALL-UNNAMED']
}

graalvmNative {
metadataRepository {
enabled = true
}
binaries {
main {
// resources.autodetect()
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(javaVersion)
vendor = JvmVendorSpec.matching("Oracle Corporation")
}
fallback = true
useFatJar = true
configurationFileDirectories.from(file('java'))
buildArgs.add('--enable-preview')
buildArgs.add('--strict-image-heap')
buildArgs.add('--report-unsupported-elements-at-runtime')
//buildArgs.add('--initialize-at-build-time=org.slf4j.LoggerFactory,ch.qos.logback')
// Permit java.lang.foreign.SymbolLookup::libraryLookup.
buildArgs.add('--enable-native-access=ALL-UNNAMED')
// FIXME: no support for nativeRun --args?
// FIXME: unclear status of AWT support in native-image.
runtimeArgs.add("--no-gui")
// FIXME: no support for symbol lookup in native-image 21.0.1.
// runtimeArgs.add("../../tests/07-simulation-base/02-ringbufindex.csc")
runtimeArgs.add("/home/user/contiki-ng/tests/07-simulation-base/01-hello-world-sky.csc")
// runtimeArgs.add("/home/user/contiki-ng/tests/07-simulation-base/07-hello-world-z1.csc")
}
}
}

tasks.named("nativeCompile") {
dependsOn fullJar
classpathJar = layout.buildDirectory.file("libs/cooja-full.jar")
}

tasks.withType(JavaCompile).configureEach {
// ErrorProne is slow, only enable with ./gradlew build -Perrorprone.
options.errorprone.enabled = project.hasProperty('errorprone')
Expand Down Expand Up @@ -135,7 +173,8 @@ tasks.withType(JavaCompile).configureEach {
options.errorprone.disable('UnusedMethod')
options.errorprone.disable('UnusedVariable')
options.compilerArgs += ['-Werror', '--enable-preview',
"-Aproject=${project.group}/${project.name}"]
"-Aproject=${project.group}/${project.name}",
"-Aother.resource.patterns=.*"]
}

tasks.withType(AbstractArchiveTask).configureEach {
Expand Down
Loading

0 comments on commit 999d953

Please sign in to comment.