forked from databricks/sjsonnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.mill
More file actions
278 lines (255 loc) · 9.54 KB
/
build.mill
File metadata and controls
278 lines (255 loc) · 9.54 KB
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
import mill._
import scalalib._
import publish._
import scalajslib._
import scalanativelib._
import scalanativelib.api._
import scalajslib.api._
import scalafmt._
import scalalib.api.JvmWorkerUtil
import $ivy.`com.lihaoyi::mill-contrib-jmh:`
import $ivy.`com.lihaoyi::mill-contrib-versionfile:`
import contrib.versionfile.VersionFileModule
import contrib.jmh.JmhModule
import java.util.Base64
trait SjsonnetPublishModule extends PublishModule {
def artifactName = "sjsonnet"
def publishVersion = sjsonnet.currentVersion().toString
def pomSettings = PomSettings(
description = artifactName(),
organization = "com.databricks",
url = "https://github.com/databricks/sjsonnet",
licenses = Seq(License.MIT),
versionControl = VersionControl.github("databricks", "sjsonnet"),
developers = Seq(
Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi")
)
)
}
trait SjsonnetCrossModule extends CrossScalaModule with ScalafmtModule {
def crossValue: String
def ivyDeps = Agg(
ivy"com.lihaoyi::fastparse::3.1.1",
ivy"com.lihaoyi::pprint::0.9.0",
ivy"com.lihaoyi::ujson::4.1.0",
ivy"com.lihaoyi::scalatags::0.13.1",
ivy"org.scala-lang.modules::scala-collection-compat::2.13.0"
)
def generatedSources = T {
os.write(
T.ctx().dest / "Version.scala",
s"""package sjsonnet
|object Version{
| val version = ${pprint.Util.literalize(sjsonnet.currentVersion().toString)}
|}
|""".stripMargin
)
Seq(PathRef(T.ctx().dest / "Version.scala"))
}
def scalacOptions = Seq("-deprecation", "-Werror") ++ (
if (!JvmWorkerUtil.isScala3(scalaVersion()))
Seq(
"-opt:l:inline",
"-feature",
"-opt-inline-from:sjsonnet.*,sjsonnet.**",
"-Xsource:3",
"-Xlint:_"
) ++ (if (scalaVersion() startsWith "2.13") Seq("-Wconf:origin=scala.collection.compat.*:s")
else Seq("-Xfatal-warnings", "-Ywarn-unused:-nowarn"))
else Seq[String]("-Wconf:origin=scala.collection.compat.*:s", "-Xlint:all")
)
trait CrossTests extends ScalaModule with TestModule.Utest {
def ivyDeps = Agg(ivy"com.lihaoyi::utest::0.8.5")
def testSandboxWorkingDir = false
def forkEnv = Map("MILL_WORKSPACE_ROOT" -> T.workspace.toString())
}
}
trait SjsonnetJvmNative extends ScalaModule {
def ivyDeps = super.ivyDeps() ++ Agg(
ivy"com.lihaoyi::os-lib::0.11.4",
ivy"com.lihaoyi::mainargs::0.7.6"
)
}
object sjsonnet extends VersionFileModule {
private val scalaVersions = Seq("3.3.6", "2.13.16", "2.12.20")
private val stackSize = "100m"
private val stackSizekBytes = 100 * 1024
object js extends Cross[SjsonnetJsModule](scalaVersions)
trait SjsonnetJsModule extends SjsonnetCrossModule with ScalaJSModule with SjsonnetPublishModule {
def millSourcePath = super.millSourcePath / os.up
def scalaJSVersion = "1.17.0"
def sources = T.sources(
this.millSourcePath / "src",
this.millSourcePath / "src-js",
this.millSourcePath / "src-jvm-js"
)
object test extends ScalaJSTests with CrossTests {
def jsEnvConfig = JsEnvConfig.NodeJs(args = List("--stack-size=" + stackSizekBytes))
def resources = T.sources(
this.millSourcePath / "resources" / "test_suite",
this.millSourcePath / "resources" / "go_test_suite"
)
def generatedSources = T {
resources().map(_.path).flatMap { testSuite =>
val fileNames = os.walk(testSuite).filter(os.isFile).map { k =>
val name = k.relativeTo(testSuite).toString
.replaceAll("/", "_").replaceAll("\\.", "_").replaceAll("-", "_")
val values = Base64.getEncoder.encodeToString(os.read.bytes(k)).grouped(65535).toSeq
val fName = T.ctx().dest / s"${testSuite.last}_$name.scala"
os.write.over(
fName,
s"""package sjsonnet
|
|import java.util.Base64
|
|object ${testSuite.last}_$name {
| def contentArr = Seq(
| ${values.map("\"" + _ + "\"").mkString(",\n ")}
| )
| def content() = Base64.getDecoder().decode(contentArr.mkString)
|}
|""".stripMargin
)
k -> fName
}.toMap
val testSuiteClassPath = T.ctx().dest / s"TestResources_${testSuite.last}.scala"
os.write.over(
testSuiteClassPath,
s"""package sjsonnet
|
|object TestResources_${testSuite.last}{
| val files: Map[String, () => Array[Byte]] = Map(
|""".stripMargin
)
for ( (k, fName) <- fileNames) {
os.write.append(
testSuiteClassPath,
s""" "${k.relativeTo(testSuite)}" -> ${fName.baseName}.content _,
|""".stripMargin
)
}
os.write.append(
testSuiteClassPath,
s""" )
|}
|""".stripMargin
)
Seq(PathRef(testSuiteClassPath)) ++ fileNames.values.map(k => PathRef(k))
}
}
}
}
object native extends Cross[SjsonnetNativeModule](scalaVersions)
trait SjsonnetNativeModule
extends SjsonnetCrossModule
with ScalaNativeModule
with SjsonnetPublishModule
with SjsonnetJvmNative {
def millSourcePath = super.millSourcePath / os.up
def scalaNativeVersion = "0.5.8"
def sources = T.sources(
this.millSourcePath / "src",
this.millSourcePath / "src-native",
this.millSourcePath / "src-jvm-native"
)
def ivyDeps = super.ivyDeps() ++
Agg(ivy"com.github.lolgab::scala-native-crypto::0.2.0")
def nativeLinkingOptions = super.nativeLinkingOptions() ++
Seq("-L/usr/local/opt/openssl@3/lib")
def releaseMode = ReleaseMode.ReleaseFull
def nativeLTO = LTO.Full
def nativeMultithreading = None
object test extends ScalaNativeTests with CrossTests {
def releaseMode = ReleaseMode.Debug
def nativeMultithreading = None
def forkEnv = super.forkEnv() ++ Map(
"SCALANATIVE_THREAD_STACK_SIZE" -> stackSize
)
def nativeLTO = LTO.None
}
}
object jvm extends Cross[SjsonnnetJvmModule](scalaVersions)
trait SjsonnnetJvmModule
extends SjsonnetCrossModule
with ScalaModule
with SjsonnetPublishModule
with SjsonnetJvmNative {
def millSourcePath = super.millSourcePath / os.up
def mainClass = Some("sjsonnet.SjsonnetMain")
def sources = T.sources(
this.millSourcePath / "src",
this.millSourcePath / "src-jvm",
this.millSourcePath / "src-jvm-native"
)
def ivyDeps = super.ivyDeps() ++ Agg(
ivy"org.json:json:20250107",
ivy"org.tukaani:xz::1.10",
ivy"org.lz4:lz4-java::1.8.0",
ivy"org.yaml:snakeyaml::2.4",
ivy"com.google.re2j:re2j:1.8"
)
object test extends ScalaTests with CrossTests {
def forkArgs = Seq("-Xss" + stackSize)
}
object client extends JavaModule with SjsonnetPublishModule {
def artifactName = "sjsonnet-server"
def ivyDeps = Agg(
ivy"org.scala-sbt.ipcsocket:ipcsocket:1.6.3".exclude(
"net.java.dev.jna" -> "jna",
"net.java.dev.jna" -> "jna-platform"
)
)
object test extends JavaTests with TestModule.Junit4
}
object server extends ScalaModule with SjsonnetPublishModule {
def artifactName = "sjsonnet-server"
def scalaVersion = SjsonnnetJvmModule.this.crossValue
def moduleDeps = Seq(SjsonnnetJvmModule.this, client)
def ivyDeps = Agg(
ivy"org.scala-sbt.ipcsocket:ipcsocket:1.6.3".exclude(
"net.java.dev.jna" -> "jna",
"net.java.dev.jna" -> "jna-platform"
),
ivy"net.java.dev.jna:jna:5.17.0",
ivy"net.java.dev.jna:jna-platform:5.17.0"
)
override def prependShellScript = mill.util.Jvm.universalScript(
shellCommands = {
def java(mainClass: String) =
s"""exec java -DSJSONNET_EXECUTABLE=$$0 -DSJSONNET_VERSION=${sjsonnet.currentVersion().toString} $$JAVA_OPTS -cp $$0 $mainClass "$$@""""
s"""case "$$1" in
| -i | --interactive )
| ${java("sjsonnet.SjsonnetMain")}
| ;;
| *)
| ${java("sjsonnet.client.SjsonnetClientMain")}
| ;;
|esac""".stripMargin
},
cmdCommands = {
def java(mainClass: String) =
s"""java -DSJSONNET_EXECUTABLE=%~dpnx0 -DSJSONNET_VERSION=${sjsonnet.currentVersion().toString} %JAVA_OPTS% -cp %~dpnx0 $mainClass %*"""
s"""if "%1" == "-i" set _I_=true
|if "%1" == "--interactive" set _I_=true
|if defined _I_ (
| ${java("sjsonnet.SjsonnetMain")}
|) else (
| ${java("sjsonnet.client.SjsonnetClientMain")}
|)""".stripMargin
}
)
object test extends ScalaTests with TestModule.Junit4
}
object bench extends ScalaModule with JmhModule with SjsonnetJvmNative {
def scalaVersion = SjsonnnetJvmModule.this.crossValue
def moduleDeps = Seq(SjsonnnetJvmModule.this)
def jmhCoreVersion = "1.37"
def sources = T.sources(
this.millSourcePath / os.up / os.up / "bench" / "src",
this.millSourcePath / os.up / "test" / "src" / "sjsonnet" / "OldRenderer.scala",
this.millSourcePath / os.up / "test" / "src" / "sjsonnet" / "OldYamlRenderer.scala"
)
def scalacOptions = SjsonnnetJvmModule.this.scalacOptions
}
}
}