-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
243 lines (213 loc) · 7.65 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
import org.gradle.api.tasks.testing.logging.TestLogEvent
buildscript {
def PNI_VERSION = '21.0.0.20'
ext.set("PNI_VERSION", PNI_VERSION)
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath group: 'io.vproxy', name: 'pni-exec', version: PNI_VERSION
}
}
plugins {
id 'java-library'
id 'maven-publish'
id 'signing'
id 'com.github.johnrengelman.shadow' version '7.1.2' apply false
}
def PNI_API_VERSION = project.PNI_VERSION
group = 'io.vproxy'
version = '1.0-SNAPSHOT'
repositories {
mavenLocal()
mavenCentral()
}
subprojects {
apply plugin: 'java-library'
group 'io.vproxy'
version rootProject.version
java {
sourceCompatibility = '21'
targetCompatibility = '21'
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
options.incremental = false
options.compilerArgs += '--enable-preview'
}
tasks.withType(JavaExec) {
jvmArgs += '--enable-preview'
jvmArgs += '--enable-native-access=ALL-UNNAMED'
javaLauncher.set(javaToolchains.launcherFor(java.toolchain))
}
tasks.withType(Test) {
jvmArgs += '--enable-preview'
jvmArgs += '--enable-native-access=ALL-UNNAMED'
testLogging {
showStandardStreams = true
events TestLogEvent.FAILED, TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.STARTED
maxGranularity 100
exceptionFormat "full"
showCauses true
showExceptions true
showStackTraces true
}
}
repositories {
mavenLocal()
mavenCentral()
}
task javadocJar(type: Jar) {
archiveClassifier = 'javadoc'
from "$buildDir/docs/javadoc"
}
tasks.withType(GenerateModuleMetadata) {
enabled = false
}
}
def isGraalBuild() {
var path = java.nio.file.Path.of(project.rootProject.projectDir.getAbsolutePath(), "is-graal-build")
return java.nio.file.Files.readString(path).trim() == "true"
}
project(':template') {
dependencies {
implementation 'io.vproxy:pni-api-jdk21:' + PNI_API_VERSION
}
compileJava {
options.compilerArgs += '-parameters'
}
task pniGenerate1() {
dependsOn compileJava
def workingDir = project.rootProject.rootDir.getAbsolutePath()
def gen = new io.vproxy.pni.exec.Generator(
new io.vproxy.pni.exec.CompilerOptions()
.setClasspath(List.of(workingDir + '/template/build/classes/java/main'))
.setJavaOutputBaseDirectory(workingDir + '/core/src/main/generated')
.setCOutputDirectory(workingDir + '/core/src/main/c-generated')
.setCompilationFlag(io.vproxy.pni.exec.CompilationFlag.TYPE_NAME_PREFIX, "PNI")
.setCompilationFlag(io.vproxy.pni.exec.CompilationFlag.RELEASE_PNI_H_FILE, null)
.setCompilationFlag(io.vproxy.pni.exec.CompilationFlag.RELEASE_PNI_C_FILE, null)
.setCompilationFlag(io.vproxy.pni.exec.CompilationFlag.RELEASE_JNI_H_MOCK_FILE, null)
)
doLast {
gen.generate()
}
}
task pniGenerate2() {
dependsOn compileJava
def workingDir = project.rootProject.rootDir.getAbsolutePath()
def gen = new io.vproxy.pni.exec.Generator(
new io.vproxy.pni.exec.CompilerOptions()
.setClasspath(List.of(workingDir + '/template/build/classes/java/main'))
.setJavaOutputBaseDirectory(workingDir + '/core/src/main/generated-graal')
.setCOutputDirectory(workingDir + '/core/src/main/c-generated-graal')
.setCompilationFlag(io.vproxy.pni.exec.CompilationFlag.TYPE_NAME_PREFIX, "PNI")
.setCompilationFlag(io.vproxy.pni.exec.CompilationFlag.RELEASE_PNI_H_FILE, null)
.setCompilationFlag(io.vproxy.pni.exec.CompilationFlag.RELEASE_PNI_C_FILE, null)
.setCompilationFlag(io.vproxy.pni.exec.CompilationFlag.RELEASE_JNI_H_MOCK_FILE, null)
.setCompilationFlag(io.vproxy.pni.exec.CompilationFlag.GRAAL_NATIVE_IMAGE_FEATURE, "io.vproxy.msquic.Feature")
.setCompilationFlag(io.vproxy.pni.exec.CompilationFlag.GRAAL_C_ENTRYPOINT_LITERAL_UPCALL, null)
)
doLast {
gen.generate()
}
}
task pniGenerate() {
dependsOn pniGenerate1
dependsOn pniGenerate2
}
if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
task pniCompile() {}
} else {
task pniCompile(type: Exec) {
workingDir project.rootProject.rootDir.getAbsolutePath() + '/core/src/main/c'
commandLine './make-quic.sh'
if (isGraalBuild()) {
environment["GRAAL"] = "true"
}
dependsOn pniGenerate
}
}
}
project(':core') {
if (isGraalBuild()) {
sourceSets {
main {
java {
srcDirs = ['src/main/java', 'src/main/generated-graal', 'src/main/module-info']
}
}
}
} else {
sourceSets {
main {
java {
srcDirs = ['src/main/java', 'src/main/generated', 'src/main/module-info']
}
}
}
}
dependencies {
api 'io.vproxy:pni-api-jdk21:' + PNI_API_VERSION
api 'io.vproxy:pni-api-graal:' + PNI_API_VERSION
api 'io.vproxy:commons:1.2.1'
compileOnly group: 'io.vproxy', name: 'graal-sdk-mock-nativeimage', version: '1.2.1'
runtimeOnly group: 'io.vproxy', name: 'graal-sdk-mock-runtime', version: '1.2.1'
}
}
project(':sample') {
apply plugin: 'com.github.johnrengelman.shadow'
dependencies {
implementation project(':core')
}
jar {
manifest {
attributes 'Main-Class': 'io.vproxy.msquic.sample.Main'
}
}
shadowJar {
archiveFileName.set('sample.jar')
}
task runSampleClient(type: JavaExec) {
standardInput = System.in
classpath = sourceSets.main.runtimeClasspath
mainClass = 'io.vproxy.msquic.sample.Client'
jvmArgs += '-Djava.library.path=' +
project.rootProject.rootDir.getAbsolutePath() + '/core/src/main/c' +
File.pathSeparator +
System.getenv("MSQUIC_LD")
}
task runSampleServer(type: JavaExec) {
standardInput = System.in
classpath = sourceSets.main.runtimeClasspath
mainClass = 'io.vproxy.msquic.sample.Server'
jvmArgs += '-Djava.library.path=' +
project.rootProject.rootDir.getAbsolutePath() + '/core/src/main/c' +
File.pathSeparator +
System.getenv("MSQUIC_LD")
dependsOn project(':template').tasks.pniCompile
dependsOn compileJava
}
task buildSampleNativeImage(type: Exec) {
executable 'native-image'
def output = 'sample'
output += '.run'
args '-jar', './build/libs/sample.jar', '--features=io.vproxy.msquic.Feature',
'--enable-preview', '--enable-native-access=ALL-UNNAMED',
'-Ob', '--no-fallback',
'-o', output
dependsOn shadowJar
}
task runSampleNativeImage(type: Exec) {
standardInput = System.in
executable './sample.run'
args '-Djava.library.path=' + project.rootProject.rootDir.getAbsolutePath() + '/core/src/main/c' +
File.pathSeparator +
System.getenv("MSQUIC_LD")
if (System.getProperty("ARGS") != null) {
args Arrays.asList(System.getProperty("ARGS").split(" "))
}
dependsOn project(':template').tasks.pniCompile
}
}