-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Status on GraalVM native image compatibility #786
Comments
Never used Graal before but as the main guy of working on MPP here I am definitely interested in it. However I don't know what the problem here is as I haven't tried it yet. What happened when you try to build a Graal image? Another thing is about dependency compatibility. I only know that ktor server supports Graal not sure about the client |
Great to hear that you're interested ^^
Some things wont work out of the box when an application is compiled using GraalVM Native Image. All limitations are described here: https://www.graalvm.org/22.1/reference-manual/native-image/Limitations/ As kord relies on kotlinx-serialization, i currently need to provide reflection hints for all
The above configuration would tell GraalVM that it should expect reflection calls for fields, methods and constructors of The same also applies to ktor-client to some extend. However, I'd expect the ktor team to provide compatibility for GraalVM in this case as there are no kord specific classes involved. Only for completeness, the following hints were required in my project:
(The above code is using Spring Frameworks RuntimeHintsRegistrar to generate json format that GraalVM expects during compilation.) Please note, that i'm still very early in the testing phase and that there are a lot of hints still missing (not only for kord but also for other libraries). I'm currently still trying to get the application to boot, which also involves connecting to the discord gateway. That's the main reason why i've started with runtime hints for kord :D And again, just for completeness, this is the branch i'm currently working on: https://github.com/DarkAtra/v-rising-discord-bot/tree/next |
This should be fixed in Kotlin 1.9 and is tracked in KT-51579 |
I've created a test project and I can run using the following config reflect-config.json[
{
"name": "kotlin.internal.jdk8.JDK8PlatformImplementations",
"allPublicMethods": true,
"allDeclaredFields": true,
"allDeclaredMethods": true,
"allDeclaredConstructors": true
},
{
"name": "io.ktor.network.selector.InterestSuspensionsMap",
"allDeclaredFields": true
},
{
"name": "io.ktor.utils.io.pool.DefaultPool",
"allDeclaredFields": true
}
] Main.ktpackage dev.kord.core
import dev.kord.core.event.message.MessageCreateEvent
import dev.kord.gateway.Intent
import dev.kord.gateway.PrivilegedIntent
suspend fun main(args: Array<String>) {
val kord = Kord(args.firstOrNull() ?: error("token required"))
kord.on<MessageCreateEvent> {
if (message.author?.isBot == true) return@on
if (message.content == "!ping") message.channel.createMessage("pong")
}
kord.login {
presence { playing("!ping to pong") }
@OptIn(PrivilegedIntent::class)
intents += Intent.MessageContent
}
} build.gradle.ktsplugins {
`kord-internal-module`
application
id("org.graalvm.buildtools.native") version "0.9.20"
}
dependencies {
implementation(projects.core)
implementation(libs.slf4j.simple)
}
application {
mainClass.set("dev.kord.core.MainKt")
}
graalvmNative {
binaries {
named("main") {
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(19))
vendor.set(JvmVendorSpec.matching("GraalVM Community"))
})
}
}
} Could you share an example of what causes issues with serialization? Also, would you mind joining the Support Discord, so we can discuss this further? After further investigation, the only method using reflection is serializer(), which should be easy to generate {
"name":"package.name.YourClassName",
"fields":[{"name":"Companion"}]
},
{
"name":"package.name.YourClassName$Companion",
"methods":[{"name":"serializer","parameterTypes":[] }]
} |
Could you please try the version |
joined discord in case you still want to discuss something.
i'll try the snapshot now |
with the snapshot it does no longer require runtime hints for:
but the following hints are still required (probably because i am registering
without i'm getting the followng exception:
Runtime hints for ktor and kotlin coroutines are also still required but that is totally fine as it's not something i'd expect kord to provide. |
* pre-release versions are usually suffixed with `-next.1`, `-dev.1` or something similar. we're excluding those from the dependency updates * we're currently relying on the graalvm snapshot build. waiting until there's progress on kordlib/kord#786
## [2.1.2](v2.1.1...v2.1.2) (2023-04-23) ### Bug Fixes * add runtime hints for kord until kordlib/kord/issues/786 is merged ([#67](#67)) ([f6c41a8](f6c41a8))
We will revisit this after #855 |
Since #928 got merged, the Ktor reflection hints might no longer be needed, as those seem to be CIO specific |
Seems like the hint for
[
{
"name": "kotlin.internal.jdk8.JDK8PlatformImplementations",
"allPublicMethods": true,
"allDeclaredFields": true,
"allDeclaredMethods": true,
"allDeclaredConstructors": true
},
{
"name": "io.ktor.utils.io.pool.DefaultPool",
"allDeclaredFields": true
}
] |
should no longer be needed as of 1.9.0 |
In the project i linked i'm stuck with Kotlin 1.8.x for the time being due to oracle/graal#7089. However, i validated that a different project (which already uses kotlin 1.9.23) runs fine without |
Small update...
Additionally, kotlinx.serialization also requires a few reflection hints for (in newer GraalVM versions):
(see oracle/graal#7089) |
Support GraalVM native images
In addition to supporting Kotlin/JS and Kotlin/Native (See #69) we should provide Support for GraalVM native image.
Tasks
Experimental builds
Currently, we provide an experimental Graal build (See #787), this build is not fully tested and not recommended for production use
You can obtain it using the
feature-graal-SNAPSHOT
version. See the Project README for more informationOriginal Issue
I saw that you're working on kotlin native/multiplatform support and was wondering if GraalVM Native Image is also something that you're interested in supporting in the future.
Some context:
I'm currently trying to build a native image for one of my side projects that uses kord and there are a lot of runtime hints required to get everything working. I was hoping that kord could provide such runtime hints so that i don't have to maintain it if something changes under the hood.
The text was updated successfully, but these errors were encountered: