-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.sc
312 lines (259 loc) · 10.1 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
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
import mill.define.Target
import mill.util.Jvm
import $ivy.`com.lihaoyi::mill-contrib-bloop:$MILL_VERSION`
import $ivy.`io.github.davidgregory084::mill-tpolecat::0.3.5`
import $ivy.`io.chris-kipp::mill-ci-release::0.1.9`
import os.Path
import mill._
import scalalib._
import publish._
import scalajslib._
import scalanativelib._
import mill.scalajslib.api._
import io.github.davidgregory084._
import io.kipp.mill.ci.release.CiReleaseModule
object versions {
val scala212Version = "2.12.1"
val scala213Version = "2.13.11"
val scala3Version = "3.3.3"
val scalaJSVersion = "1.14.0"
val scalaNativeVersion = "0.4.17"
val munitVersion = "1.0.0-M9"
val fs2Version = "3.10.0"
val weaverVersion = "0.8.3"
val jsoniterVersion = "2.17.0"
val scala213 = "2.13"
val scala212 = "2.12"
val scala3 = "3"
val crossMap = Map(
"2.13" -> scala213Version,
"2.12" -> scala212Version,
"3" -> scala3Version
)
}
import versions._
object core extends RPCCrossPlatformModule { cross =>
def crossPlatformIvyDeps: T[Agg[Dep]] = Agg(
ivy"com.github.plokhotnyuk.jsoniter-scala::jsoniter-scala-macros::${jsoniterVersion}"
)
object jvm extends mill.Cross[JvmModule](scala213, scala3)
class JvmModule(cv: String) extends cross.JVM(cv) {
object test extends MunitTests
}
object js extends mill.Cross[JsModule](scala213, scala3)
class JsModule(cv: String) extends cross.JS(cv) {
object test extends MunitTests
}
object native extends mill.Cross[NativeModule](scala213, scala3)
class NativeModule(cv: String) extends cross.Native(cv) {
object test extends MunitTests
}
}
object fs2 extends RPCCrossPlatformModule { cross =>
override def crossPlatformModuleDeps = Seq(core)
def crossPlatformIvyDeps: T[Agg[Dep]] = Agg(
ivy"co.fs2::fs2-core::${fs2Version}"
)
object jvm extends mill.Cross[JvmModule](scala213, scala3)
class JvmModule(cv: String) extends cross.JVM(cv) {
object test extends WeaverTests
}
object js extends mill.Cross[JsModule](scala213, scala3)
class JsModule(cv: String) extends cross.JS(cv) {
object test extends WeaverTests
}
object native extends mill.Cross[NativeModule](scala213, scala3)
class NativeModule(cv: String) extends cross.Native(cv) {
object test extends WeaverTests
}
}
object examples extends mill.define.Module {
object server extends ScalaModule {
def ivyDeps = Agg(ivy"co.fs2::fs2-io:${fs2Version}")
def moduleDeps = Seq(fs2.jvm(versions.scala213))
def scalaVersion = versions.scala213Version
}
object client extends ScalaModule {
def ivyDeps = Agg(ivy"co.fs2::fs2-io:$fs2Version")
def moduleDeps = Seq(fs2.jvm(versions.scala213))
def scalaVersion = versions.scala213Version
def forkEnv: Target[Map[String, String]] = T {
val assembledServer = server.assembly()
super.forkEnv() ++ Map("SERVER_JAR" -> assembledServer.path.toString())
}
}
}
// #############################################################################
// COMMON SETUP
// #############################################################################
trait RPCCrossPlatformModule extends Module { shared =>
def artifactName = s"jsonrpclib-${millModuleSegments.parts.mkString("-")}"
def crossPlatformIvyDeps = T { Agg.empty[Dep] }
def crossPlatformModuleDeps: Seq[Module] = Seq()
def crossPlatformTestModuleDeps: Seq[Module] = Seq()
class JVM(val crossVersion: String) extends PlatformSpecific {
override def platformLabel: String = "jvm"
trait WeaverTests extends Tests {
def ivyDeps = super.ivyDeps() ++ Agg(ivy"com.disneystreaming::weaver-cats::$weaverVersion")
def testFramework = "weaver.framework.CatsEffect"
}
trait MunitTests extends Tests with TestModule.Munit {
def ivyDeps = super.ivyDeps() ++ Agg(ivy"org.scalameta::munit::$munitVersion")
}
trait Tests extends super.Tests {
override def sources = T.sources(computeSources(this).map(PathRef(_)))
override def moduleDeps = super.moduleDeps ++ shared.crossPlatformTestModuleDeps.flatMap(matchingCross)
}
}
class JS(val crossVersion: String) extends PlatformSpecific with ScalaJSModule {
override def platformLabel: String = "js"
override def scalaJSVersion = versions.scalaJSVersion
override def scalacOptions = T {
super.scalacOptions().filterNot(_ == "-Ywarn-unused:params")
}
override def moduleKind = T(ModuleKind.CommonJSModule)
override def skipIdea = true
trait WeaverTests extends Tests {
def ivyDeps = super.ivyDeps() ++ Agg(ivy"com.disneystreaming::weaver-cats::$weaverVersion")
def testFramework = "weaver.framework.CatsEffect"
}
trait MunitTests extends Tests with TestModule.Munit {
def ivyDeps = super.ivyDeps() ++ Agg(ivy"org.scalameta::munit::$munitVersion")
}
trait Tests extends super.Tests with mill.contrib.Bloop.Module {
override def sources = T.sources(computeSources(this).map(PathRef(_)))
override def skipIdea = true
override def skipBloop = true
override def moduleDeps = super.moduleDeps ++ shared.crossPlatformTestModuleDeps.flatMap(matchingCross).collect {
case m: ScalaJSModule => m
}
}
}
class Native(val crossVersion: String) extends PlatformSpecific with ScalaNativeModule {
override def platformLabel: String = "native"
override def scalaNativeVersion = versions.scalaNativeVersion
override def scalacOptions = T {
super
.scalacOptions()
.filterNot { opts =>
Seq(
"-Ywarn-extra-implicit",
"-Xlint:constant"
).contains(opts)
}
.filterNot(_.startsWith("-Ywarn-unused"))
}
override def skipIdea = true
override def skipBloop = true
trait WeaverTests extends Tests {
def ivyDeps = super.ivyDeps() ++ Agg(ivy"com.disneystreaming::weaver-cats::$weaverVersion")
def testFramework = "weaver.framework.CatsEffect"
}
trait MunitTests extends Tests with TestModule.Munit {
def ivyDeps = super.ivyDeps() ++ Agg(ivy"org.scalameta::munit::$munitVersion")
}
trait Tests extends super.Tests with mill.contrib.Bloop.Module {
override def nativeLinkStubs = true
override def skipIdea = true
override def skipBloop = true
override def sources = T.sources(computeSources(this).map(PathRef(_)))
override def moduleDeps = super.moduleDeps ++ shared.crossPlatformTestModuleDeps.flatMap(matchingCross).collect {
case m: ScalaNativeModule => m
}
}
}
trait PlatformSpecific extends JsonRPCModule with mill.contrib.Bloop.Module { self =>
def platformLabel: String
def crossVersion: String
override def scalaVersion = versions.crossMap(crossVersion)
override def millSourcePath = shared.millSourcePath
override def ivyDeps = super.ivyDeps() ++ shared.crossPlatformIvyDeps()
def samePlatform(module: Module): Boolean =
self match {
case _: ScalaJSModule => module.isInstanceOf[ScalaJSModule]
case _: ScalaNativeModule => module.isInstanceOf[ScalaNativeModule]
case _ =>
!(module.isInstanceOf[ScalaJSModule] || module
.isInstanceOf[ScalaNativeModule])
}
def sameScalaVersion(module: Module): Boolean = {
// Don't know why, pattern matching didn't seem to work here
module.isInstanceOf[PlatformSpecific] && (module.asInstanceOf[PlatformSpecific].crossVersion == self.crossVersion)
}
def sameCross(module: Module) = samePlatform(module) && sameScalaVersion(module)
def matchingCross(module: Module): Seq[JsonRPCModule] = module match {
case m: RPCCrossPlatformModule =>
m.millModuleDirectChildren.collect {
case cross: Cross[_] =>
cross.millModuleDirectChildren.collect {
case child: JsonRPCModule if sameCross(child) => child
}
case child: JsonRPCModule if sameCross(child) => Seq(child)
}.flatten
case _ => Seq()
}
override def moduleDeps: Seq[JsonRPCModule] =
shared.crossPlatformModuleDeps.flatMap(matchingCross)
override def artifactName = shared.artifactName
def computeSources(module: mill.define.Module): Seq[os.Path] = {
val modulePath = module.millSourcePath
module match {
case _: ScalaJSModule =>
Seq(
modulePath / 'src,
modulePath / s"src-js",
modulePath / s"src-jvm-js",
modulePath / s"src-js-native"
)
case _: ScalaNativeModule =>
Seq(
modulePath / 'src,
modulePath / s"src-native",
modulePath / s"src-jvm-native",
modulePath / s"src-js-native"
)
case _ =>
Seq(
modulePath / 'src,
modulePath / s"src-jvm",
modulePath / s"src-jvm-js",
modulePath / s"src-jvm-native"
)
}
}
override def sources = T.sources(computeSources(self).map(PathRef(_)))
override def skipBloop = {
self match {
case _: ScalaJSModule => true
case _: ScalaNativeModule => true
case _ => false
}
} && { crossVersion != scala213 }
}
}
trait JsonRPCModule extends ScalaModule with CiReleaseModule with scalafmt.ScalafmtModule {
def scalafmt() = T.command(reformat())
def fmt() = T.command(reformat())
def refreshedEnv = T.input(T.ctx().env)
def publishVersion = T {
if (refreshedEnv().contains("CI")) super.publishVersion()
else "dev"
}
override def scalacOptions = T {
super.scalacOptions() ++ Tpolecat.scalacOptionsFor(scalaVersion())
}
override def forkEnv = T { refreshedEnv() }
def pomSettings = PomSettings(
description = "A Scala jsonrpc library",
organization = "tech.neander",
url = "https://github.com/neandertech/jsonrpclib",
licenses = Seq(License.`Apache-2.0`),
versionControl = VersionControl(Some("https://github.com/neandertech/jsonrpclib")),
developers = Seq(
Developer("Baccata", "Olivier Mélois", "https://github.com/baccata")
)
)
override def sonatypeUri = "https://s01.oss.sonatype.org/service/local"
override def sonatypeSnapshotUri =
"https://s01.oss.sonatype.org/content/repositories/snapshots"
}