diff --git a/build.gradle.kts b/build.gradle.kts index 76a5244..42a5b36 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,7 +10,19 @@ repositories { } kotlin { - macosX64("native") { + val hostOs = System.getProperty("os.name") + val isArm64 = System.getProperty("os.arch") == "aarch64" + val isMingwX64 = hostOs.startsWith("Windows") + val nativeTarget = when { + hostOs.startsWith("Mac OS X") && isArm64 -> macosArm64("nativeMacArm64") + hostOs.startsWith("Mac OS X") && !isArm64 -> macosX64("nativeMacX64") + hostOs.startsWith("Linux") && isArm64 -> linuxArm64("nativeLinuxArm64") + hostOs.startsWith("Linux") && !isArm64 -> linuxX64("nativeLinuxX64") + isMingwX64 -> mingwX64("nativeWindows") + else -> throw GradleException("Host OS is not supported in Kotlin/Native.") + } + + nativeTarget.apply { binaries { executable { entryPoint = "main" @@ -22,6 +34,49 @@ kotlin { } } + /*macosX64("native11") { + binaries { + executable() { + entryPoint = "main" + debuggable = true + //freeCompilerArgs += "-Xdefine=DEBUG=true" + ext.set("debug", true) + //project.setProperty("debug", true) + //freeCompilerArgs += "-Pdebug" //-Pdebug=true + } + *//*executable("release") { + entryPoint = "main" + debuggable = false + //freeCompilerArgs += "-Xdefine=RELEASE" + }*//* + } + + compilations["main"].cinterops { + val ncurses by creating { + } + } + }*/ + + val generateBuildConfig by tasks.registering { + doLast { + val file = file("src/commonMain/kotlin/BuildConfig.kt") + + file.writeText( + """ + object BuildConfig { + val DEBUG = ${project.hasProperty("debug")} + } + """.trimIndent() + ) + } + } + + /*tasks { + "compileKotlinNative" { + dependsOn("generateBuildConfig") + } + }*/ + /*val hostOs = System.getProperty("os.name") val isArm64 = System.getProperty("os.arch") == "aarch64" val isMingwX64 = hostOs.startsWith("Windows") @@ -49,21 +104,18 @@ kotlin { sourceSets { val commonMain by getting { dependencies { - //or api? - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3") - implementation("org.kodein.di:kodein-di:7.20.2") + api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3") + api("org.kodein.di:kodein-di:7.20.2") } } - val nativeMain by getting { - //dependsOn(commonMain) - + val nativeMain by creating { dependencies { implementation("com.kgit2:kommand:2.0.1") implementation("org.jetbrains.kotlinx:kotlinx-cli:0.3.6") } } - val nativeTest by getting { + val nativeTest by creating { dependencies { //or api()?? implementation(kotlin("test"))