-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle
319 lines (294 loc) · 9.35 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
plugins {
id "com.zoltu.git-versioning" version "2.0.28"
id "org.ccrusius.erlang" version "1.3.7"
}
apply plugin: 'c'
//=============================================================================
//
// Why not rebar?
//
// Because, while it works well in its own space, as soon as you get out of it
// it is not flexible enough. The C compilation support, for example, is not
// really there. I need something that works on SmartOS (Solaris), Windows, Mac,
// and Linux. My options are Gradle, CMake, and Shake, and Gradle is the one
// that made all the integrations I needed the least painful. (Bazel
// is currently not an option because of its lack of Windows support.)
//
//=============================================================================
/// ---------------------------------------------------------------------------
///
/// Gradle wrapper configuration
///
/// To upgrade the wrapper, change the version here and run `./gradlew wrapper`
///
/// ---------------------------------------------------------------------------
task wrapper(type: Wrapper) {
gradleVersion = '3.0'
}
//=============================================================================
//
// Empty tasks to be extended as we go.
//
//=============================================================================
task(install)
/// ---------------------------------------------------------------------------
///
/// Erlang
///
/// ---------------------------------------------------------------------------
ext {
eiInclude = erlang.eval('io:format("~s", [code:lib_dir(erl_interface, include)]).')
eiLib = erlang.eval('io:format("~s", [code:lib_dir(erl_interface, lib)]).')
}
install.dependsOn ebuild
//=============================================================================
//
// Sources
//
//=============================================================================
task install_src(type: Copy) {
from 'src'
into "$ebuildAppDir/src"
include '**/*.erl'
}
install.dependsOn install_src
//=============================================================================
//
// Includes
//
//=============================================================================
task install_include(type: Copy) {
from 'include'
into "$ebuildAppDir/include"
include '**/*.h'
}
install.dependsOn install_include
/// ---------------------------------------------------------------------------
///
/// Testing
///
/// ---------------------------------------------------------------------------
///
/// One thing one may want to be able to do is to easily change the
/// name of the behavior without having to edit the file itself (so
/// the name change can be automated easily in build scripts).
///
task custom_gen_c_server(type: org.ccrusius.erlang.tasks.Compile) {
setSourceFile 'src/gen_c_server.erl'
setNewName 'custom_gen_c_server.erl'
addReplacement '\\bgen_c_server\\b', 'custom_gen_c_server'
setOutputDir "$rootDir/test/custom_gen_c_server-1.0/ebin"
}
task ct {
dependsOn install
ext.destDir = new File("$rootDir/build/test")
ext.suites = fileTree(dir: "$rootDir/test", include: '**/*_SUITE.erl')
doLast {
destDir.mkdirs()
exec {
executable 'ct_run'
args '-pa', "$ebuildAppDir/ebin"
args '-pa', "$rootDir/test/custom_gen_c_server-1.0/ebin"
args '-logdir', "$destDir"
args '-suite'
args suites
standardInput System.in
environment 'ROOT_DIR': "$rootDir"
}
}
}
ct.dependsOn custom_gen_c_server
//=============================================================================
//
// Erlang shell
//
//=============================================================================
task shell {
dependsOn install
doLast {
def command = [ 'erl', '-name', 'gradle', '-pa', "$ebuildAppDir/ebin" ]
def proc = new ProcessBuilder((String[])command)
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
.redirectInput(ProcessBuilder.Redirect.INHERIT)
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start()
proc.waitFor()
if (0 != proc.exitValue()) {
throw new RuntimeException(
"erlang shell exited with status: ${proc.exitValue()}")
}
}
}
//=============================================================================
//
// C
//
//=============================================================================
model {
platforms {
x64 { architecture 'x86_64' }
}
repositories {
libs(PrebuiltLibraries) {
ei {
headers.srcDir "$eiInclude"
binaries.withType(StaticLibraryBinary) { binary ->
if (binary.targetPlatform.operatingSystem.windows) {
staticLibraryFile = file("$eiLib\\ei.lib")
}
if (binary.targetPlatform.operatingSystem.linux ||
binary.targetPlatform.operatingSystem.macOsX) {
staticLibraryFile = file("$eiLib/libei.a")
}
}
}
erl_interface {
headers.srcDir "$eiInclude"
binaries.withType(StaticLibraryBinary) { binary ->
if (binary.targetPlatform.operatingSystem.windows) {
staticLibraryFile = file("$eiLib\\erl_interface.lib")
}
if (binary.targetPlatform.operatingSystem.linux ||
binary.targetPlatform.operatingSystem.macOsX) {
staticLibraryFile = file("$eiLib/liberl_interface.a")
}
}
}
pthread {
binaries.withType(SharedLibraryBinary) { binary ->
def p = binary.targetPlatform
if (p.operatingSystem.windows) {
def baseDir = "$rootDir\\pthreads-win32\\Pre-built.2"
headers.srcDir "$baseDir\\include"
sharedLibraryFile = file("$baseDir\\dll\\$p.name\\pthreadVC2.dll")
sharedLibraryLinkFile = file("$baseDir\\lib\\$p.name\\pthreadVC2.lib")
}
}
}
winsock {
binaries.withType(StaticLibraryBinary) { binary ->
def p = binary.targetPlatform
if (p.operatingSystem.windows) {
// TODO: Find ws2_32 instead of hardcoding the path
def baseDir = "C:\\Program Files (x86)\\Windows Kits\\8.0\\Lib\\win8\\um"
staticLibraryFile = file("$baseDir\\$p.name\\ws2_32.lib")
}
}
}
}
}
binaries {
all {
cCompiler.define "_REENTRANT"
lib library: 'erl_interface', linkage: 'static'
lib library: 'ei', linkage: 'static'
if (toolChain in VisualCpp) {
// MSVC defines '_WIN32', but Erlang includes rely on '__WIN32__'
cCompiler.define "__WIN32__"
cCompiler.args "/TP"
linker.args "/SUBSYSTEM:CONSOLE"
lib library: 'winsock', linkage: 'static'
lib library: 'pthread', linkage: 'shared'
}
if (targetPlatform.operatingSystem.linux) {
cCompiler.args '-pthread'
linker.args '-pthread'
}
//println 'configuring variant: ' + name + '.' + targetPlatform.name + '.' + buildType.name
}
}
components {
//=========================================================================
//
// gen_c_server native library
//
//=========================================================================
gen_c_server(NativeLibrarySpec) {
targetPlatform 'x64'
binaries.withType(SharedLibraryBinarySpec) {
buildable = false
}
sources.c {
source {
srcDir "c_src"
include "*.c"
}
exportedHeaders {
srcDir "include"
}
}
binaries.withType(StaticLibraryBinarySpec) { lib ->
lib.tasks.withType(CreateStaticLibrary) { linkTask ->
linkTask << {
copy {
from lib.staticLibraryFile
into file("$ebuildAppDir/lib/")
}
}
install.dependsOn lib
}
}
}
//=========================================================================
//
// Test C nodes
//
//=========================================================================
call_counter(NativeExecutableSpec) {
targetPlatform 'x64'
sources.c {
source {
srcDir "test/call_counter/c_src"
include "*.c"
}
exportedHeaders {
srcDir "include"
}
}
binaries.all {
lib library: 'gen_c_server', linkage: 'static'
}
}
crashy(NativeExecutableSpec) {
targetPlatform 'x64'
sources.c {
source {
srcDir "test/crashy/c_src"
include "*.c"
}
exportedHeaders {
srcDir "include"
}
}
binaries.all {
lib library: 'gen_c_server', linkage: 'static'
}
}
reply_this(NativeExecutableSpec) {
targetPlatform 'x64'
sources.c {
source {
srcDir "test/reply_this/c_src"
include "*.c"
}
exportedHeaders {
srcDir "include"
}
}
binaries.all {
lib library: 'gen_c_server', linkage: 'static'
}
}
}
}
//
// For each executable, gradle defines a task called
// install${binary.name}Executable, which will create a suitable
// installation that includes all the library dependencies.
// This installation will have a shell script placed at
// ${project.buildDir}/install/${binary.name}/${binary.name}
// (with a .bat extension on Windows).
//
install.dependsOn 'installCall_counterExecutable'
install.dependsOn 'installCrashyExecutable'
install.dependsOn 'installReply_thisExecutable'