Created
April 17, 2024 13:33
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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