Skip to content

Instantly share code, notes, and snippets.

@illarionov
Created April 17, 2024 13:33
Show Gist options
  • Save illarionov/9ce560f95366649876133c1634a03b88 to your computer and use it in GitHub Desktop.
Save illarionov/9ce560f95366649876133c1634a03b88 to your computer and use it in GitHub Desktop.
Enabling JVMCI and adding Graal compiler to the upgrade-module-path in android unit tests
configurations {
dependencyScope("graalvmCompiler")
resolvable("graalvmCompilerClasspath") {
extendsFrom(configurations["graalvmCompiler"])
}
}
dependencies {
add("graalvmCompiler", "org.graalvm.compiler:compiler:24.0.1")
}
val isRunningOnGraalVm: Provider<Boolean> = providers.gradleProperty("GRAALVM")
.map(String::toBoolean)
.orElse(
providers
.systemProperty("java.home")
.map { javaHome ->
Paths.get("$javaHome/lib/graalvm").exists()
},
)
.orElse(false)
android {
testOptions {
unitTests.all {
it.javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(22)
}
it.jvmArgumentProviders += GraalvmCompilerJvmArgumentsProvider(
configurations["graalvmCompilerClasspath"],
isRunningOnGraalVm,
)
}
}
}
class GraalvmCompilerJvmArgumentsProvider(
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
val gralvmClasspath: FileCollection,
val isGralvm: Provider<Boolean>,
) : CommandLineArgumentProvider {
override fun asArguments(): Iterable<String> {
return if (!isGralvm.get()) {
listOf(
"-XX:+UnlockExperimentalVMOptions",
"-XX:+EnableJVMCI",
"--upgrade-module-path=${gralvmClasspath.asPath}",
)
} else {
emptyList()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment