Hi, I’m trying to achieve something similar to wha...
# kotlin-native
j
Hi, I’m trying to achieve something similar to what this person asks about: https://discuss.kotlinlang.org/t/multiplatform-multiple-native-targets-same-source-code/11276 Basically, I want to have shared source for two targets (
macos64
and
linuxX64
). They should both be able to utilize
platform.posix
and
kotlin.system
. Is there an example for setting up something like that? I tried to setup what the original Q/A had but IntelliJ showed that “Kotlin/Native 1.3.50 - stdlib” wasn’t an available dependency for that
sourceSet
.
b
you can create a source directory called
nixMain
or something like that, and then you add that source directory to both targets
j
Ok so I’ve ended up with something like this:
Copy code
plugins {
    id 'org.jetbrains.kotlin.multiplatform' version '1.3.50'
}
repositories {
    mavenCentral()
}
kotlin {
    macosX64("macos") {
        binaries {
            executable {
                // Change to specify fully qualified name of your application's entry point:
                entryPoint = 'sample.main'
                // Specify command-line arguments, if necessary:
                runTask?.args('')
            }
        }
    }

    linuxX64("linux") {

    }

    sourceSets {
        // Note: To enable common source sets please comment out 'kotlin.import.noCommonSourceSets' property
        // in gradle.properties file and re-import your project in IDE.
        macosMain {
            kotlin.srcDirs += file("src/nativeCommon/kotlin")
        }
        linuxMain {
            kotlin.srcDirs += file("src/nativeCommon/kotlin")
        }
    }
}
It seems to compile and run fine but IntelliK is unhappy. 😕
message has been deleted
b
Hm. For that, I'd probably start clearing caches. Satisfying gradle isn't hard. Satisfying IntelliJ is another project ha
j
Is there additional configuration I need to do so that intellij properly understands what’s going on?
Ok I’ve tried a few things. Truthfully, I’ve spent more time on this that I’d care to mention. 😄 Seems like you are right in that the issue is mainly to do with IntelliJ. Seems like it would be related to this: https://youtrack.jetbrains.com/issue/IDEABKL-6745#focus=streamItem-27-2672229.0-0 https://youtrack.jetbrains.com/issue/IDEA-210908 https://youtrack.jetbrains.com/issue/IDEA-210311 Haven’t read the whole history of this issue but it certainly makes it unusable for the use case I have in mind.
I’ve pushed a bare sample repo to reproduce my pain point in case anyone is interested: https://github.com/jromero/native-posix-sample
l
I have a solution that I use in #splitties (develop branch), but it requires symlinks and additional config in buildScr to see a shared sourceSet as a platform one in the IDE. If you're willing to add the config, then you can do the same (feel free to ask for clarification on what I do exactly).
j
Thanks I'll have to check it out.
s
@jromero There is something called "hierarchical multiplatform projects" (hmpp) which might cover your use case. It is currently under development, but you might want to try it. Putting this kotlin.mpp.enableGranularSourceSetsMetadata=true into your gradle.properties will get you started!