forked from luben/zstd-jni
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
173 lines (134 loc) · 5.22 KB
/
build.sbt
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
name := "zstd-jni"
version := "1.2.0"
scalaVersion := "2.12.2"
enablePlugins(JniPlugin, SbtOsgi)
autoScalaLibrary := false
crossPaths := false
logBuffered in Test := false
parallelExecution in Test := false
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.0.1" % "test",
"org.scalacheck" %% "scalacheck" % "1.13.4" % "test"
)
javacOptions ++= Seq("-source", "1.7", "-target", "1.7")
javacOptions in doc := Seq("-source", "1.7")
// sbt-jni configuration
jniLibraryName := "zstd"
jniNativeClasses := Seq(
"com.github.luben.zstd.Zstd",
"com.github.luben.zstd.ZstdDictCompress",
"com.github.luben.zstd.ZstdDictDecompress",
"com.github.luben.zstd.ZstdOutputStream",
"com.github.luben.zstd.ZstdInputStream",
"com.github.luben.zstd.ZstdDirectBufferDecompressingStream",
"com.github.luben.zstd.ZstdDirectBufferCompressingStream"
)
jniLibSuffix := (System.getProperty("os.name").toLowerCase match {
case os if os startsWith "mac" => "dylib"
case os if os startsWith "darwin" => "dylib"
case os if os startsWith "win" => "dll"
case _ => "so"
})
jniNativeCompiler := "gcc"
jniUseCpp11 := false
jniCppExtensions := Seq("c")
jniGccFlags ++= Seq(
"-std=c99", "-Wundef", "-Wshadow", "-Wcast-align", "-Wstrict-prototypes",
"-Wno-unused-variable", "-DZSTD_LEGACY_SUPPORT=4"
) ++ (System.getProperty("os.arch") match {
case "amd64"|"x86_64" => Seq("-msse4")
case "i386" => Seq("-msse4")
case _ => Seq()
})
// compilation on Windows with MSYS/gcc needs extra flags in order
// to produce correct DLLs, also it alway produces position independent
// code so let's remove the flag and silence a warning
jniGccFlags := (
if (System.getProperty("os.name").toLowerCase startsWith "win")
jniGccFlags.value.filterNot(_ == "-fPIC") ++
Seq("-D_JNI_IMPLEMENTATION_", "-Wl,--kill-at", "-static-libgcc", "-static-libstdc++")
else
jniGccFlags.value
)
// Special case the jni platform header on windows (use the one from the repo)
// because the JDK provided one is not compatible with the standard compliant
// compilers but only with VisualStudio - our build uses MSYS/gcc
jniJreIncludes := {
jniJdkHome.value.fold(Seq.empty[String]) { home =>
val absHome = home.getAbsolutePath
if (System.getProperty("os.name").toLowerCase startsWith "win") {
Seq(s"include").map(file => s"-I$absHome/../$file") ++
Seq(s"""-I${sourceDirectory.value / "windows" / "include"}""")
} else {
val jniPlatformFolder = System.getProperty("os.name").toLowerCase match {
case os if os.startsWith("mac") => "darwin"
case os => os
}
// in a typical installation, JDK files are one directory above the
// location of the JRE set in 'java.home'
Seq(s"include", s"include/$jniPlatformFolder").map(file => s"-I$absHome/../$file")
}
}
}
jniIncludes ++= Seq("-I" + jniNativeSources.value.toString,
"-I" + jniNativeSources.value.toString + "/common",
"-I" + jniNativeSources.value.toString + "/legacy"
)
// Where to put the compiled binaries
jniBinPath := {
val os = System.getProperty("os.name").toLowerCase.replace(' ','_') match {
case os if os startsWith "win" => "win"
case os if os startsWith "mac" => "darwin"
case os => os
}
val arch = System.getProperty("os.arch")
(target in Compile).value / "classes" / os / arch
}
// Where to put the generated headers for the JNI lib
jniHeadersPath := (target in Compile).value / "classes" / "include"
// JaCoCo
import de.johoop.jacoco4sbt._
jacoco.settings
jacoco.reportFormats in jacoco.Config := Seq(
XMLReport(encoding = "utf-8"),
ScalaHTMLReport(withBranchCoverage = true)
)
// Sonatype
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (version.value.toString.trim.endsWith("SNAPSHOT"))
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
}
publishMavenStyle := true
publishArtifact in Test := false
pomIncludeRepository := { _ => false }
organization := "com.github.luben"
licenses := Seq("BSD 2-Clause License" -> url("https://opensource.org/licenses/BSD-2-Clause"))
description := "JNI bindings for Zstd native library that provides fast and high " +
"compression lossless algorithm for Java and all JVM languages."
pomExtra := (
<url>https://github.com/luben/zstd-jni</url>
<scm>
<url>git@github.com:luben/zstd-jni.git</url>
<connection>scm:git:git@github.com:luben/zstd-jni.git</connection>
</scm>
<developers>
<developer>
<id>karavelov</id>
<name>Luben Karavelov</name>
<email>karavelov@gmail.com</email>
<organization>com.github.luben</organization>
<organizationUrl>https://github.com/luben</organizationUrl>
</developer>
</developers>
)
// OSGI
osgiSettings
OsgiKeys.bundleSymbolicName := "com.github.luben.zstd-jni"
OsgiKeys.exportPackage := Seq(s"""com.github.luben.zstd;version="${version.value}"""")
OsgiKeys.privatePackage := Seq("com.github.luben.zstd.util", "include",
"linux.amd64", "linux.i386", "linux.aarch64", "linux.ppc64",
"aix.ppc64", "darwin.x86_64", "win.amd64", "win.x86"
)