[go: nahoru, domu]

blob: c9c4e2ed43e62faba22446e96ce8032b4aa02cd0 [file] [log] [blame]
Daniel Santiago Rivera2a592e52023-09-15 13:47:53 -04001/*
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 Rivera1461d462023-09-20 18:23:40 -040017
Daniel Santiago Rivera2a592e52023-09-15 13:47:53 -040018import androidx.build.KmpPlatformsKt
19import androidx.build.LibraryType
Daniel Santiago Rivera1461d462023-09-20 18:23:40 -040020import androidx.build.PlatformIdentifier
Daniel Santiago Rivera2a592e52023-09-15 13:47:53 -040021import androidx.build.Publish
22import androidx.build.SdkHelperKt
23import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
Andrei Shikovb4902f32023-08-12 05:14:30 +010024import org.jetbrains.kotlin.konan.target.KonanTarget
Daniel Santiago Rivera2a592e52023-09-15 13:47:53 -040025
26plugins {
27 id("AndroidXPlugin")
Daniel Santiago Rivera1461d462023-09-20 18:23:40 -040028 id("com.android.library")
Daniel Santiago Rivera2a592e52023-09-15 13:47:53 -040029}
30
31def enableNative = KmpPlatformsKt.enableNative(project)
32
33androidXMultiplatform {
Daniel Santiago Rivera1461d462023-09-20 18:23:40 -040034 android()
Daniel Santiago Rivera2a592e52023-09-15 13:47:53 -040035 // 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 Rivera1461d462023-09-20 18:23:40 -040045 defaultPlatform(PlatformIdentifier.ANDROID)
46
Daniel Santiago Rivera2a592e52023-09-15 13:47:53 -040047 sourceSets {
Daniel Santiago Rivera2a592e52023-09-15 13:47:53 -040048 commonMain {
49 dependencies {
50 implementation(libs.kotlinStdlib)
51 api(project(":sqliteMultiplatform:sqlite"))
52 }
53 }
54 commonTest {
55 dependencies {
Daniel Santiago Rivera1461d462023-09-20 18:23:40 -040056 implementation(project(":sqliteMultiplatform:conformanceTest"))
Daniel Santiago Rivera2a592e52023-09-15 13:47:53 -040057 implementation(libs.kotlinTest)
58 implementation(project(":kruth:kruth"))
59 }
60 }
Daniel Santiago Rivera1461d462023-09-20 18:23:40 -040061 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 Rivera2a592e52023-09-15 13:47:53 -040075 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 Rivera1461d462023-09-20 18:23:40 -040089 // 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 Rivera2a592e52023-09-15 13:47:53 -040092 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 Shikovb4902f32023-08-12 05:14:30 +0100105 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 Rivera2a592e52023-09-15 13:47:53 -0400111 }
112 }
113 }
114 }
115}
116
Daniel Santiago Rivera1461d462023-09-20 18:23:40 -0400117android {
118 namespace "androidx.sqliteMultiplatform.driver"
119}
120
Daniel Santiago Rivera2a592e52023-09-15 13:47:53 -0400121androidx {
122 name = "SQLite KMP Implementation"
123 type = LibraryType.UNSET
124 inceptionYear = "2023"
125 description = "SQLite Kotlin Multiplatform Implementation"
126 publish = Publish.NONE
127}