Hey guys! :blush: Do you know how I can compile a ...
# kotlin-native
p
Hey guys! 😊 Do you know how I can compile a
kotlinx
library like
kotlinx-datetime
for LinuxArm64 and use it in my project? 🤔
l
Are you looking to use it in a C project, or a Kotlin project? If you’re looking to use it in a Kotlin project, you’ll just need to add it as a dependency in your build.gradle.kts
e
landry: the issue is that jetbrains libraries don't have published native linux arm64 binaries (e.g. https://github.com/Kotlin/kotlinx.coroutines/issues/855)
p
Yeah, I want to use it in a Kotlin project. The problem is that there is no official build in the maven central for LinuxArm64 only for LinuxX64 (https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-datetime-linuxx64/0.4.0/klib). Is there a way to build it from sources?
l
Actually, looks like it only supports linuxX64
e
patrick: you should be able to build them yourself
p
@ephemient That's interesting. Do you know how to include it into my project via gradle? 😅
e
you will first need to check out the projects, modify the build scripts to include linuxArm64 targets, then publish to your own maven repository
then in your own project you can use it as normal
p
Is it possible to publish it "locally"? I don't have a remote maven repository. 😅
l
You can use publishToMavenLocal gradle task and add mavenLocal() to your repositories block.
p
Thanks. I'll try this. 👍
e
it is possible to publish to mavenLocal which is
~/.m2/repository
but there are some issue with that
l
This will publish it to ~/.m2/repository if you need to inspect the files manually at some point. Note that this won’t work with CI.
e
you can treat any directory as a maven repo instead
p
Oh, okay. I try to publish into a subdirectory in my project like "project/libs" or something. 👍
l
Aren’t the issues with mavenLocal largely mitigated by putting mavenLocal() last in the repositories block? I’ve used it a few times without any major issues.
e
if you have a maven build that uses kotlinx-datetime, as well as your own built versions, you can end up with a broken mix
kotlin scripting, for example, will end up pulling jvm artifacts into
~/.m2/repository
most issues aren't so bad by putting it last or with a content filter, but if you're extending/replacing artifacts that exist elsewhere, that doesn't help
l
You’d have to make sure the version doesn’t match one that exists remotely if you use mavenLocal with it set as the last repo. I would always add a -local or something to the version.
e
I'd use the same version, but ok even if you change it, you have to take care as Maven versions cannot contain arbitrary components
(well, they can, but then version comparison becomes inconsistent between build tools)
l
Yeah. I guess at some point it’s easier to use a folder in the project. Also helps with CI.
e
honestly I'd just put a simple HTTP server on the CI machine or something, you need very little to host a maven repository
l
Isn’t there a project that uses a basic KTor setup and Google’s App Engine to host a maven repository somewhere on GitHub? I think I saw that once before setting up a mavenCentral account.
e
I don't know of one in ktor but there's https://github.com/dzikoysk/reposilite for example
(but if you don't need the management interface, literally serving a maven directory via HTTP is sufficient to distribute artifacts as long as the server supports the HEAD method, since Gradle requires that)
p
Alright, I've compiled it and tried to use it in Gradle. I added the `mavenLocal()`` call but after trying to build my project it says that the
.def
file doesn't exist. Do you know how to solve this issue? 🤔
Nevermind, it worked. I had to copy the
.def
file to my project. Thank you guys! 🥳
n
Support for various targets with the KotlinX libraries is inconsistent. The Kotlin Libraries team need to resolve the issue. Some of the KotlinX libraries do have support for linuxArm64 like KotlinX Serialization ( https://github.com/Kotlin/kotlinx.serialization/blob/16a85df254f4f1e317554eb61ee1fbe914800aa4/gradle/native-targets.gradle#L102 ) for example.
b
Why is nobody mentioning grade included builds? No need to publish anything
e
they have issues with multiplatform
composite builds (
includeBuild
) are usually a great way to substitute binary dependencies with source builds, but in this case they don't work
b
They do work, just can be flakey sometimes. If I were you I'd first try the composite builds and only go for local publishing if they do not work for you.
I have used included builds successfully in many (but not all) occasions myself