/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * This file was created using the `create_project.py` script located in the
 * `<AndroidX root>/development/project-creator` directory.
 *
 * Please use that script when creating a new project, rather than copying an existing project and
 * modifying its settings.
 */

import androidx.build.LibraryType
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.mpp.BitcodeEmbeddingMode
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkConfig
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
import org.jetbrains.kotlin.konan.target.Family

plugins {
    id("AndroidXPlugin")
    id("com.android.library")
    id("androidx.benchmark")
    id("androidx.benchmark.darwin")
}

androidXMultiplatform {
    android()

    // XCFrameworkConfig must always be called AndroidXDarwinBenchmarks
    def xcf = new XCFrameworkConfig(project, "AndroidXDarwinBenchmarks")
    ios {
        binaries.framework {
            // The module name must be AndroidXDarwinBenchmarks for the discovery to work.
            baseName = "AndroidXDarwinBenchmarks"
            // https://youtrack.jetbrains.com/issue/KT-48552
            embedBitcode = BitcodeEmbeddingMode.DISABLE
            export(project(":benchmark:benchmark-darwin"))
            xcf.add(it)
        }
    }

    sourceSets {
        commonMain {
            dependencies {
                implementation(project(":collection:collection"))
                implementation(libs.kotlinStdlib)
            }
        }

        commonTest {
            dependencies {
                implementation(project(":collection:collection"))
                implementation(libs.kotlinStdlib)
            }
        }

        androidInstrumentedTest {
            dependsOn(commonTest)
            dependencies {
                implementation(projectOrArtifact(":benchmark:benchmark-junit4"))
                implementation(libs.junit)
                implementation(libs.testExtJunit)
                implementation(libs.testCore)
                implementation(libs.testRunner)
                implementation(libs.testRules)
            }
        }

        darwinMain {
            dependsOn(commonMain)
            dependencies {
                api(project(":benchmark:benchmark-darwin"))
            }
        }

        targets.configureEach { target ->
            if (target.platformType == KotlinPlatformType.native) {
                target.compilations["main"].defaultSourceSet {
                    def konanTargetFamily = target.konanTarget.family
                    if (konanTargetFamily == Family.OSX || konanTargetFamily == Family.IOS) {
                        dependsOn(darwinMain)
                    } else {
                        throw new GradleException("unknown native target ${target}")
                    }
                }
                target.compilations.configureEach {
                    compilerOptions.options.optIn.add("kotlinx.cinterop.ExperimentalForeignApi")
                }
            }
        }

        // Workaround for https://youtrack.jetbrains.com/issue/KT-51763
        // Make sure commonization runs before any compilation task.
        tasks.withType(KotlinNativeCompile).configureEach {
            it.dependsOn(tasks.named("commonize"))
        }
    }
}

androidx {
    name = "Collections Benchmarks (Android / iOS)"
    type = LibraryType.BENCHMARK
    inceptionYear = "2022"
    description = "AndroidX Collections Benchmarks (Android / iOS)"
}

darwinBenchmark {
    xcodeGenConfigFile = project.rootProject.file(
            "benchmark/benchmark-darwin-xcode/projects/collection-benchmark-ios.yml"
    )
    xcodeProjectName = "collection-benchmark-ios"
    scheme = "testapp-ios"
    // To run locally switch to iOS 17.0 simulators
    destination = "platform=iOS Simulator,name=iPhone 13,OS=15.2"
    referenceSha.set(androidx.getReferenceSha())
}

android {
    namespace = "androidx.collection.benchmark"
    defaultConfig {
        minSdk = 22 // b/294570164
    }
}
