33import com.vanniktech.maven.publish.SonatypeHost
44import org.gradle.configurationcache.extensions.capitalized
55import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
6+ import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
67import org.jetbrains.kotlin.gradle.tasks.CInteropProcess
78import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
9+ import org.jetbrains.kotlin.konan.target.KonanTarget
10+ import java.util.Properties
811
912plugins {
1013 kotlin(" multiplatform" )
1114 `maven- publish`
15+ id(" com.android.library" )
1216 id(" org.jetbrains.dokka" )
1317 id(" com.vanniktech.maven.publish" )
1418}
1519
1620group = " com.martmists.ndarray-simd"
17- version = " 1.4.4 "
21+ version = " 1.5.0 "
1822val isProduction = (findProperty(" production" ) ? : System .getProperty(" production" )) != null
1923
2024repositories {
25+ google()
2126 mavenCentral()
2227}
2328
29+ android {
30+ compileSdk = 35
31+ namespace = group.toString().replace(' -' , ' .' )
32+ ndkVersion = " 21.4.7075529"
33+
34+ sourceSets {
35+ getByName(" debug" ).jniLibs.srcDirs(project.layout.buildDirectory.dir(" generated/jni/Debug" ))
36+ getByName(" release" ).jniLibs.srcDirs(project.layout.buildDirectory.dir(" generated/jni/Release" ))
37+ }
38+ }
39+
2440kotlin {
2541 jvmToolchain(21 )
2642
2743 withSourcesJar()
2844
29- jvm()
45+ androidTarget {
46+ publishLibraryVariants(" release" , " debug" )
47+ }
48+ jvm(" desktop" )
3049
3150 val natives = if (isProduction) {
3251 listOf (
@@ -39,6 +58,9 @@ kotlin {
3958 // Feel free to open a PR
4059// macosX64(),
4160// macosArm64(),
61+
62+ androidNativeArm64(),
63+ androidNativeX64(),
4264 )
4365 } else {
4466 when (val osArch = System .getProperty(" os.arch" )) {
@@ -58,26 +80,42 @@ kotlin {
5880 }
5981 }
6082
83+ applyDefaultHierarchyTemplate()
84+
6185 for (native in natives) {
6286 native.apply {
6387 binaries {
6488 sharedLib {
6589 baseName = " ndarray_simd"
90+
91+ if (native.targetName.startsWith(" android" )) {
92+ linkTaskProvider.configure {
93+ doLast {
94+ copy {
95+ from(outputFile)
96+
97+ val typeName = if (buildType == NativeBuildType .DEBUG ) " Debug" else " Release"
98+ val abiDirName = when (this @sharedLib.target.konanTarget) {
99+ KonanTarget .ANDROID_ARM32 -> " armeabi-v7a"
100+ KonanTarget .ANDROID_ARM64 -> " arm64-v8a"
101+ KonanTarget .ANDROID_X86 -> " x86"
102+ KonanTarget .ANDROID_X64 -> " x86_64"
103+ else -> " unknown"
104+ }
105+
106+ into(project.layout.buildDirectory.dir(" generated/jni/$typeName /$abiDirName " ))
107+ }
108+ }
109+ }
110+
111+ afterEvaluate {
112+ tasks.getByName(" preBuild" ).dependsOn(linkTaskProvider)
113+ }
114+ }
66115 }
67116 }
68117
69118 compilations.named(" main" ) {
70- val jni by cinterops.creating {
71- val javaHome = File (System .getProperty(" java.home" )!! )
72- defFile(projectDir.resolve(" src/nativeMain/cinterops/jni.def" ))
73- includeDirs(
74- javaHome.resolve(" include" ),
75- javaHome.resolve(" include/linux" ),
76- javaHome.resolve(" include/darwin" ),
77- javaHome.resolve(" include/win32" ),
78- )
79- }
80-
81119 val simd by cinterops.creating {
82120 defFile(projectDir.resolve(" src/nativeMain/cinterops/simd.def" ))
83121 includeDirs(
@@ -198,25 +236,43 @@ kotlin {
198236 dependsOn(arTask)
199237 }
200238 }
239+
240+ if (! native.targetName.startsWith(" android" )) {
241+ val jni by cinterops.creating {
242+ val javaHome = File (System .getProperty(" java.home" )!! )
243+ defFile(projectDir.resolve(" src/desktopNativeMain/cinterops/jni.def" ))
244+
245+ includeDirs(
246+ javaHome.resolve(" include" ),
247+ javaHome.resolve(" include/linux" ),
248+ javaHome.resolve(" include/darwin" ),
249+ javaHome.resolve(" include/win32" ),
250+ )
251+ }
252+ }
201253 }
202254 }
203255 }
204256
205257 sourceSets {
206- commonTest {
258+ val commonMain by getting
259+
260+ val commonTest by getting {
207261 dependencies {
208262 api(kotlin(" test" ))
209263 }
210264 }
211265
212- jvmMain {
266+ val jvmMain by creating {
267+ dependsOn(commonMain)
268+
213269 dependencies {
214270 // Compat: OpenCV
215271 compileOnly(" org.openpnp:opencv:4.9.0-0" )
216272
217273 // Compat: Exposed+PGVector
218274 compileOnly(" com.pgvector:pgvector:0.1.6" )
219- compileOnly(" org.jetbrains.exposed:exposed-core:0.52 .0" )
275+ compileOnly(" org.jetbrains.exposed:exposed-core:0.60 .0" )
220276
221277 // Compat: Image Formats
222278 compileOnly(" com.sksamuel.scrimage:scrimage-core:4.1.3" )
@@ -226,18 +282,50 @@ kotlin {
226282 compileOnly(" dev.langchain4j:langchain4j:0.32.0" )
227283
228284 // Compat: kotlinx.dataframe
229- compileOnly(" org.jetbrains.kotlinx:dataframe:0.13.1" )
285+ compileOnly(" org.jetbrains.kotlinx:dataframe-core :0.13.1" )
230286 }
231287 }
232288
233- jvmTest {
289+ val jvmTest by creating {
290+ dependsOn(commonTest)
291+
234292 dependencies {
235- runtimeOnly(" org.openpnp:opencv:4.9.0-0" )
236- runtimeOnly(" com.sksamuel.scrimage:scrimage-core:4.1.3" )
237- runtimeOnly(" dev.langchain4j:langchain4j:0.32.0" )
238- runtimeOnly(" org.jetbrains.kotlinx:dataframe:0.13.1" )
293+ implementation(" org.openpnp:opencv:4.9.0-0" )
294+ implementation(" com.sksamuel.scrimage:scrimage-core:4.1.3" )
295+ implementation(" dev.langchain4j:langchain4j:0.32.0" )
296+ implementation(" org.jetbrains.kotlinx:dataframe-core:0.13.1" )
297+ }
298+ }
299+
300+ val androidMain by getting {
301+ dependsOn(jvmMain)
302+ }
303+
304+ val desktopMain by getting {
305+ dependsOn(jvmMain)
306+ }
307+
308+ val nativeMain by getting
309+
310+ val desktopNativeMain by creating {
311+ dependsOn(nativeMain)
312+ }
313+
314+ for (native in natives) {
315+ if (! native.targetName.startsWith(" android" )) {
316+ named(" ${native.targetName} Main" ) {
317+ dependsOn(desktopNativeMain)
318+ }
239319 }
240320 }
321+
322+ // val androidUnitTest by getting {
323+ // dependsOn(jvmTest)
324+ // }
325+
326+ val desktopTest by getting {
327+ dependsOn(jvmTest)
328+ }
241329 }
242330}
243331
@@ -255,14 +343,23 @@ tasks {
255343 }
256344 }
257345
258- val jvmProcessResources by existing(Copy ::class ) {
346+ afterEvaluate {
347+ named(" testDebugUnitTest" ) {
348+ enabled = false
349+ }
350+ named(" testReleaseUnitTest" ) {
351+ enabled = false
352+ }
353+ }
354+
355+ val desktopProcessResources by existing(Copy ::class ) {
259356 val binaryName = if (isProduction) {
260357 " releaseShared"
261358 } else {
262359 " debugShared"
263360 }
264361
265- for (native in kotlin.targets.withType<KotlinNativeTarget >()) {
362+ for (native in kotlin.targets.withType<KotlinNativeTarget >().filter { ! it.name.startsWith( " android " ) } ) {
266363 into(" META-INF/natives/${native.targetName} " ) {
267364 from(named(native.binaries.getByName(binaryName).linkTaskName)) {
268365 exclude(" **/*.h" )
@@ -340,7 +437,7 @@ if (isProduction) {
340437
341438 mavenPublishing {
342439 publishToMavenCentral(SonatypeHost .CENTRAL_PORTAL , automaticRelease = true )
343- coordinates(group as String , name, releaseVersion)
440+ coordinates(group.toString() , name, releaseVersion)
344441 signAllPublications()
345442
346443 pom {
0 commit comments