plugins {
    id 'org.jetbrains.kotlin.multiplatform'
}

repositories {
    mavenCentral()
    maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
    // Coroutines from the outer project are published by previous CI buils step
    mavenLocal()
}

kotlin {
    jvm()
    js(IR) {
        nodejs()
    }
    wasmJs() {
        nodejs()
    }
    
    macosArm64()
    macosX64()
    linuxArm64()
    linuxX64()
    mingwX64()

    sourceSets {
        commonMain {
            dependencies {
                implementation kotlin('stdlib-common')
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
            }
        }
        commonTest {
            dependencies {
                implementation kotlin('test-common')
                implementation kotlin('test-annotations-common')
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version"
            }
        }
        jsTest {
            dependencies {
                implementation kotlin('test-js')
            }
        }
        wasmJsTest {
            dependencies {
                implementation kotlin('test-wasm-js')
            }
        }
        wasmWasiTest {
            dependencies {
                implementation kotlin('test-wasm-wasi')
            }
        }
        jvmTest {
            dependencies {
                implementation kotlin('test')
                implementation kotlin('test-junit')
            }
        }
    }
    targets {
        configure([]) {
            tasks.getByName(compilations.main.compileKotlinTaskName).kotlinOptions {
                jvmTarget = "1.8"
            }
        }
    }
}

// Drop this configuration when the Node.JS version in KGP will support wasm gc milestone 4
// check it here:
// https://github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/nodejs/NodeJsRootExtension.kt
rootProject.extensions.findByType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension.class).with {
    // canary nodejs that supports recent Wasm GC changes
    it.nodeVersion = "21.0.0-v8-canary202309167e82ab1fa2"
    it.nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary"
}
