Daniel Santiago Rivera | 2a592e5 | 2023-09-15 13:47:53 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2023 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Daniel Santiago Rivera | 1461d46 | 2023-09-20 18:23:40 -0400 | [diff] [blame] | 17 | |
Daniel Santiago Rivera | 2a592e5 | 2023-09-15 13:47:53 -0400 | [diff] [blame] | 18 | import androidx.build.KmpPlatformsKt |
| 19 | import androidx.build.LibraryType |
Daniel Santiago Rivera | 1461d46 | 2023-09-20 18:23:40 -0400 | [diff] [blame] | 20 | import androidx.build.PlatformIdentifier |
Daniel Santiago Rivera | 2a592e5 | 2023-09-15 13:47:53 -0400 | [diff] [blame] | 21 | import androidx.build.Publish |
| 22 | import androidx.build.SdkHelperKt |
| 23 | import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType |
Andrei Shikov | b4902f3 | 2023-08-12 05:14:30 +0100 | [diff] [blame] | 24 | import org.jetbrains.kotlin.konan.target.KonanTarget |
Daniel Santiago Rivera | 2a592e5 | 2023-09-15 13:47:53 -0400 | [diff] [blame] | 25 | |
| 26 | plugins { |
| 27 | id("AndroidXPlugin") |
Daniel Santiago Rivera | 1461d46 | 2023-09-20 18:23:40 -0400 | [diff] [blame] | 28 | id("com.android.library") |
Daniel Santiago Rivera | 2a592e5 | 2023-09-15 13:47:53 -0400 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | def enableNative = KmpPlatformsKt.enableNative(project) |
| 32 | |
| 33 | androidXMultiplatform { |
Daniel Santiago Rivera | 1461d46 | 2023-09-20 18:23:40 -0400 | [diff] [blame] | 34 | android() |
Daniel Santiago Rivera | 2a592e5 | 2023-09-15 13:47:53 -0400 | [diff] [blame] | 35 | // TODO(b/300666074): Enable linux target once we can compile sqlite3.c |
| 36 | // linux() |
| 37 | mac() |
| 38 | ios() { |
| 39 | // Link to sqlite3 available in iOS |
| 40 | binaries.all { |
| 41 | linkerOpts += ["-lsqlite3"] |
| 42 | } |
| 43 | } |
| 44 | |
Daniel Santiago Rivera | 1461d46 | 2023-09-20 18:23:40 -0400 | [diff] [blame] | 45 | defaultPlatform(PlatformIdentifier.ANDROID) |
| 46 | |
Daniel Santiago Rivera | 2a592e5 | 2023-09-15 13:47:53 -0400 | [diff] [blame] | 47 | sourceSets { |
Daniel Santiago Rivera | 2a592e5 | 2023-09-15 13:47:53 -0400 | [diff] [blame] | 48 | commonMain { |
| 49 | dependencies { |
| 50 | implementation(libs.kotlinStdlib) |
| 51 | api(project(":sqliteMultiplatform:sqlite")) |
| 52 | } |
| 53 | } |
| 54 | commonTest { |
| 55 | dependencies { |
Daniel Santiago Rivera | 1461d46 | 2023-09-20 18:23:40 -0400 | [diff] [blame] | 56 | implementation(project(":sqliteMultiplatform:conformanceTest")) |
Daniel Santiago Rivera | 2a592e5 | 2023-09-15 13:47:53 -0400 | [diff] [blame] | 57 | implementation(libs.kotlinTest) |
| 58 | implementation(project(":kruth:kruth")) |
| 59 | } |
| 60 | } |
Daniel Santiago Rivera | 1461d46 | 2023-09-20 18:23:40 -0400 | [diff] [blame] | 61 | androidMain { |
| 62 | dependsOn(commonMain) |
| 63 | } |
| 64 | androidUnitTest { |
| 65 | dependsOn(commonTest) |
| 66 | dependencies { |
| 67 | implementation(libs.kotlinTestJunit) |
| 68 | implementation(libs.testRunner) |
| 69 | implementation(libs.testCore) |
| 70 | } |
| 71 | } |
| 72 | androidInstrumentedTest { |
| 73 | dependsOn(androidUnitTest) |
| 74 | } |
Daniel Santiago Rivera | 2a592e5 | 2023-09-15 13:47:53 -0400 | [diff] [blame] | 75 | if (enableNative) { |
| 76 | nativeMain { |
| 77 | dependsOn(commonMain) |
| 78 | } |
| 79 | nativeTest { |
| 80 | dependsOn(commonTest) |
| 81 | } |
| 82 | } |
| 83 | targets.all { target -> |
| 84 | if (target.platformType == KotlinPlatformType.native) { |
| 85 | def main = target.compilations["main"] |
| 86 | main.defaultSourceSet { |
| 87 | dependsOn(nativeMain) |
| 88 | } |
Daniel Santiago Rivera | 1461d46 | 2023-09-20 18:23:40 -0400 | [diff] [blame] | 89 | // For usage of sqlite3.h C APIs |
| 90 | // See: https://kotlinlang.org/docs/whatsnew19.html#explicit-c-interoperability-stability-guarantees |
| 91 | main.compilerOptions.options.optIn.add("kotlinx.cinterop.ExperimentalForeignApi") |
Daniel Santiago Rivera | 2a592e5 | 2023-09-15 13:47:53 -0400 | [diff] [blame] | 92 | main.cinterops { |
| 93 | sqlite3 { |
| 94 | def externalSQLiteDir = new File( |
| 95 | SdkHelperKt.getCheckoutRoot(project), |
| 96 | "/external/sqlite/dist/orig/" |
| 97 | ) |
| 98 | includeDirs(externalSQLiteDir) |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | def test = target.compilations["test"] |
| 103 | test.defaultSourceSet { |
| 104 | dependsOn(nativeTest) |
Andrei Shikov | b4902f3 | 2023-08-12 05:14:30 +0100 | [diff] [blame] | 105 | if (target.konanTarget != KonanTarget.LINUX_X64) { |
| 106 | // For tests in Mac host, link to shared library included in MacOS |
| 107 | test.kotlinOptions.freeCompilerArgs += [ |
| 108 | "-linker-options", "-lsqlite3" |
| 109 | ] |
| 110 | } |
Daniel Santiago Rivera | 2a592e5 | 2023-09-15 13:47:53 -0400 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
Daniel Santiago Rivera | 1461d46 | 2023-09-20 18:23:40 -0400 | [diff] [blame] | 117 | android { |
| 118 | namespace "androidx.sqliteMultiplatform.driver" |
| 119 | } |
| 120 | |
Daniel Santiago Rivera | 2a592e5 | 2023-09-15 13:47:53 -0400 | [diff] [blame] | 121 | androidx { |
| 122 | name = "SQLite KMP Implementation" |
| 123 | type = LibraryType.UNSET |
| 124 | inceptionYear = "2023" |
| 125 | description = "SQLite Kotlin Multiplatform Implementation" |
| 126 | publish = Publish.NONE |
| 127 | } |