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

diesieben07

09/15/2020, 4:59 PM
I am playing around with Multiplatform and Kotlin/Native. I want to be able to use
posix
in code shared between Linux/OSX. However I cannot get this to work at all. I have set
kotlin.mpp.enableGranularSourceSetsMetadata=true
and
kotlin.native.enableDependencyPropagation=false
like described in the docs. Then I have created a
nativeMain
source set:
Copy code
val nativeMain by creating {
  dependsOn(commonMain)
 }
Then I have configured the
linuxX64Main
and
osxX64Main
source sets to depend on
nativeMain
. However I still cannot use
posix
in
nativeMain
. This issue happens both when trying to compile with Gradle as well as in IntelliJ (types / functions cannot be resolved). What am I missing?
a

aleksey.tomin

09/15/2020, 5:02 PM
1. You have to use
macosX64Main
- not
osxX64Main
2. IDEA has the bug. But
gradle build
works fine.
d

diesieben07

09/15/2020, 5:05 PM
1. Renaming the target (and thereby sourceset) to
macosX64
does not help. 2.
gradle build
does not work fine (like I said above). It shows "unresolved reference: platform" for
import platform.posix.*
I've pushed my Code to github: https://github.com/diesieben07/konan_test
b

Big Chungus

09/15/2020, 5:38 PM
I believe he meant to change the target, not just the name. i.e. instead of
Copy code
kotlin {
  osxX64("macosX64") {...}
}
Do
Copy code
kotlin {
  macosX64 {...}
}
d

diesieben07

09/15/2020, 5:39 PM
osxX64
would not even compile
b

Big Chungus

09/15/2020, 5:43 PM
My bad, thought they've added a shortcut for that same as for ios
Imports are red in IDE, but it does compile.
d

diesieben07

09/15/2020, 6:02 PM
Okay, so I have to explicitly not enable the thing that the documentation tells me I need to enable for it to work. Very strange. But it does compile for me using Gradle now, thanks Arkadii
👍 1
m

msink

09/16/2020, 10:01 AM
If you want it working in IDEA - something like this should work:
Copy code
kotlin {
    linuxX64()
    macosX64()
 
   targets.withType<KotlinNativeTarget> {
        sourceSets["${targetName}Main"].apply {
            kotlin.srcDir("src/nativeMain/kotlin")
        }
    }
}
2 Views