This repository has been archived by the owner on Oct 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
471 lines (440 loc) · 17.9 KB
/
build.gradle.kts
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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
*/
import java.net.*
plugins {
`java-platform`
`maven-publish`
signing
}
val lwjglVersion: String by project
val sonatypeUsername: String by project
val sonatypePassword: String by project
defaultTasks = mutableListOf("publish")
buildDir = file("bin/MAVEN")
group = "org.lwjgl"
version = lwjglVersion
enum class BuildType {
LOCAL,
SNAPSHOT,
RELEASE
}
data class Deployment(
val type: BuildType,
val repo: URI,
val user: String? = null,
val password: String? = null
)
val deployment = when {
hasProperty("release") -> Deployment(
type = BuildType.RELEASE,
repo = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/"),
user = sonatypeUsername,
password = sonatypePassword
)
hasProperty("snapshot") -> {
version = "$version-SNAPSHOT"
Deployment(
type = BuildType.SNAPSHOT,
repo = uri("https://oss.sonatype.org/content/repositories/snapshots/"),
user = sonatypeUsername,
password = sonatypePassword
)
}
else -> {
version = "$version-SNAPSHOT"
Deployment(
type = BuildType.LOCAL,
repo = repositories.mavenLocal().url
)
}
}
println("${deployment.type.name} BUILD")
enum class Platforms(val classifier: String) {
LINUX("linux"),
LINUX_ARM64("linux-arm64"),
LINUX_ARM32("linux-arm32"),
MACOS("macos"),
WINDOWS("windows"),
WINDOWS_X86("windows-x86");
companion object {
val ALL = values()
}
}
enum class Artifacts(
val artifact: String,
val projectName: String,
val projectDescription: String,
vararg val platforms: Platforms
) {
CORE("lwjgl", "LWJGL", "The LWJGL core library.", *Platforms.ALL),
ASSIMP(
"lwjgl-assimp", "LWJGL - Assimp bindings",
"A portable Open Source library to import various well-known 3D model formats in a uniform manner.",
*Platforms.ALL
),
BGFX(
"lwjgl-bgfx", "LWJGL - bgfx bindings",
"A cross-platform, graphics API agnostic rendering library. It provides a high performance, low level abstraction for common platform graphics APIs like OpenGL, Direct3D and Apple Metal.",
*Platforms.ALL
),
BULLET(
"lwjgl-bullet", "LWJGL - Bullet bindings",
"Real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.",
*Platforms.ALL
),
CUDA(
"lwjgl-cuda", "LWJGL - CUDA bindings",
"A parallel computing platform and programming model developed by NVIDIA for general computing on GPUs."
),
DRIFTFX(
"lwjgl-driftfx", "LWJGL - DriftFX bindings",
"A library that allows you to render any OpenGL content directly into JavaFX nodes.",
*Platforms.ALL
),
EGL(
"lwjgl-egl", "LWJGL - EGL bindings",
"An interface between Khronos rendering APIs such as OpenGL ES or OpenVG and the underlying native platform window system."
),
GLFW(
"lwjgl-glfw", "LWJGL - GLFW bindings",
"A multi-platform library for OpenGL, OpenGL ES and Vulkan development on the desktop. It provides a simple API for creating windows, contexts and surfaces, receiving input and events.",
*Platforms.ALL
),
JAWT(
"lwjgl-jawt", "LWJGL - JAWT bindings",
"The AWT native interface."
),
JEMALLOC(
"lwjgl-jemalloc", "LWJGL - jemalloc bindings",
"A general purpose malloc implementation that emphasizes fragmentation avoidance and scalable concurrency support.",
*Platforms.ALL
),
LIBDIVIDE(
"lwjgl-libdivide", "LWJGL - libdivide bindings",
"A library that replaces expensive integer divides with comparatively cheap multiplication and bitshifts.",
*Platforms.ALL
),
LLVM(
"lwjgl-llvm", "LWJGL - LLVM/Clang bindings",
"A collection of modular and reusable compiler and toolchain technologies.",
*Platforms.ALL
),
LMDB(
"lwjgl-lmdb", "LWJGL - LMDB bindings",
"A compact, fast, powerful, and robust database that implements a simplified variant of the BerkeleyDB (BDB) API.",
*Platforms.ALL
),
LZ4(
"lwjgl-lz4", "LWJGL - LZ4 bindings",
"A lossless data compression algorithm that is focused on compression and decompression speed.",
*Platforms.ALL
),
MEOW(
"lwjgl-meow", "LWJGL - Meow hash bindings",
"An extremely fast non-cryptographic hash.",
Platforms.LINUX, Platforms.LINUX_ARM64, Platforms.MACOS, Platforms.WINDOWS, Platforms.WINDOWS_X86
),
MESHOPTIMIZER(
"lwjgl-meshoptimizer", "LWJGL - meshoptimizer bindings",
"A library that provides algorithms to help optimize meshes.",
*Platforms.ALL
),
NANOVG(
"lwjgl-nanovg", "LWJGL - NanoVG & NanoSVG bindings",
"A small antialiased vector graphics rendering library for OpenGL. Also includes NanoSVG, a simple SVG parser.",
*Platforms.ALL
),
NFD(
"lwjgl-nfd", "LWJGL - Native File Dialog bindings",
"A tiny, neat C library that portably invokes native file open and save dialogs.",
Platforms.LINUX, Platforms.MACOS, Platforms.WINDOWS, Platforms.WINDOWS_X86
),
NUKLEAR(
"lwjgl-nuklear", "LWJGL - Nuklear bindings",
"A minimal state immediate mode graphical user interface toolkit.",
*Platforms.ALL
),
ODBC(
"lwjgl-odbc", "LWJGL - ODBC bindings",
"A C programming language interface that makes it possible for applications to access data from a variety of database management systems (DBMSs)."
),
OPENAL(
"lwjgl-openal", "LWJGL - OpenAL bindings",
"A cross-platform 3D audio API appropriate for use with gaming applications and many other types of audio applications.",
*Platforms.ALL
),
OPENCL(
"lwjgl-opencl", "LWJGL - OpenCL bindings",
"An open, royalty-free standard for cross-platform, parallel programming of diverse processors found in personal computers, servers, mobile devices and embedded platforms."
),
OPENGL(
"lwjgl-opengl", "LWJGL - OpenGL bindings",
"The most widely adopted 2D and 3D graphics API in the industry, bringing thousands of applications to a wide variety of computer platforms.",
*Platforms.ALL
),
OPENGLES(
"lwjgl-opengles", "LWJGL - OpenGL ES bindings",
"A royalty-free, cross-platform API for full-function 2D and 3D graphics on embedded systems - including consoles, phones, appliances and vehicles.",
*Platforms.ALL
),
OPENVR(
"lwjgl-openvr", "LWJGL - OpenVR bindings",
"An API and runtime that allows access to VR hardware from multiple vendors without requiring that applications have specific knowledge of the hardware they are targeting.",
Platforms.LINUX, Platforms.MACOS, Platforms.WINDOWS, Platforms.WINDOWS_X86
),
OPUS(
"lwjgl-opus", "LWJGL - Opus bindings",
"A totally open, royalty-free, highly versatile audio codec.",
*Platforms.ALL
),
OVR(
"lwjgl-ovr", "LWJGL - OVR bindings",
"The API of the Oculus SDK.",
Platforms.WINDOWS, Platforms.WINDOWS_X86
),
PAR(
"lwjgl-par", "LWJGL - par_shapes bindings",
"Generate parametric surfaces and other simple shapes.",
*Platforms.ALL
),
REMOTERY(
"lwjgl-remotery", "LWJGL - Remotery bindings",
"A realtime CPU/GPU profiler hosted in a single C file with a viewer that runs in a web browser.",
*Platforms.ALL
),
RPMALLOC(
"lwjgl-rpmalloc", "LWJGL - rpmalloc bindings",
"A public domain cross platform lock free thread caching 16-byte aligned memory allocator implemented in C.",
*Platforms.ALL
),
SHADERC(
"lwjgl-shaderc", "LWJGL - Shaderc bindings",
"A collection of libraries for shader compilation.",
*Platforms.ALL
),
SPVC(
"lwjgl-spvc", "LWJGL - SPIRV-Cross bindings",
"A library for performing reflection on SPIR-V and disassembling SPIR-V back to high level languages.",
*Platforms.ALL
),
SSE(
"lwjgl-sse", "LWJGL - SSE bindings",
"Simple SSE intrinsics.",
Platforms.LINUX, Platforms.MACOS, Platforms.WINDOWS, Platforms.WINDOWS_X86
),
STB(
"lwjgl-stb", "LWJGL - stb bindings",
"Single-file public domain libraries for fonts, images, ogg vorbis files and more.",
*Platforms.ALL
),
TINYEXR(
"lwjgl-tinyexr", "LWJGL - Tiny OpenEXR bindings",
"A small library to load and save OpenEXR(.exr) images.",
*Platforms.ALL
),
TINYFD(
"lwjgl-tinyfd", "LWJGL - Tiny File Dialogs bindings",
"Provides basic modal dialogs.",
*Platforms.ALL
),
TOOTLE(
"lwjgl-tootle", "LWJGL - AMD Tootle bindings",
"A 3D triangle mesh optimization library that improves on existing mesh preprocessing techniques.",
Platforms.LINUX, Platforms.MACOS, Platforms.WINDOWS, Platforms.WINDOWS_X86
),
VMA(
"lwjgl-vma", "LWJGL - Vulkan Memory Allocator bindings",
"An easy to integrate Vulkan memory allocation library.",
*Platforms.ALL
),
VULKAN(
"lwjgl-vulkan", "LWJGL - Vulkan bindings",
"A new generation graphics and compute API that provides high-efficiency, cross-platform access to modern GPUs used in a wide variety of devices from PCs and consoles to mobile phones and embedded platforms.",
Platforms.MACOS
),
XXHASH(
"lwjgl-xxhash", "LWJGL - xxHash bindings",
"An extremely fast hash algorithm, running at RAM speed limits.",
*Platforms.ALL
),
YOGA(
"lwjgl-yoga", "LWJGL - Yoga bindings",
"An open-source, cross-platform layout library that implements Flexbox.",
*Platforms.ALL
),
ZSTD(
"lwjgl-zstd", "LWJGL - Zstandard bindings",
"A fast lossless compression algorithm, targeting real-time compression scenarios at zlib-level and better compression ratios.",
*Platforms.ALL
);
fun directory(buildDir: String) = "$buildDir/$artifact"
private fun path() = "${directory("bin/MAVEN")}/$artifact"
val isActive get() = File(directory("bin/RELEASE")).exists()
fun hasArtifact(classifier: String) = File("${directory("bin/RELEASE")}/${artifact}-${classifier}.jar").exists()
fun artifact(classifier: String? = null) =
if (classifier === null)
File("${path()}.jar")
else
File("${path()}-$classifier.jar")
}
publishing {
repositories {
maven {
url = deployment.repo
if (deployment.type !== BuildType.LOCAL) {
credentials {
username = deployment.user
password = deployment.password
}
}
}
}
publications {
/*
Ideally, we'd have the following structure:
-------------------------------------------
lwjgl
lwjgl-windows (depends on lwjgl)
glfw (depends on lwjgl)
glfw-windows (depends on glfw & lwjgl-windows)
stb (depends on lwjgl)
stb-windows (depends on stb & lwjgl-windows)
-------------------------------------------
If a user wanted to use GLFW + stb in their project, running on
the Windows platform, they'd only have to define glfw-windows
and stb-windows as dependencies. This would automatically
resolve stb, glfw, lwjgl and lwjgl-windows as transitive
dependencies. Unfortunately, it is not possible to define such
a relationship between Maven artifacts when using classifiers.
A method to make this work is make the natives-<arch> classified
JARs separate artifacts. We do not do it for aesthetic reasons.
Instead, we assume that a tool is available (on the LWJGL website)
that automatically generates POM/Gradle dependency structures for
projects wanting to use LWJGL. The output is going to be verbose;
the above example is going to look like this in Gradle:
-------------------------------------------
compile 'org.lwjgl:lwjgl:$lwjglVersion' // NOTE: this is optional, all binding artifacts have a dependency on lwjgl
compile 'org.lwjgl:lwjgl:$lwjglVersion:natives-$lwjglArch'
compile 'org.lwjgl:lwjgl-glfw:$lwjglVersion'
compile 'org.lwjgl:lwjgl-glfw:$lwjglVersion:natives-$lwjglArch'
compile 'org.lwjgl:lwjgl-stb:$lwjglVersion'
compile 'org.lwjgl:lwjgl-stb:$lwjglVersion:natives-$lwjglArch'
-------------------------------------------
and a whole lot more verbose in Maven. Hopefully, the automation
is going to alleviate the pain.
*/
fun org.gradle.api.publish.maven.MavenPom.setupPom(pomName: String, pomDescription: String, pomPackaging: String) {
name.set(pomName)
description.set(pomDescription)
url.set("https://www.lwjgl.org")
packaging = pomPackaging
scm {
connection.set("scm:git:https://github.com/LWJGL/lwjgl3.git")
developerConnection.set("scm:git:https://github.com/LWJGL/lwjgl3.git")
url.set("https://github.com/LWJGL/lwjgl3.git")
}
licenses {
license {
name.set("BSD")
url.set("https://www.lwjgl.org/license")
distribution.set("repo")
}
}
developers {
developer {
id.set("spasi")
name.set("Ioannis Tsakpinis")
email.set("[email protected]")
url.set("https://github.com/Spasi")
}
}
}
Artifacts.values().forEach { module ->
if (module.isActive) {
create<MavenPublication>("maven${module.name}") {
artifactId = module.artifact
artifact(module.artifact())
if (deployment.type !== BuildType.LOCAL || module.hasArtifact("sources")) {
artifact(module.artifact("sources")) {
classifier = "sources"
}
}
if (deployment.type !== BuildType.LOCAL || module.hasArtifact("javadoc")) {
artifact(module.artifact("javadoc")) {
classifier = "javadoc"
}
}
module.platforms.forEach {
if (deployment.type !== BuildType.LOCAL || module.hasArtifact("natives-${it.classifier}")) {
artifact(module.artifact("natives-${it.classifier}")) {
classifier = "natives-${it.classifier}"
}
}
}
pom {
setupPom(module.projectName, module.projectDescription, "jar")
if (module != Artifacts.CORE) {
withXml {
asNode().appendNode("dependencies").apply {
appendNode("dependency").apply {
appendNode("groupId", "org.lwjgl")
appendNode("artifactId", "lwjgl")
appendNode("version", project.version)
appendNode("scope", "compile")
}
}
}
}
}
}
}
}
create<MavenPublication>("lwjglBOM") {
from(components["javaPlatform"])
artifactId = "lwjgl-bom"
pom {
setupPom("LWJGL BOM", "LWJGL 3 Bill of Materials.", "pom")
withXml {
asElement().getElementsByTagName("dependencyManagement").item(0).apply {
asElement().getElementsByTagName("dependencies").item(0).apply {
Artifacts.values().forEach { module ->
module.platforms.forEach {
ownerDocument.createElement("dependency").also(::appendChild).apply {
appendChild(ownerDocument.createElement("groupId").also(::appendChild).apply { textContent = "org.lwjgl" })
appendChild(ownerDocument.createElement("artifactId").also(::appendChild).apply { textContent = module.artifact })
appendChild(ownerDocument.createElement("version").also(::appendChild).apply { textContent = project.version as String })
appendChild(ownerDocument.createElement("classifier").also(::appendChild).apply { textContent = "natives-${it.classifier}" })
appendChild(ownerDocument.createElement("scope").also(::appendChild).apply { textContent = "compile" })
}
}
}
}
}
// Workaround for https://github.com/gradle/gradle/issues/7529
asNode()
}
}
}
}
}
signing {
isRequired = deployment.type === BuildType.RELEASE
sign(publishing.publications)
}
val copyArchives = tasks.create<Copy>("copyArchives") {
from("bin/RELEASE")
include("**")
destinationDir = buildDir
}
tasks.withType<Sign> {
dependsOn(copyArchives)
}
dependencies {
constraints {
Artifacts.values().forEach { module ->
api("org.lwjgl:${module.artifact}:$version")
}
}
}