https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
s

Sarah-Jane Gallitz

09/09/2020, 12:09 AM
Hey all, new to KMP. I was wondering, is it possible to publish a “kotlin” library for use in multi platform projects? I don’t want Library A (kotlin code, no dependencies) to have to compile for every target that Library B wants to use. Especially with regards to macOS/iOS targets. If not, is it possible to compile for iOS targets (assuming we don’t use any of the framework code) without a mac?
d

darkmoon_uk

09/09/2020, 12:23 AM
Hi @Sarah-Jane Gallitz, my understanding of your two questions is: 1 - Sort of. and 2 - No. Both of these scenarios are being targeted by the new Kotlin compiler that will take Kotlin source through to an intermediate representation first - akin to Apple's Bitcode. Referred to as the 'IR' compiler. Today, the only(?) solution for distributing multiplatform libraries is via Gradle - it compiles separately for each target then packs the output artifact, be it a jar for JVM/Android, klib for K/Native etc, as a Maven-style artifact. These are then tied together by a Gradle Metadata package. When resolving the dependency, Gradle is pointed to the metadata package and then it resolves the correct platforms artifact (if it exists).
This gives the effect of being able to distribute a 'kotlin' library, but is not the true solution it sounds like you're seeking - the IR code which can be much more lightly transformed to the target platform is the grail we seek.
...as the above implies, today it's not possible to compile even un-linked mac/ios binary library on a non-Mac platform.
If this is for production and you need iOS support, my suggestion would be to get one or more Mac Mini's to be build agents for your CI.
They're the do-it-all workhorse right now.
s

Sarah-Jane Gallitz

09/09/2020, 12:30 AM
Thanks @darkmoon_uk. So, in the future it may be possible to publish the IR code for use by other multiplatform projects? That’s very exciting!
d

darkmoon_uk

09/09/2020, 12:32 AM
Sure is 🙂 Probably a year or more away, so worth getting the hang of the Gradle alternative first. Looking forward to it though.
@Sarah-Jane Gallitz The IR compiler already exists and is released in some form... for example: https://kotlinlang.org/docs/reference/js-ir-compiler.html ...the longer term plan being for it to mature and roll out as the foundation of all the targets.
l

louiscad

09/09/2020, 6:15 AM
@Sarah-Jane Gallitz Is the library you want to make an open source project? If so, you can have GitHub Actions build and publish your library for free on a Mac (I can link you examples as I do it).
s

Sarah-Jane Gallitz

09/09/2020, 6:19 AM
Thanks! Unfortunately it’s not,, but I’ll keep that in mind for other projects
n

Neil

09/09/2020, 8:54 AM
Bitrise CI can build on Mac, I don't know if it can be configured to include the kotlin compiler/tools at the same time but it might be worth a look. (Private builds, maybe not free but not too expensive)
1
l

louiscad

09/09/2020, 8:57 AM
Yes for paid, possibly with a free tier with limits, you can have a multiplatform library build on a mac, for less than the price of a mac. If you host your code on GitHub, Actions can work on private repos too, with 2K free minutes per month IIRC. Bitrise might be better than GitHub Actions though, I didn't compare and only build OSS multiplatform projects for now.
5 Views