-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle
159 lines (134 loc) · 4.94 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
plugins {
id 'application'
id 'org.graalvm.buildtools.native' version '0.10.1'
id 'com.google.osdetector' version '1.7.3'
}
tasks.wrapper {
gradleVersion = '8.6'
distributionType = Wrapper.DistributionType.ALL
}
group = 'com.github.chirontt.lwjgl'
description = 'LWJGL3 HelloWorld demo with native image by GraalVM'
version = '0.0.1-SNAPSHOT'
//returns the <os>-<arch> platform string suitable for retrieval of LWJGL natives
//(if <arch> is blank, it implies "x86_64")
def getCurrentPlatform() {
def os = osdetector.os
def lwjglOS = os == 'linux' ? 'linux' :
os == 'osx' ? 'macos' :
os == 'windows' ? 'windows' :
'unknown'
if (lwjglOS == 'unknown')
throw new GradleException('Unsupported OS: ' + os)
def arch = osdetector.arch
//consider 64-bit architectures only
def lwjglArch = arch == 'x86_64' ? '' :
arch == 'aarch_64' ? 'arm64' :
'unknown'
if (lwjglArch == 'unknown')
throw new GradleException('Unsupported Architecture: ' + arch)
return (lwjglArch == '' ? lwjglOS : (lwjglOS + '-' + lwjglArch))
}
ext {
lwjglVersion = '3.3.3'
//LWJGL modules used: minimal OpenGL
lwjglModules = ['lwjgl', 'lwjgl-assimp', 'lwjgl-glfw', 'lwjgl-openal', 'lwjgl-opengl', 'lwjgl-stb']
mainClassName = 'com.github.chirontt.lwjgl.demo.HelloWorld'
currentPlatform = getCurrentPlatform()
}
repositories {
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
mavenLocal()
}
dependencies {
//get recommended dependency versions from the LWJGL BOM
implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
//add LWJGL modules and the current OS's natives to the compile and runtime classpaths
lwjglModules.each {
implementation "org.lwjgl:$it"
if (it != 'lwjgl-egl') //lwjgl-egl has no native libraries
runtimeOnly "org.lwjgl:$it::natives-$currentPlatform"
}
}
application {
mainClass = project.mainClassName
applicationName = project.name //name of the resulting native executable
}
compileJava {
options.release = 11 //use JDK11+ for compiling & running
options.encoding = 'UTF-8'
}
run {
//get system properties specified from the command line (for debugging, etc.)
//and pass them on to the running application's JVM
systemProperties = System.getProperties()
//use the following jvmArgs for as many different run scenarios as possible,
//and for all the code-execution paths as much as possible,
//to generate (or merge with) the GraalVM native-image configuration files
//in the src/main/resources/META-INF/native-image directory.
//This directory is read by GraalVM during the native-image build.
//jvmArgs = ["-agentlib:native-image-agent=config-merge-dir=src/main/resources/META-INF/native-image"]
}
task extractLwjglManifest(type: Copy) {
from {
configurations.compileClasspath.filter { it.name == "lwjgl-${lwjglVersion}.jar" }
.collect { zipTree(it) }
}
include 'META-INF/MANIFEST.MF'
into "$buildDir/tmp"
}
//create a stand-alone executable uber jar
//including all dependencies for current platform
task uberJar(type: Jar) {
dependsOn extractLwjglManifest
archiveClassifier = "no-deps-$currentPlatform"
with jar
manifest {
from (extractLwjglManifest.destinationDir.path + '/META-INF/MANIFEST.MF') {
eachEntry { details ->
if (details.key == 'Created-By')
details.value = System.getProperty('java.runtime.version') + ' (' + System.getProperty('java.vendor') + ')'
else if (details.key == 'Ant-Version')
details.exclude()
}
}
attributes(
'Main-Class': project.mainClassName,
'Built-By': System.getProperty('user.name'),
'Gradle-Version': 'Gradle ' + gradle.getGradleVersion(),
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
duplicatesStrategy 'exclude'
}
graalvmNative {
toolchainDetection = false
binaries {
main {
imageName = project.name
mainClass = project.mainClassName
debug = true
verbose = true
fallback = false
buildArgs.add('--initialize-at-run-time=org.lwjgl')
buildArgs.add('--native-image-info')
buildArgs.add('-march=compatibility') //only available in GraalVM for JDK 17+
//buildArgs.add('-H:+TraceNativeToolUsage')
useFatJar = false
}
}
metadataRepository {
enabled = false
}
}
tasks.named("nativeCompile") {
//use the uber jar if long classpath becomes a problem in Windows:
//dependsOn uberJar
//classpathJar = uberJar.archiveFile
}