-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild.gradle
111 lines (100 loc) · 3.81 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
apply plugin: 'scala'
apply plugin: 'maven-publish'
version = '0.2.0-SNAPSHOT'
group = "weld"
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile 'org.scala-lang:scala-library:2.11.8'
testImplementation 'junit:junit:4.12'
}
/**
* Generate the JNI headers for java integration.
*/
task generateJniHeaders(type:Exec) {
def classpath = sourceSets.main.scala.outputDir
def nativeIncludes = "src/native/include"
commandLine "javah", "-d", nativeIncludes, "-classpath", classpath, "weld.WeldJNI\$"
dependsOn classes
}
/**
* Compile the weld-java native library.
*
* We currently support compilation for the local platform and provide a docker image for linux
* compilation. You can build weld-java for linux using the docker linux image by executing the
* `compileWeldLinux` task. Note that building the linux library is not super fast, and that this
* should be reserved for release builds.
*
* There is also an image that should be able to build weld-java for both linux and mac. You can
* find its Dockerfile in the `docker/cross` directory. This is however a work in progress and it
* is currently not able to build its mac target; it fails with various linker errors.
*
* A different solution to cross compilation would be use something like travis of appveyor to
* do for us.
*
* I have tried to use the rust's x86_64-unkown-musl target but that only supports static
* libraries which does not work with JNI. We should revisit this when it supports dynamic
* libraries. See https://chr4.org/blog/2017/03/15/cross-compile-and-link-a-static-binary-on-macos-for-linux-with-cargo-and-rust/
* for more information on this, and be sure to set the CC & AR environment vars in order to
* compile backtrace.
*/
task compileWeld(type:Exec) {
commandLine "cargo", "build", "--release"
}
task compileWeldLinux(type:Exec) {
def dir = rootProject.projectDir.toString()
// Build the docker image. This will take some time on the first run.
commandLine "docker", "build", "-t", "weld-java-linux", "docker/linux"
// Build the weld-java native library for linux.
commandLine "docker", "run", "--rm", "-v", dir + ":/source", "weld-java-linux",
"cargo", "build", "--release", "--target=x86_64-unknown-linux-gnu"
}
test {
dependsOn cleanTest
testLogging.showStandardStreams = true
systemProperty 'weld.library.path', 'target/release/'
}
jar {
manifest {
attributes('Implementation-Title': project.name,
'Implementation-Version': project.version)
}
// Determine the platform and extension of the regular build.
def arch = System.getProperty("os.arch").toLowerCase()
def os = System.getProperty("os.name").toLowerCase()
def platform = "unsupported"
def is64bitIntel = (arch.contains("86") || arch.contains("amd")) && arch.contains("64")
if (is64bitIntel && (os.contains("nux") || os.contains("nix"))) {
platform = "linux_64"
} else if (is64bitIntel && os.contains("mac")) {
platform = "osx_64"
}
into('META-INF/lib/' + platform) {
from 'target/release/' + System.mapLibraryName('weld_java')
}
// Attempt to copy native libraries for the various platforms to the jar.
into('META-INF/lib/osx_64') {
from 'target/x86_64-apple-darwin/release/libweld_java.dylib'
}
into('META-INF/lib/linux_64') {
from 'target/x86_64-unknown-linux-gnu/release/libweld_java.so'
}
dependsOn generateJniHeaders
dependsOn compileWeld
mustRunAfter compileWeldLinux
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
def target = version.contains('SNAPSHOT') ? 'snapshot' : 'release'
maven {
url "$rootProject.projectDir/../repo/$target"
}
}
}