-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
399 lines (366 loc) · 10.6 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
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
plugins {
id "com.diffplug.spotless" version "7.0.1"
id 'java'
id 'maven-publish'
id 'signing'
id 'eclipse'
id 'idea'
id 'jacoco'
id "com.github.jakemarsden.git-hooks" version "0.0.2"
id 'net.researchgate.release' version '3.1.0'
id 'me.champeau.gradle.japicmp' version '0.4.5'
id 'de.undercouch.download' version "5.6.0"
}
apply plugin: "java-library"
release {
tagTemplate = 'v${version}'
git {
requireBranch.set('master')
signTag.set(true)
}
}
allprojects {
apply plugin: "java"
apply plugin: "com.diffplug.spotless"
java {
sourceCompatibility = targetCompatibility = JavaLanguageVersion.of(22)
}
repositories {
mavenCentral()
}
spotless {
java {
target '**/*.java'
targetExclude "${project.buildDir}/**/*.java"
licenseHeader '/*\n * Copyright (c) $YEAR James Yuzawa (https://www.jyuzawa.com/)\n * SPDX-License-Identifier: MIT\n */'
removeUnusedImports()
importOrder()
palantirJavaFormat()
endWithNewline()
}
format 'misc', {
target '**/*.gradle'
trimTrailingWhitespace()
indentWithTabs()
endWithNewline()
}
format 'proto', {
target '**/*.proto'
trimTrailingWhitespace()
indentWithSpaces(2)
endWithNewline()
}
format 'md', {
target '**/*.md'
trimTrailingWhitespace()
endWithNewline()
}
}
}
gitHooks {
hooks = ['pre-push': 'spotlessCheck']
}
jacoco {
}
jacocoTestReport {
reports {
xml.required = true
html.required = true
}
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: "com/jyuzawa/onnxruntime_extern/**")
}))
}
}
description = "A Java binding of Microsoft's ONNX Runtime project."
// NOTE: to bump ORT version, update gradle.properties then run `./gradlew clean jextractClean jextract`
def ORT_VERSION = project.findProperty('com.jyuzawa.onnxruntime.library_version')
def ORT_BASELINE = project.findProperty('com.jyuzawa.onnxruntime.library_baseline')
// NOTE: if the baseline is a snapshot then the other artifacts need to be snapshots in order to be uploaded
def ORT_JAR_VERSION = ORT_BASELINE.endsWith('-SNAPSHOT') ? "${ORT_VERSION}-SNAPSHOT" : ORT_VERSION
// NOTE: publish tasks are: publishOnnxruntimeCpuPublicationToMavenRepository publishOnnxruntimeGpuPublicationToMavenRepository
def getGitHash = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}
def jarAttributes = [
'Built-By' : System.properties['user.name'],
'Build-Timestamp' : new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()),
'Specification-Vendor' : 'yuzawa-san',
'Specification-Title' : project.name,
'Specification-Version' : project.version,
'Implementation-Vendor' : 'yuzawa-san',
'Implementation-Title' : project.name,
'Implementation-Version' : "${-> getGitHash()}",
'Onnxruntime-Version' : ORT_VERSION,
'Created-By' : "Gradle ${gradle.gradleVersion}",
'Build-Jdk' : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
'Build-OS' : "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}"
]
java {
withJavadocJar()
withSourcesJar()
}
def cpuOsArches = ["linux-x86_64", "linux-aarch_64", "windows-x86_64", "windows-aarch_64", "osx-x86_64", "osx-aarch_64"]
def gpuOsArches = ["linux-x86_64-gpu", "windows-x86_64-gpu"]
def allArches = cpuOsArches + gpuOsArches
allArches.each { osArch ->
def osArchRoot = "${project.buildDir}/onnxruntime-${ORT_VERSION}/${osArch}"
task "download${osArch}" (type: Exec) {
outputs.cacheIf { true }
inputs.property('ortVersion', ORT_VERSION)
inputs.property('osArch', osArch)
inputs.file('./download.sh')
environment('ORT_VERSION', ORT_VERSION)
environment('VARIANT', osArch)
commandLine 'sh','./download.sh'
outputs.dir("${osArchRoot}/include")
outputs.dir("${osArchRoot}/assembly")
}
task "copy${osArch}" (type: Copy) {
dependsOn tasks.named("download${osArch}")
from "${osArchRoot}/assembly"
into "${project.buildDir}/dst/${osArch}"
}
task "osArchJar${osArch}" (type: Jar) {
from tasks.named("copy${osArch}")
archiveBaseName = osArch.endsWith("-gpu") ? "onnxruntime-gpu" : "onnxruntime-cpu"
archiveClassifier = osArch.replace("-gpu","")
archiveVersion = ORT_JAR_VERSION
doFirst {
manifest {
attributes(jarAttributes)
}
}
from ("${project.projectDir}/src/dist")
from ("${osArchRoot}/LICENSE") {
rename "LICENSE", "LICENSE.onnxruntime.txt"
into "META-INF/licenses/"
}
}
}
task "cpuJar" (type: Jar) {
archiveBaseName = "onnxruntime-cpu"
archiveVersion = ORT_JAR_VERSION
doFirst {
manifest {
attributes(jarAttributes)
}
}
}
task "gpuJar" (type: Jar) {
archiveBaseName = "onnxruntime-gpu"
archiveVersion = ORT_JAR_VERSION
doFirst {
manifest {
attributes(jarAttributes)
}
}
}
def compatibleVersion = project.findProperty('compatibleVersion') ?: 'SKIP'
task downloadBaseline(type: Download) {
onlyIf {
if (project.gradle.startParameter.isOffline()) {
println "Offline: skipping downloading of baseline and JAPICMP"
return false
}
else if ("$compatibleVersion" == "SKIP") {
println "SKIP: Instructed to skip the baseline comparison"
return false
}
else {
println "Will download and perform baseline comparison with ${compatibleVersion}"
return true
}
}
onlyIfNewer true
compress true
src "${repositories.mavenCentral().url}com/jyuzawa/onnxruntime/$compatibleVersion/onnxruntime-${compatibleVersion}.jar"
dest "${buildDir}/baselineLibs/onnxruntime-${compatibleVersion}.jar"
}
tasks.register("japicmp", me.champeau.gradle.japicmp.JapicmpTask) {
onlyIf { "$compatibleVersion" != "SKIP" }
oldClasspath.from(files("${buildDir}/baselineLibs/onnxruntime-${compatibleVersion}.jar"))
newClasspath.from(tasks.named('jar'))
packageExcludes = ['com.jyuzawa.onnxruntime_extern']
onlyModified = true
failOnModification = true
txtOutputFile = layout.buildDirectory.file("reports/japi.txt")
}
tasks.japicmp.dependsOn(downloadBaseline)
tasks.check.dependsOn(japicmp)
// TODO: enable jextract
task jextract(type: Exec) {
environment('ORT_VERSION', ORT_VERSION)
commandLine 'sh','./jextract.sh'
dependsOn tasks.named("downloadlinux-x86_64-gpu")
dependsOn tasks.named("downloadosx-x86_64")
finalizedBy tasks.named('spotlessJavaApply')
// TODO: enable jextract
// outputs.dir("${project.buildDir}/generated/source/jextract")
}
// TODO: enable jextract
//compileJava.dependsOn(jextract)
configurations {
cpu {
cpuOsArches.each {
outgoing.artifact(tasks.named("osArchJar${it}"))
}
}
}
components.java {
}
def makePom(node, osArches, theVersion, theBaseline) {
def parentNode = node.appendNode('parent')
parentNode.appendNode('groupId', project.group)
parentNode.appendNode('artifactId', project.name)
parentNode.appendNode('version', theBaseline)
def dependenciesNode = node.appendNode('dependencies')
def mainDependency = dependenciesNode.appendNode('dependency')
mainDependency.appendNode('groupId', project.group)
mainDependency.appendNode('artifactId', project.name)
mainDependency.appendNode('version', theBaseline)
osArches.each {
def dependency = dependenciesNode.appendNode('dependency')
dependency.appendNode('groupId', '${project.groupId}')
dependency.appendNode('artifactId', '${project.artifactId}')
dependency.appendNode('version', '${project.version}')
dependency.appendNode('classifier', it)
}
}
project.group = "com.jyuzawa"
def REPO = "yuzawa-san/onnxruntime-java"
publishing {
repositories {
maven {
name = 'Maven'
url = uri(version.endsWith('-SNAPSHOT') ? 'https://s01.oss.sonatype.org/content/repositories/snapshots/' : 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/')
credentials {
username = project.findProperty("ossrhUsername")
password = project.findProperty("ossrhPassword")
}
}
}
publications {
onnxruntimeCpu(MavenPublication) {
version = ORT_JAR_VERSION
artifactId = "${rootProject.name}-cpu"
pom.withXml {
makePom(asNode(), cpuOsArches, ORT_JAR_VERSION, ORT_BASELINE)
}
artifact tasks.named("cpuJar")
cpuOsArches.each {
artifact tasks.named("osArchJar${it}")
}
}
/*
onnxruntimeGpu(MavenPublication) {
version = ORT_JAR_VERSION
artifactId = "${rootProject.name}-gpu"
pom.withXml {
makePom(asNode(), gpuOsArches, ORT_JAR_VERSION, ORT_BASELINE)
}
artifact tasks.named("gpuJar")
gpuOsArches.each {
artifact tasks.named("osArchJar${it}")
}
}
*/
onnxruntime(MavenPublication) {
from components.java
pom {
name = 'ONNX Runtime for Java'
inceptionYear = '2022'
description = project.description
url = "https://github.com/${REPO}"
issueManagement {
url = "https://github.com/${REPO}/issues"
system = "GitHub Issues"
}
licenses {
license {
name = 'MIT License'
url = 'https://opensource.org/licenses/MIT'
distribution = 'repo'
}
}
developers {
developer {
id = 'yuzawa-san'
name = 'James Yuzawa'
email = '[email protected]'
}
}
scm {
connection = "scm:git:git://github.com/${REPO}.git"
developerConnection = "scm:git:[email protected]:${REPO}.git"
url = "https://github.com/${REPO}"
}
}
}
}
}
afterReleaseBuild.dependsOn tasks.named('publishOnnxruntimePublicationToMavenRepository')
signing {
sign publishing.publications
}
dependencies {
implementation platform('org.junit:junit-bom:5.11.4')
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
testImplementation project(':onnx')
testRuntimeOnly 'org.apache.logging.log4j:log4j-core:2.24.3'
testRuntimeOnly 'org.apache.logging.log4j:log4j-jpl:2.24.3'
}
sourceSets {
main {
java {
// TODO: enable jextract
// srcDirs jextract
}
}
test {
resources {
cpuOsArches.each { osArch ->
srcDir tasks.named("copy${osArch}")
}
}
}
}
java {
modularity.inferModulePath = true
}
javadoc {
}
javadoc.options {
addStringOption('-release', '22')
}
def moduleName = "com.jyuzawa.onnxruntime"
jar {
doFirst {
manifest {
attributes(jarAttributes)
}
}
from ("${project.projectDir}/LICENSE") {
into "META-INF/"
}
into("META-INF/maven/$project.group/$project.name") {
from { generatePomFileForOnnxruntimePublication }
rename ".*", "pom.xml"
}
}
tasks.named('compileJava') {
// use the project's version or define one directly
options.javaModuleVersion = provider { project.version }
}
test {
useJUnitPlatform()
jvmArgs '--enable-native-access=ALL-UNNAMED'
finalizedBy jacocoTestReport
}