Skip to content
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

Native artifact only supports linuxX64 #8

Open
tclement0922 opened this issue Jan 4, 2023 · 2 comments
Open

Native artifact only supports linuxX64 #8

tclement0922 opened this issue Jan 4, 2023 · 2 comments

Comments

@tclement0922
Copy link

I was using this lib in a personal project but it appears that the colorkt-native artifact (from Maven Central) only supports linuxX64.
Here is the error thrown by Gradle :

   > Could not resolve dev.kdrag0n:colorkt:1.0.5.
     Required by:
         project :
      > No matching variant of dev.kdrag0n:colorkt:1.0.5 was found. The consumer was configured to find a usage of 'kotlin-cinterop' of a library, with the library elements 'cinterop-klib', preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native', attribute 'org.jetbrains.kotlin.native.target' with value 'mingw_x64' but:
...
          - Variant 'nativeApiElements-published' capability dev.kdrag0n:colorkt:1.0.5 declares a usage of 'kotlin-api' of a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'mingw_x64'
...

So right now if anyone wants to use this lib in a Multiplatform project targeting multiple native platforms (like mingwX64 or macosX64) they need to clone this repo and build the lib themselves (cross-compilation is available for all native targets expect for Apple products targets afaik).

@kdrag0n
Copy link
Owner

kdrag0n commented Jan 9, 2023

Is there an easy way to set up all the cross-compiling targets? I can build from an Apple host.

@tclement0922
Copy link
Author

I think the easiest way to set up all the targets is to simply do something like this:

kotlin {
    linuxX64()
    mingwX64()
    macosX64()
    ...

But if you want to use the same code for all native targets, you should add something like this in the sourceSets block:

val nativeMain by creating { dependsOn(commonMain) }
val nativeTest by creating { dependsOn(commonTest) }

val linuxX64Main by getting { dependsOn(nativeMain) }
val linuxX64Test by getting { dependsOn(nativeTest) }

val mingwX64Main by getting { dependsOn(nativeMain) }
val mingwX64Test by getting { dependsOn(nativeTest) }

val macosX64Main by getting { dependsOn(nativeMain) }
val macosX64Test by getting { dependsOn(nativeTest) }

And it looks like that cross compilation is possible from a MacOS host to almost any other targets (see there), so you'll be able to build the library for (almost) every target you want from your Apple host.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants