/*
 * Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

import static KotlinVersion.*

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(11))
    }
}

tasks.withType(JavaCompile).configureEach {
    options.release = 8
}

// Unfortunately there is no compatible version of okio for Wasm WASI target, so we need to skip to configure WASI for json-okio and json-tests.
// json-tests uses okio with incorporate with other formatter tests so it is hard and not worth to separate it for two projects for WASI.
// So we disable WASI target in it and we hope, that WASI version of compiler and serialization plugin are identical to the WasmJS target so WASI target is being covered.
Boolean isOkIoOrFormatTests = (project.name == 'kotlinx-serialization-json-okio' || project.name == 'kotlinx-serialization-json-tests')

kotlin {
    jvm {
        withJava()
        compilations.configureEach {
            kotlinOptions {
                jvmTarget = '1.8'
                freeCompilerArgs += '-Xjdk-release=1.8'
            }
        }
    }

    js {
        nodejs {
            testTask {
                useMocha {
		    timeout = "10s"
                }
            }
        }
        configure([compilations.main, compilations.test]) {
            kotlinOptions {
                sourceMap = true
                moduleKind = "umd"
            }
        }
    }

    wasmJs {
        nodejs()
    }

    if (!isOkIoOrFormatTests) {
        wasmWasi {
            nodejs()
        }
    }

    sourceSets.all {
        kotlin.srcDirs = ["$it.name/src"]
        resources.srcDirs = ["$it.name/resources"]
        languageSettings {
            progressiveMode = true

            optIn("kotlin.ExperimentalMultiplatform")
            optIn("kotlin.ExperimentalStdlibApi")
            optIn("kotlinx.serialization.InternalSerializationApi")
        }
    }

    sourceSets {
        commonMain {
            dependencies {
                api 'org.jetbrains.kotlin:kotlin-stdlib-common'
            }
        }

        commonTest {
            dependencies {
                api 'org.jetbrains.kotlin:kotlin-test-common'
                api 'org.jetbrains.kotlin:kotlin-test-annotations-common'
            }
        }

        jvmMain {
            dependencies {
                api 'org.jetbrains.kotlin:kotlin-stdlib'
            }
        }

        jvmTest {
            dependencies {
                api 'org.jetbrains.kotlin:kotlin-test-junit'
            }
        }

        jsMain {
            dependencies {
                api 'org.jetbrains.kotlin:kotlin-stdlib-js'
            }
        }

        jsTest {
            dependencies {
                api 'org.jetbrains.kotlin:kotlin-test-js'
            }
        }

        create("wasmMain") {
            dependsOn(commonMain)
        }
        create("wasmTest") {
            dependsOn(commonTest)
        }

        wasmJsMain {
            dependsOn(wasmMain)
            dependencies {
                api 'org.jetbrains.kotlin:kotlin-stdlib-wasm-js'
            }
        }

        wasmJsTest {
            dependsOn(wasmTest)
            dependencies {
                api 'org.jetbrains.kotlin:kotlin-test-wasm-js'
            }
        }

        if (!isOkIoOrFormatTests) {
            wasmWasiMain {
                dependsOn(wasmMain)
                dependencies {
                    api 'org.jetbrains.kotlin:kotlin-stdlib-wasm-wasi'
                }
            }

            wasmWasiTest {
                dependsOn(wasmTest)
                dependencies {
                    api 'org.jetbrains.kotlin:kotlin-test-wasm-wasi'
                }
            }
        }

        nativeMain.dependencies {
        }
    }

    sourceSets.findAll({ it.name.contains("Test") }).forEach { srcSet ->
        srcSet.languageSettings {
            it.optIn("kotlinx.serialization.InternalSerializationApi")
            it.optIn("kotlinx.serialization.ExperimentalSerializationApi")
        }
    }

    sourceSets.matching({ it.name.contains("Main") }).all { srcSet ->
        project.ext.set("kotlin.mpp.freeCompilerArgsForSourceSet.${srcSet.name}", ["-Xexplicit-api=strict"])
    }

    targets.all {
        compilations.all {
            kotlinOptions {
                if (rootProject.ext.kotlin_lv_override != null) {
                    languageVersion = rootProject.ext.kotlin_lv_override
                    freeCompilerArgs += "-Xsuppress-version-warnings"
                }
                freeCompilerArgs += "-Xexpect-actual-classes"
            }
        }
        compilations.main {
            kotlinOptions {
                allWarningsAsErrors = true
            }
        }
    }

    def targetsWithoutTestRunners = ["linuxArm64", "linuxArm32Hfp"]
    configure(targets) {
        // Configure additional binaries to run tests in the background
        if (["macos", "linux", "mingw"].any { name.startsWith(it) && !targetsWithoutTestRunners.contains(name) }) {
            binaries {
                test("background", [nativeDebugBuild]) {
                    freeCompilerArgs += ["-trw"]
                }
            }
            testRuns {
                background { setExecutionSourceFrom(binaries.backgroundDebugTest) }
            }
        }
    }
}

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"
}