-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild.gradle
291 lines (243 loc) · 7.95 KB
/
build.gradle
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
buildscript {
ext {
kotlin_version = '1.4.21'
}
}
plugins {
id "org.jetbrains.dokka" version "1.4.10.2"
id "org.jetbrains.kotlin.jvm" version "$kotlin_version"
}
apply plugin: 'cpp'
apply plugin: 'kotlin'
apply plugin: 'maven'
apply plugin: 'org.jetbrains.dokka'
apply plugin: 'signing'
apply from: "$rootDir/gradle/jni-headers.gradle"
apply from: "$rootDir/gradle/boost-simd.gradle"
apply from: "$rootDir/gradle/disable-static.gradle"
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions {
languageVersion = "1.4"
}
}
model {
platforms {
linux {
operatingSystem 'linux'
}
osx {
operatingSystem 'osx'
}
windows {
operatingSystem 'windows'
}
}
toolChains {
visualCpp(VisualCpp) {
/* this is not pretty, but:
1. Gradle currently doesn't always play nice with Visual Studio 2017
2. Gradle currently doesn't have any other way to specify Visual Studio version
3. Without "file://", the build script causes exceptions on Linux, since it tries to convert
this string to Unix path, which leads to a problem with spaces. */
installDir "file://C:/Program Files (x86)/Microsoft Visual Studio 14.0"
}
gcc(Gcc)
clang(Clang)
}
components {
loader(NativeLibrarySpec) {
sources {
cpp.lib library: 'jniHeaders', linkage: 'api'
}
targetPlatform 'linux'
targetPlatform 'windows'
targetPlatform 'osx'
binaries.withType(SharedLibraryBinarySpec) {
def libraryName = System.mapLibraryName('simd.x86_64')
sharedLibraryFile = file("$buildDir/libs/$libraryName")
}
}
simd(NativeLibrarySpec) {
sources {
cpp.lib library: 'boostSimd', linkage: 'api'
cpp.lib library: 'jniHeaders', linkage: 'api'
}
flavors {
sse2
avx
}
targetPlatform 'linux'
targetPlatform 'windows'
targetPlatform 'osx'
targetFlavors 'sse2', 'avx'
binaries.withType(SharedLibraryBinarySpec) {
switch (flavor) {
case flavors.sse2: if (targetPlatform == 'windows') {
cppCompiler.args '/arch:SSE2'
} else {
cppCompiler.args '-msse2'
}; break
case flavors.avx: if (targetPlatform == 'windows') {
cppCompiler.args '/arch:AVX'
} else {
cppCompiler.args '-mavx'
}; break
}
def libraryName = System.mapLibraryName("simd.${flavor.name}.x86_64")
sharedLibraryFile = file("$buildDir/libs/$libraryName")
}
}
}
components {
all {
binaries.all {
cppCompiler.define 'BOOST_DISABLE_ASSERTS'
cppCompiler.define 'NDEBUG'
if (toolChain in Gcc) {
cppCompiler.args('-std=c++11', '-fno-rtti', '-fno-exceptions',
'-O3', '-Wno-narrowing')
}
if (toolChain in VisualCpp) {
cppCompiler.args('/GR-', '/O2')
}
if (toolChain in Clang) {
cppCompiler.args('-stdlib=libc++', '-std=c++1y')
}
}
}
}
tasks {
buildAllVariants(Task) {
dependsOn $.binaries.findAll { it.buildable }
}
}
}
task jniHeaders(dependsOn: compileKotlin) {
def outputDir = file("$buildDir/include")
def jniClasses = [
'org.jetbrains.bio.viktor.NativeSpeedups',
'org.jetbrains.bio.viktor.LoaderKt'
]
def jniHeaders = jniClasses.collect {
new File(outputDir, it.replace('.', '_') + '.hpp')
}
inputs.files sourceSets.main.output
outputs.files jniHeaders
doLast {
outputDir.mkdirs()
[jniClasses, jniHeaders].transpose().each(javah)
}
}
tasks.withType(CppCompile) {
dependsOn 'jniHeaders'
dependsOn 'installBoostSimd'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile 'org.apache.commons:commons-math3:3.6'
compile "org.jetbrains.bio:npy:0.3.5"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
testCompile 'junit:junit:4.12'
testCompile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.25'
}
dokkaJavadoc {
outputDirectory = javadoc.destinationDir
inputs.dir 'src/main/kotlin'
}
test {
dependsOn 'buildAllVariants'
systemProperty 'java.library.path', "$buildDir/libs"
}
apply plugin: 'idea'
idea {
module {
name = 'viktor'
}
}
jar {
archivesBaseName = 'viktor'
dependsOn 'buildAllVariants'
from "$buildDir/libs"
exclude '*.jar'
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: dokkaJavadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar, javadocJar
}
signing {
// multiline environment variables are not fun.
def signingKey = findProperty("signingKey")?.replace("\\n", "\n")
def signingPassword = findProperty("signingPassword")
useInMemoryPgpKeys(signingKey, signingPassword)
sign configurations.archives
}
uploadArchives {
doFirst {
assert file("./build/libs/libsimd.x86_64.so").exists()
assert file("./build/libs/libsimd.x86_64.dylib").exists()
assert file("./build/libs/simd.x86_64.dll").exists()
}
repositories {
mavenDeployer {
def ossrhUsername = findProperty("ossrhUsername")
def ossrhPassword = findProperty("ossrhPassword")
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.groupId = 'org.jetbrains.bio'
pom.project {
name 'viktor'
packaging 'jar'
// optionally artifactId can be defined here
description 'Efficient f64-only ndarray in Kotlin'
url 'https://github.com/JetBrains-Research/viktor'
scm {
connection 'scm:git:[email protected]:JetBrains-Research/viktor.git'
developerConnection 'scm:git:[email protected]:JetBrains-Research/viktor.git'
url 'https://github.com/JetBrains-Research/viktor'
}
licenses {
license {
name 'MIT License'
url 'https://github.com/JetBrains-Research/viktor/blob/master/LICENSE'
}
}
developers {
developer {
id 'dievsky'
name 'Aleksei Dievskii'
email '[email protected]'
}
developer {
id 'slebedev'
name 'Sergei Lebedev'
email '[email protected]'
}
}
}
}
}
}
wrapper {
gradleVersion = '6.5'
}