https://kotlinlang.org logo
#kotlin-native
Title
# kotlin-native
p

p4czyk

08/08/2022, 7:03 PM
Hey guys! 😊 Do you know how I can compile a
kotlinx
library like
kotlinx-datetime
for LinuxArm64 and use it in my project? 🤔
l

Landry Norris

08/08/2022, 7:07 PM
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

ephemient

08/08/2022, 7:09 PM
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

p4czyk

08/08/2022, 7:09 PM
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

Landry Norris

08/08/2022, 7:09 PM
Actually, looks like it only supports linuxX64
e

ephemient

08/08/2022, 7:09 PM
patrick: you should be able to build them yourself
p

p4czyk

08/08/2022, 7:10 PM
@ephemient That's interesting. Do you know how to include it into my project via gradle? 😅
e

ephemient

08/08/2022, 7:11 PM
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

p4czyk

08/08/2022, 7:12 PM
Is it possible to publish it "locally"? I don't have a remote maven repository. 😅
l

Landry Norris

08/08/2022, 7:12 PM
You can use publishToMavenLocal gradle task and add mavenLocal() to your repositories block.
p

p4czyk

08/08/2022, 7:13 PM
Thanks. I'll try this. 👍
e

ephemient

08/08/2022, 7:13 PM
it is possible to publish to mavenLocal which is
~/.m2/repository
but there are some issue with that
l

Landry Norris

08/08/2022, 7:13 PM
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

ephemient

08/08/2022, 7:13 PM
you can treat any directory as a maven repo instead
p

p4czyk

08/08/2022, 7:15 PM
Oh, okay. I try to publish into a subdirectory in my project like "project/libs" or something. 👍
l

Landry Norris

08/08/2022, 7:15 PM
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

ephemient

08/08/2022, 7:18 PM
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

Landry Norris

08/08/2022, 7:22 PM
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

ephemient

08/08/2022, 7:25 PM
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

Landry Norris

08/08/2022, 7:25 PM
Yeah. I guess at some point it’s easier to use a folder in the project. Also helps with CI.
e

ephemient

08/08/2022, 7:26 PM
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

Landry Norris

08/08/2022, 7:27 PM
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

ephemient

08/08/2022, 7:29 PM
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

p4czyk

08/08/2022, 7:57 PM
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

napperley

08/08/2022, 11:20 PM
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

Big Chungus

08/08/2022, 11:35 PM
Why is nobody mentioning grade included builds? No need to publish anything
e

ephemient

08/08/2022, 11:58 PM
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

Big Chungus

08/09/2022, 8:29 AM
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
8 Views