-
Notifications
You must be signed in to change notification settings - Fork 55
/
build.sc
189 lines (172 loc) · 6.42 KB
/
build.sc
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
import mill._, scalalib._, publish._, scalajslib._, scalanativelib._, scalanativelib.api._
import $ivy.`com.lihaoyi::mill-contrib-jmh:`
import contrib.jmh.JmhModule
val sjsonnetVersion = "0.4.14"
val scalaVersions = Seq("2.12.20", "2.13.15")
trait SjsonnetCrossModule extends CrossScalaModule with PublishModule {
def crossValue: String
def artifactName = "sjsonnet"
def ivyDeps = Agg(
ivy"com.lihaoyi::fastparse::2.3.3",
ivy"com.lihaoyi::pprint::0.6.6",
ivy"com.lihaoyi::ujson::1.3.15",
ivy"com.lihaoyi::scalatags::0.9.4",
ivy"org.scala-lang.modules::scala-collection-compat::2.11.0"
)
def publishVersion = sjsonnetVersion
def generatedSources = T{
os.write(
T.ctx().dest / "Version.scala",
s"""package sjsonnet
|object Version{
| val version = ${pprint.Util.literalize(sjsonnetVersion)}
|}
|""".stripMargin
)
Seq(PathRef(T.ctx().dest / "Version.scala"))
}
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 CrossTests extends ScalaModule with TestModule.Utest {
def ivyDeps = Agg(ivy"com.lihaoyi::utest::0.8.2")
}
}
trait SjsonnetJvmNative extends ScalaModule {
def ivyDeps = super.ivyDeps() ++ Agg(
ivy"com.lihaoyi::os-lib::0.7.8",
ivy"com.lihaoyi::mainargs::0.2.5"
)
}
object sjsonnet extends Module {
object js extends Cross[SjsonnetJsModule](scalaVersions)
trait SjsonnetJsModule extends SjsonnetCrossModule with ScalaJSModule{
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 sources = T.sources(
this.millSourcePath / "src",
this.millSourcePath / "src-js",
this.millSourcePath / "src-jvm-js"
)
}
}
object native extends Cross[SjsonnetNativeModule](scalaVersions)
trait SjsonnetNativeModule extends SjsonnetCrossModule with ScalaNativeModule with SjsonnetJvmNative {
def millSourcePath = super.millSourcePath / os.up
def scalaNativeVersion = "0.4.17"
def sources = T.sources(
this.millSourcePath / "src",
this.millSourcePath / "src-native",
this.millSourcePath / "src-jvm-native"
)
def releaseMode = ReleaseMode.ReleaseFast
def nativeLTO = LTO.Thin
object test extends ScalaNativeTests with CrossTests {
def releaseMode = ReleaseMode.Debug
def scalaNativeVersion = SjsonnetNativeModule.this.scalaNativeVersion
def nativeLTO = LTO.None
def sources = T.sources(
this.millSourcePath / "src",
this.millSourcePath / "src-native",
this.millSourcePath / "src-jvm-native"
)
}
}
object jvm extends Cross[SjsonnnetJvmModule](scalaVersions)
trait SjsonnnetJvmModule extends SjsonnetCrossModule with ScalaModule 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:20240303",
ivy"org.tukaani:xz::1.10",
ivy"org.lz4:lz4-java::1.8.0",
ivy"org.yaml:snakeyaml::1.33",
ivy"com.google.re2j:re2j:1.7",
)
def scalacOptions = Seq("-opt:l:inline", "-opt-inline-from:sjsonnet.**")
object test extends ScalaTests with CrossTests {
def forkOptions = Seq("-Xss100m")
def sources = T.sources(
this.millSourcePath / "src",
this.millSourcePath / "src-jvm",
this.millSourcePath / "src-jvm-native"
)
}
object client extends JavaModule {
def ivyDeps = Agg(
ivy"org.scala-sbt.ipcsocket:ipcsocket:1.0.0".exclude(
"net.java.dev.jna" -> "jna",
"net.java.dev.jna" -> "jna-platform"
)
)
object test extends JavaModuleTests with TestModule.Junit4
}
object server extends ScalaModule{
def scalaVersion = SjsonnnetJvmModule.this.crossValue
def moduleDeps = Seq(SjsonnnetJvmModule.this, client)
def ivyDeps = Agg(
ivy"org.scala-sbt.ipcsocket:ipcsocket:1.0.0".exclude(
"net.java.dev.jna" -> "jna",
"net.java.dev.jna" -> "jna-platform"
),
ivy"net.java.dev.jna:jna:4.5.0",
ivy"net.java.dev.jna:jna-platform:4.5.0"
)
override def prependShellScript = mill.util.Jvm.universalScript(
shellCommands = {
def java(mainClass: String) =
s"""exec java -DSJSONNET_EXECUTABLE=$$0 -DSJSONNET_VERSION=$sjsonnetVersion $$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=$sjsonnetVersion %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
}
}
}