-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathbuild.gradle
More file actions
354 lines (306 loc) · 11.6 KB
/
build.gradle
File metadata and controls
354 lines (306 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
import org.gradle.internal.jvm.Jvm
plugins {
id 'java-library'
id 'c'
id 'cpp'
id 'maven-publish'
id 'signing'
id 'com.diffplug.spotless' version '6.25.0'
}
group = "cloud.unum"
version = file("VERSION").text.trim()
java {
sourceCompatibility = JavaVersion.VERSION_18
targetCompatibility = JavaVersion.VERSION_18
}
repositories {
mavenCentral()
}
sourceSets {
main {
java {
srcDir "java/"
exclude "test/"
}
// Ensure native libraries are included in the main source set
resources {
srcDirs "$buildDir/libs"
include "usearch-native/**"
}
}
test {
java {
srcDir "java/test"
}
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier.set('sources')
from sourceSets.main.allSource
}
javadoc {
options.addStringOption('Xdoclint:all,-missing', '-quiet')
options.encoding = 'UTF-8'
options.charSet = 'UTF-8'
}
task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier.set('javadoc')
from javadoc.destinationDir
}
dependencies {
testImplementation('junit:junit:4.13.2')
}
spotless {
format 'gradle', {
target '*.gradle'
trimTrailingWhitespace()
indentWithSpaces(4)
endWithNewline()
}
// Use AOSP style but preserve Javadoc formatting
// java {
// target 'java/**/*.java'
// googleJavaFormat('1.17.0').aosp().skipJavadocFormatting()
// removeUnusedImports()
// trimTrailingWhitespace()
// endWithNewline()
// }
}
model {
components {
usearch(NativeLibrarySpec) {
baseName = "usearch_jni" // JNI library for Java bindings
sources {
cpp {
source {
srcDirs "java/cloud/unum/usearch"
include "**/*.cpp"
}
exportedHeaders {
srcDirs "include", "fp16/include", "simsimd/include", "${Jvm.current().javaHome}/include"
}
}
c {
source {
srcDirs "simsimd/c/"
include "**/*.c"
}
exportedHeaders {
srcDirs "simsimd/include"
}
}
}
binaries.withType(StaticLibraryBinarySpec) {
buildable = false
}
binaries.withType(SharedLibraryBinarySpec) {
cppCompiler.args '-DUSEARCH_USE_FP16LIB=1'
cppCompiler.args '-DUSEARCH_USE_SIMSIMD=1'
cppCompiler.args '-DSIMSIMD_DYNAMIC_DISPATCH=1'
cppCompiler.args '-DSIMSIMD_NATIVE_BF16=0'
cppCompiler.args '-DSIMSIMD_NATIVE_F16=0'
if (targetPlatform.operatingSystem.linux) {
cppCompiler.args '-I', "${Jvm.current().javaHome}/include/linux"
cppCompiler.args '-D_FILE_OFFSET_BITS=64'
cppCompiler.args '-std=c++17'
cppCompiler.args '-O2'
cppCompiler.args '-ffast-math'
cppCompiler.args '-Wno-unknown-pragmas'
// x86_64 targets for Linux CI
cppCompiler.args '-DSIMSIMD_TARGET_HASWELL=1'
cppCompiler.args '-DSIMSIMD_TARGET_SKYLAKE=1'
cppCompiler.args '-DSIMSIMD_TARGET_ICE=1'
cppCompiler.args '-DSIMSIMD_TARGET_GENOA=1'
cppCompiler.args '-DSIMSIMD_TARGET_SAPPHIRE=1'
cppCompiler.args '-DSIMSIMD_TARGET_TURIN=0'
cppCompiler.args '-DSIMSIMD_TARGET_SIERRA=0'
// ARM targets for Linux ARM64 builds
cppCompiler.args '-DSIMSIMD_TARGET_NEON=1'
cppCompiler.args '-DSIMSIMD_TARGET_NEON_BF16=1'
cppCompiler.args '-DSIMSIMD_TARGET_NEON_F16=1'
cppCompiler.args '-DSIMSIMD_TARGET_NEON_I8=1'
cppCompiler.args '-DSIMSIMD_TARGET_SVE=1'
cppCompiler.args '-DSIMSIMD_TARGET_SVE_BF16=1'
cppCompiler.args '-DSIMSIMD_TARGET_SVE_F16=1'
cppCompiler.args '-DSIMSIMD_TARGET_SVE_I8=1'
cppCompiler.args '-DSIMSIMD_TARGET_SVE2=1'
} else if (targetPlatform.operatingSystem.macOsX) {
cppCompiler.args '-I', "${Jvm.current().javaHome}/include/darwin"
cppCompiler.args '-D_FILE_OFFSET_BITS=64'
cppCompiler.args '-mmacosx-version-min=10.15'
cppCompiler.args '-std=c++17'
cppCompiler.args '-O2'
cppCompiler.args '-ffast-math'
cppCompiler.args '-Wno-unknown-pragmas'
// ARM targets for Apple Silicon (M1/M2/M3/M4)
cppCompiler.args '-DSIMSIMD_TARGET_NEON=1'
cppCompiler.args '-DSIMSIMD_TARGET_NEON_BF16=1'
cppCompiler.args '-DSIMSIMD_TARGET_NEON_F16=1'
cppCompiler.args '-DSIMSIMD_TARGET_NEON_I8=1'
// x86_64 targets for Intel Macs
cppCompiler.args '-DSIMSIMD_TARGET_HASWELL=1'
} else if (targetPlatform.operatingSystem.windows) {
cppCompiler.args "-I${Jvm.current().javaHome}/include/win32"
cppCompiler.args '/std:c++17'
cppCompiler.args '/O2'
cppCompiler.args '/fp:fast'
cppCompiler.args '/W1'
} else if (targetPlatform.name.contains("android")) {
// Android support - similar to macOS ARM settings
cppCompiler.args '-std=c++17'
cppCompiler.args '-O2'
cppCompiler.args '-ffast-math'
cppCompiler.args '-Wno-unknown-pragmas'
// ARM targets for Android devices
cppCompiler.args '-DSIMSIMD_TARGET_NEON=1'
cppCompiler.args '-DSIMSIMD_TARGET_NEON_BF16=1'
cppCompiler.args '-DSIMSIMD_TARGET_NEON_F16=1'
cppCompiler.args '-DSIMSIMD_TARGET_NEON_I8=1'
}
}
}
}
toolChains {
clang(Clang)
gcc(Gcc) {
target("linux_aarch64") {
cppCompiler.withArguments { args ->
args << "-march=armv8-a"
}
}
}
}
}
test {
forkEvery = 1
dependsOn jar
// Rearrange test classpath, add compiled JAR instead of main classes
classpath = project.sourceSets.test.output + configurations.testRuntimeClasspath + files(jar.archiveFile)
// Enable detailed test logging
testLogging {
// Ensure that we get output from all tests, not just failing ones
showStandardStreams = true
exceptionFormat = 'full' // Can be 'short', 'full', or 'summary'
// More detailed test result logging
events "passed", "skipped", "failed"
}
}
jar {
dependsOn("usearchSharedLibrary")
// Include all native libraries with their platform-specific directory structure
from("$buildDir/libs/usearch/shared") {
include "**/*"
into "usearch-native"
}
from sourceSets.main.output
}
// Separate task for creating a fat JAR with all platform native libraries
// This is used in CI/CD where we pre-download all platform libraries
task fatJar(type: Jar) {
archiveClassifier = ''
archiveBaseName = 'usearch'
from sourceSets.main.output
// Include pre-built native libraries from all platforms
from("build/libs/usearch/shared") {
include "**/*"
into "usearch-native"
}
manifest {
attributes 'Implementation-Title': 'USearch',
'Implementation-Version': version
}
// Log what we're packaging for transparency
doFirst {
def nativeDir = file("build/libs/usearch/shared")
println "Looking for native libraries in: ${nativeDir.absolutePath}"
println "Directory exists: ${nativeDir.exists()}"
if (nativeDir.exists()) {
def platforms = []
nativeDir.eachDir { platforms.add(it.name) }
println "Found ${platforms.size()} platform directories: ${platforms}"
if (platforms.size() > 0) {
println "Packaging native libraries for platforms: ${platforms.join(', ')}"
} else {
println "ERROR: Native library directory exists but contains no platform subdirectories"
println "Directory contents:"
nativeDir.eachFile { println " - ${it.name} (${it.isDirectory() ? 'dir' : 'file'})" }
throw new GradleException("No platform directories found in build/libs/usearch/shared")
}
} else {
throw new GradleException("Native libraries directory not found at build/libs/usearch/shared - ensure native libraries are downloaded first")
}
}
}
signing {
def signingKey = findProperty("signingKey")
def signingPassword = findProperty("signingPassword")
useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications
}
publishing {
publications {
library(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
signing {
sign publishing.publications.library
}
pom {
name = "USearch"
description = "Smaller & Faster Single-File Vector Search Engine from Unum"
url = "https://github.com/unum-cloud/usearch"
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
scm {
connection = 'scm:git:git://github.com/unum-cloud/usearch.git'
developerConnection = 'scm:git:ssh://github.com/unum-cloud/usearch.git'
url = 'https://github.com/unum-cloud/usearch'
}
developers {
developer {
id = 'ashvardanian'
name = 'Ash Vardanian'
email = 'ash.vardanian@unum.cloud'
}
}
}
}
}
// Maven Central via central.sonatype.com would be great, but it doesn't support Gradle yet :(
// Info: https://central.sonatype.org/publish/publish-portal-gradle/
/*
repositories {
maven {
name = "MavenCentral"
url = "https://central.sonatype.com/api/v1/publisher/upload"
credentials {
username = System.getenv("MAVEN_CENTRAL_USERNAME")
password = System.getenv("MAVEN_CENTRAL_TOKEN")
}
authentication {
basic(BasicAuthentication)
}
}
}
*/
repositories {
maven {
name = "GitHubPackages"
url = "https://maven.pkg.github.com/unum-cloud/usearch"
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}
// Ensure that the native library is built before the Java code
compileJava.dependsOn tasks.withType(SharedLibraryBinarySpec)
tasks.named("processResources").configure {
dependsOn tasks.named("linkUsearchSharedLibrary")
}