Search code examples
kotlingradle-kotlin-dslkotlin-native

kotlin native gradle hello world


I am trying to get started with Kotlin Native, and have fallen at getting build.gradle.kts right for "hello world" ;(

I have stumbled to:

plugins {
    kotlin("native") version "0.8.2"
    //kotlin("konan") version "0.8"  <- seems to be auto loaded
}

dependencies {
    kotlin("stdlib")

}
repositories { 
    jcenter() 
}
sourceSets["main"].kotlin {
    srcDir("src")
}

But I need to set compilation arguments and enable the GRADLE_METADATA feature, I have drawn a black trying to find these. Samples I have found usually seem to be already out of date. I am not sure if sourceSets works either, while it allows this syntax, there is no colored folders happening in Clion as happens with Intellij. Pity I cant work in Intellij as the project is multi platform so I will need to move to woring in both it seems.

Any Ideas on how to solve the two problems identified so far?


Solution

  • OK, Found the answer,

    The correct file should be

    plugins {
        //kotlin("native") version "0.8.2"
        kotlin("konan") version "0.8.2"
    }
    
    
    konanArtifacts{
       program("hello"){
           srcDir("src/main/kotlin")
       }
    }
    dependencies {
        kotlin("stdlib")
    
    }
    repositories { 
        jcenter() 
    }
    

    The "native" plugin seeming to work was a red herring, and it enabled the 'sourceSets', making a second red herring. The correct plugin 'konan' specifies the src as above.

    The executable runs!

    (However, still no color coding of folders in Clion, not sure if that means anything. More significantly, debugging not running at this time.)