-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
164 lines (141 loc) · 6.02 KB
/
build.gradle.kts
File metadata and controls
164 lines (141 loc) · 6.02 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
import java.io.File as JFile
plugins {
java
}
allprojects {
group = "dev.engine"
version = "0.1.0-SNAPSHOT"
repositories {
mavenCentral()
}
}
// ── GraalVM installation detection ──────────────────────────────────────
// Gradle's toolchain selection cannot distinguish Oracle GraalVM from regular
// Oracle JDK when both have the same language version — both report
// vendor=Oracle. To let graal-* modules compile reliably regardless of which
// Java 26 JDK is SDKMAN's current default, we scan the filesystem here and
// expose the detected GraalVM install path to subprojects via
// rootProject.extra["graalVmHome"]. Subprojects then use it to override
// JavaCompile.forkOptions.javaHome, bypassing the toolchain-picked javac.
//
// Priority order:
// 1. $GRAALVM_HOME environment variable
// 2. Latest ~/.sdkman/candidates/java/*-graal with a valid bin/javac
// Returns null if no GraalVM was found — subprojects fall back to default.
//
// See docs/graalwasm-toolchain.md for the full rationale.
val detectedGraalVmHome: String? = run {
val envHome = System.getenv("GRAALVM_HOME")
if (envHome != null && JFile(envHome, "bin/javac").exists()) {
return@run envHome
}
val sdkman = JFile(System.getProperty("user.home"), ".sdkman/candidates/java")
if (!sdkman.isDirectory) return@run null
val entries: Array<JFile> = sdkman.listFiles() ?: return@run null
val graalDirs: List<JFile> = entries
.filter { f: JFile -> f.isDirectory && f.name.endsWith("-graal") }
.sortedByDescending { f: JFile -> f.name }
for (dir in graalDirs) {
if (JFile(dir, "bin/javac").exists()) {
return@run dir.absolutePath
}
}
null
}
rootProject.extra["graalVmHome"] = detectedGraalVmHome
if (detectedGraalVmHome != null) {
logger.lifecycle("GraalVM detected at: $detectedGraalVmHome")
} else {
logger.info("No GraalVM detected — graal-* modules will fall back to default toolchain selection")
}
// ── Aggregated Javadoc ──────────────────────────────────────────────────
val javadocModules = listOf(
":core",
":graphics:api",
":graphics:common",
":graphics:opengl",
":graphics:vulcan",
":graphics:webgpu"
)
tasks.register<Javadoc>("javadocAll") {
group = "documentation"
description = "Generates aggregated Javadoc for all public modules"
val catalog = rootProject.extensions
.getByType<VersionCatalogsExtension>()
.named("libs")
val javaVersion = catalog.findVersion("java").orElseThrow().requiredVersion
val javadocProjects = javadocModules.map { project(it) }
source = files(javadocProjects.map { it.sourceSets.main.get().allJava }).asFileTree
classpath = files(javadocProjects.map { it.sourceSets.main.get().compileClasspath })
setDestinationDir(file("docs/javadoc"))
javadocTool = javaToolchains.javadocToolFor {
languageVersion = JavaLanguageVersion.of(javaVersion)
}
options {
this as StandardJavadocDocletOptions
encoding = "UTF-8"
docEncoding = "UTF-8"
charSet = "UTF-8"
windowTitle = "jGibbonEngine API"
docTitle = "jGibbonEngine API Documentation"
header = "<a href='https://zzuegg.github.io/jGibbonEngine'>jGibbonEngine</a>"
addStringOption("Xdoclint:none", "-quiet")
addBooleanOption("-enable-preview", true)
addStringOption("source", javaVersion)
addStringOption("-add-stylesheet", file("tools/site-generator/src/main/resources/javadoc-theme.css").absolutePath)
links("https://docs.oracle.com/en/java/javase/25/docs/api/")
}
javadocProjects.forEach { dependsOn("${it.path}:classes") }
}
subprojects {
// Skip java-library for grouping-only projects (e.g. :graphics)
if (childProjects.isNotEmpty() && projectDir.resolve("src").exists().not()) return@subprojects
apply(plugin = "java-library")
val catalog = rootProject.extensions
.getByType<VersionCatalogsExtension>()
.named("libs")
java {
toolchain {
languageVersion = JavaLanguageVersion.of(
catalog.findVersion("java").orElseThrow().requiredVersion
)
}
}
dependencies {
"testImplementation"(platform(catalog.findLibrary("junit-bom").orElseThrow()))
"testImplementation"(catalog.findLibrary("junit-jupiter").orElseThrow())
"testRuntimeOnly"(catalog.findLibrary("junit-launcher").orElseThrow())
}
tasks.test {
useJUnitPlatform()
jvmArgs("--enable-native-access=ALL-UNNAMED")
// Slang's C++ runtime can trigger glibc heap metadata corruption on
// certain glibc versions when COM objects are released (free/delete).
// Using jemalloc as a drop-in replacement avoids the issue.
val jemallocPaths = listOf(
"/lib/x86_64-linux-gnu/libjemalloc.so.2",
"/usr/lib/libjemalloc.so.2",
"/usr/lib64/libjemalloc.so.2",
"/opt/homebrew/lib/libjemalloc.dylib"
)
jemallocPaths.map { file(it) }.firstOrNull { it.exists() }?.let {
environment("LD_PRELOAD", it.absolutePath)
}
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
}
// ── Screenshot tests: ./gradlew screenshotTest ──────────────────────
tasks.register("screenshotTest") {
group = "verification"
description = "Runs the full screenshot regression test pipeline"
dependsOn(":samples:tests:screenshot:analysis:screenshotTest")
}
// ── testAll: unit tests + screenshot tests ──────────────────────────
tasks.register("testAll") {
group = "verification"
description = "Runs all unit tests and screenshot regression tests"
dependsOn(subprojects.mapNotNull { it.tasks.findByName("test") })
dependsOn("screenshotTest")
}