Repository navigation
Expand file tree
/
Copy pathbuild.mill
More file actions
341 lines (318 loc) · 16.4 KB
/
Copy pathbuild.mill
File metadata and controls
341 lines (318 loc) · 16.4 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
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
//| mill-version: 1.3.1
//| mill-jvm-version: zulu:25.0.3
//| mill-jvm-opts: ["-Xss8m", "-Xmx6g"]
//| mvnDeps: ["com.github.lolgab::mill-scalablytyped::0.4.2"]
package build
// =================================================================================================
// dapr4s build (Mill)
//
// Modules:
// core.jvm / core.js the published library (dapr4s_3 / dapr4s_sjs1_3); `core.<p>.test` are its
// unit tests (every test source outside an `integration/` directory)
// integration.jvm / .js the Docker-based integration suites (never published)
// stFacades the ScalablyTyped-generated Scala.js facades (never published on its own;
// its .sjsir are embedded into dapr4s_sjs1_3, see core.js)
//
// Source layout: src/{shared,jvm,js} and test/{shared,jvm,js}. The modules point INTO it
// rather than owning it; all build output goes to out/.
//
// JDK 25 is required for stable virtual-thread support (no carrier pinning on `synchronized`), see
// AGENTS.md: the `mill-jvm-version` header above makes Mill download and use Zulu 25 for itself and
// for every forked JVM (tests), whatever JDK is on the PATH.
// =================================================================================================
import mill.*
import mill.api.{BuildCtx, ModuleRef}
import mill.scalalib.*
import mill.scalajslib.*
import mill.scalajslib.api.*
import mill.javalib.publish.*
import com.github.lolgab.mill.scalablytyped.ScalablyTyped
// Single source of truth for the nightly (scripts read it with `./mill show scala3Nightly`).
def scala3Nightly: T[String] = Task(Versions.scala3Nightly)
/** The version of every published artifact, computed from git like sbt-dynver + sbt-ci-release did (see Dynver in
* buildsupport.mill).
*/
def publishVersion: T[String] = Task.Input(Dynver.version(BuildCtx.workspaceRoot))
object nightliesJvmWorker extends JvmWorkerModule {
override def repositoriesTask = Task.Anon(super.repositoriesTask() ++ Seq(Repos.nightlies))
}
/** Every module compiled by dapr4s's nightly. */
trait NightlyModule extends ScalaModule {
override def jvmWorker = ModuleRef(nightliesJvmWorker)
def scalaVersion = Versions.scala3Nightly
override def repositoriesTask = Task.Anon(super.repositoriesTask() ++ Seq(Repos.nightlies))
}
/** ...and with dapr4s's compiler flags. */
trait Dapr4sFlags extends NightlyModule {
override def scalacOptions = Task(super.scalacOptions() ++ Versions.compilerFlags)
}
/** Unit tests: every source of the module's test trees outside an `integration/` directory. */
trait UnitTestSources extends JavaModule {
override def allSourceFiles = Task {
super.allSourceFiles().filterNot(p => Dapr4sPaths.isIntegrationSource(p.path))
}
}
/** POM metadata. Must stay identical to what sbt (and scala-cli before it) published up to 3.0.0. */
trait Dapr4sPublish extends PublishModule {
def publishVersion: T[String] = build.publishVersion()
def pomSettings: T[PomSettings] = Task(Dapr4sPom.settings(artifactName()))
// Mill's POM renderer differs from sbt's (no <organization>, an empty <email>, element order), so
// the POM is rendered by Dapr4sPom in exactly the sbt layout: the published POMs stay byte-for-byte
// comparable with the 3.0.0 ones (only the version differs).
def pomProperties: T[Seq[(String, String)]] = Task(Seq.empty[(String, String)])
override def pom: T[PathRef] = Task {
val path = Task.dest / s"${artifactId()}-${publishVersion()}.pom"
os.write.over(path, Dapr4sPom.render(artifactMetadata(), artifactName(), publishXmlDeps(), pomProperties()))
PathRef(path)
}
}
trait Dapr4sJs extends ScalaJSModule {
def scalaJSVersion = Versions.scalaJS
}
// -------------------------------------------------------------------------------------------------
// The library
// -------------------------------------------------------------------------------------------------
object core extends Module {
object jvm extends Dapr4sFlags with Dapr4sPublish {
def artifactName = "dapr4s"
// Since Scala 3.8 Mill depends on `scala-library` 3.x directly; sbt (and so every published POM up
// to 3.0.0) depends on `scala3-library_3`, which brings that very `scala-library` transitively.
// Keep sbt's coordinate: same classpath, same POM.
override def scalaLibraryMvnDeps = Task(Seq(mvn"org.scala-lang::scala3-library:${scalaVersion()}"))
override def sources = Task.Sources(Dapr4sPaths.src / "shared", Dapr4sPaths.src / "jvm")
override def resources = Task.Sources()
override def mvnDeps = Seq(
mvn"io.dapr:dapr-sdk:${Versions.daprJava}",
mvn"io.dapr:dapr-sdk-actors:${Versions.daprJava}",
mvn"io.dapr:dapr-sdk-workflows:${Versions.daprJava}",
)
object test extends ScalaTests with TestModule.Munit with UnitTestSources {
override def sources = Task.Sources(Dapr4sPaths.test / "shared", Dapr4sPaths.test / "jvm")
override def resources = Task.Sources()
// One forked JVM, suites one after another (as sbt's forked `Test` ran them): the server
// suites start real HTTP servers and wait for their port with a short timeout.
override def testParallelism = false
override def mvnDeps = Seq(
mvn"org.scalameta::munit:${Versions.munit}",
mvn"com.lihaoyi::upickle:${Versions.upickle}",
)
}
}
object js extends Dapr4sFlags with Dapr4sJs with Dapr4sPublish {
def artifactName = "dapr4s"
override def sources = Task.Sources(Dapr4sPaths.src / "shared", Dapr4sPaths.src / "js")
override def resources = Task.Sources()
// js.async/js.await (the JS internal layer) need ES2017 output.
override def esFeatures = Task(super.esFeatures().withESVersion(ESVersion.ES2017))
override def mvnDeps = Seq(
// java.time on Scala.js (java.time.Instant is part of the public WorkflowSnapshot/Models API).
mvn"io.github.cquiroz::scala-java-time::${Versions.scalaJavaTime}",
// Link-time runtime libraries of the EMBEDDED facade classes (the versions the converter's
// generated code is written against). They are regular POM dependencies of dapr4s_sjs1_3.
mvn"com.olvind::scalablytyped-runtime::${Versions.scalablytypedRuntime}",
mvn"org.scala-js::scalajs-dom::${Versions.scalajsDom}",
)
// stFacades is a COMPILE-TIME dependency only as far as consumers are concerned: its .sjsir are
// embedded into dapr4s_sjs1_3.jar (`jar` below), so the POM must not name it (it is never
// published). It stays a moduleDep so its classes are on every classpath of this build.
override def moduleDeps = Seq(stFacades)
override def publishXmlDeps = Task.Anon {
super.publishXmlDeps().filterNot(_.artifact.id == stFacades.artifactId())
}
override def publishMvnDeps = Task.Anon {
val prev = super.publishMvnDeps()
(root: Map[coursier.core.Module, String], bom: coursier.core.DependencyManagement.Map) =>
prev(root, bom).filterNot(_.artifact.id.startsWith("dapr4s-st-facades"))
}
override def jar: T[PathRef] = Task {
val out = Task.dest / "out.jar"
mill.util.Jvm.createJar(
out,
localClasspath().map(_.path).filter(os.exists) :+ stFacades.embeddedFacades().path,
manifest(),
)
PathRef(out)
}
object test extends ScalaJSTests with TestModule.Munit with UnitTestSources {
override def sources = Task.Sources(Dapr4sPaths.test / "shared", Dapr4sPaths.test / "js")
override def resources = Task.Sources()
override def mvnDeps = Seq(
mvn"org.scalameta::munit::${Versions.munit}",
mvn"com.lihaoyi::upickle::${Versions.upickle}",
)
}
}
}
/** The two example service mains of test/jvm/apps as runnable fat jars (`k8s.<service>.assembly`), for
* scripts/k8s-test.sh and the Dockerfiles (`java -jar app.jar`). gRPC's ServiceLoader files are merged; other
* duplicated metadata (netty's versions.properties, protobuf .proto copies, ...) only needs one copy.
*/
object k8s extends Module {
trait ServiceApp extends JavaModule {
override def moduleDeps = Seq(core.jvm.test)
override def sources = Task.Sources()
override def resources = Task.Sources()
override def assemblyRules = super.assemblyRules ++ Seq(
Assembly.Rule.AppendPattern("META-INF/services/.*"),
Assembly.Rule.ExcludePattern(".*module-info\\.class"),
)
}
object orderService extends ServiceApp {
override def mainClass = Some("dapr4s.test.integration.apps.orderServiceMain")
}
object inventoryService extends ServiceApp {
override def mainClass = Some("dapr4s.test.integration.apps.inventoryServiceMain")
}
}
// -------------------------------------------------------------------------------------------------
// Integration suites (Docker). Never published.
//
// They are their own modules for two reasons: the JS suites must be linked with a different linker
// configuration (Wasm + JSPI) than the plain-JS unit tests, and keeping them out of core means
// `core.<p>.test` ARE the unit-test legs. Suites run strictly one after another in ONE runtime: the
// server-delivery suites share one sidecar + one in-process app server (fixed ports) for the whole
// run (wiki: dapr4s server IT consolidation).
// -------------------------------------------------------------------------------------------------
object integration extends Module {
object jvm extends Dapr4sFlags with TestModule.Munit {
override def moduleDeps = Seq(core.jvm.test)
override def sources =
Task.Sources(Dapr4sPaths.test / "shared" / "integration", Dapr4sPaths.test / "jvm" / "integration")
override def resources = Task.Sources()
override def testParallelism = false
override def mvnDeps = Seq(
mvn"org.scalameta::munit:${Versions.munit}",
// testcontainers-scala 0.43.6 pulls TC 1.21.1; testcontainers-dapr 1.17.2 pulls TC 1.21.4.
// Both resolve to 1.21.4 with no conflict. Upgrade to testcontainers-scala 0.44+ only after
// testcontainers-dapr ships a TC 2.x-compatible release (fix merged to dapr/java-sdk master,
// awaiting release as v1.18.0).
mvn"com.dimafeng::testcontainers-scala-munit:${Versions.testcontainersScala}",
mvn"io.dapr:testcontainers-dapr:${Versions.daprJava}",
)
}
object js extends Dapr4sFlags with Dapr4sJs with TestScalaJSModule with TestModule.Munit {
override def moduleDeps = Seq(core.js.test)
override def sources =
Task.Sources(Dapr4sPaths.test / "shared" / "integration", Dapr4sPaths.test / "js" / "integration")
override def resources = Task.Sources()
override def mvnDeps = Seq(mvn"org.scalameta::munit::${Versions.munit}")
// The suites block on the Dapr JS SDK through orphan js.await (JsAwait), which only exists on the
// WebAssembly backend with JSPI. That needs ES modules, ES2022 and Wasm, plus the explicit JSPI
// switch (Scala.js >= 1.22).
override def moduleKind = ModuleKind.ESModule
override def esFeatures = Task(super.esFeatures().withESVersion(ESVersion.ES2022))
override def scalaJSUseWebAssembly = true
override def scalaJSUseWebAssemblyJSPI = true
// Node >= 25 first on the PATH: JSPI and Wasm 3.0 are on by default there. The resolve hook
// appends ".js" to the deep, extensionless CommonJS submodule paths ScalablyTyped emits for the
// testcontainers facades, which Node's ESM resolver rejects (scripts/js-it/node-resolve-hook.mjs).
// DAPR4S_REPO_ROOT tells the suites where the canonical component files (scripts/it/) are.
override def jsEnvConfig = Task {
JsEnvConfig.NodeJs(
args = List("--import", (Dapr4sPaths.root / "scripts" / "js-it" / "node-resolve-hook.mjs").toString),
env = Map("DAPR4S_REPO_ROOT" -> Dapr4sPaths.root.toString),
)
}
}
}
// -------------------------------------------------------------------------------------------------
// ScalablyTyped facades for @dapr/dapr, express and node (main) plus testcontainers and
// @dapr/testcontainer-node (JS integration suites only), generated from the npm packages pinned in
// package.json / package-lock.json into the dapr4s-specific `dapr4styped.*` package.
//
// WHY a separate module: the generated code is plain Scala.js facade code. It cannot be compiled with
// dapr4s's flags (capture checking, explicit nulls, fatal warnings would all reject it), and it is
// compiled with the Scala LTS the converter targets.
//
// WHY `dapr4styped` and not ScalablyTyped's default `typings`: the facades are EMBEDDED into the
// published jar, and a consumer running their own ScalablyTyped generation (which always emits
// `typings.*`, including its own `typings.std`/`typings.node`) would collide with them at link time.
// -------------------------------------------------------------------------------------------------
/** The facades come from mill-scalablytyped (com.github.lolgab), with the settings sbt's converter plugin had:
* `scalablyTypedStdLibs` = sbt's `stStdlib` and `scalablyTypedOutputPackage` = `stOutputPackage`. The conversion roots
* are the `dependencies` of package.json (the single source of truth), `npm ci` installs package-lock.json first
* (`scalablyTypedNpmCi`, re-run whenever the lock file changes), and the SAME node_modules serves the JS integration
* test runtime. ~10 min cold; the converter's parse cache is ~/.cache/scalablytyped (CI caches it with out/stFacades).
*/
object stFacades extends Dapr4sJs with ScalablyTyped with Dapr4sPublish {
def scalaVersion = Versions.scala3Facades
def artifactName = "dapr4s-st-facades"
override def sources = Task.Sources()
override def resources = Task.Sources()
override def mvnDeps = Task(
super.mvnDeps() ++ Seq(
mvn"com.olvind::scalablytyped-runtime::${Versions.scalablytypedRuntime}",
mvn"org.scala-js::scalajs-dom::${Versions.scalajsDom}",
),
)
override def scalablyTypedOutputPackage = "dapr4styped"
override def scalablyTypedStdLibs = Seq("es2022")
override def scalablyTypedNpmCi = true
// Facade sources are generated, not documented (never published on their own anyway).
override def docSources = Task(Seq.empty[PathRef])
// The ScalablyTyped library packages (`dapr4styped.<pkg>`) of the main roots' transitive closure:
// these are embedded into dapr4s_sjs1_3. The ones only the testcontainers roots need stay out.
// Every generated package must be in exactly one list; a converter or npm change that adds a package
// fails the build until it is classified (an unclassified MAIN package would otherwise be silently
// missing from the published jar and break consumers at link time).
val mainFacadePackages = Set(
"daprDapr",
"express",
"expressServeStaticCore",
"googleProtobuf",
"grpcGrpcJs",
"grpcProtoLoader",
"httpErrors",
"httpTerminator",
"jsSdslOrderedMap",
"jsTemporalPolyfill",
"long",
"nodeFetch",
"node",
"protobufjs",
"qs",
"rangeParser",
"roarr",
"send",
"serveStatic",
"std",
"typeFest",
"undiciTypes",
)
val testOnlyFacadePackages = Set(
"daprTestcontainerNode",
"dockerCompose",
"dockerModem",
"dockerode",
"ssh2",
"testcontainers",
"undici",
)
/** The facade .sjsir that dapr4s_sjs1_3 embeds (a directory laid out as in the jar).
*
* ONLY .sjsir, deliberately not .class/.tasty: consumers only ever LINK against the facades (they are internal to
* dapr4s and never surface in the public API), and embedded .tasty would make scaladoc document the full
* node/express/@dapr typings (a 1.1 GB -javadoc.jar, over Central's upload limit: the 0.20.0 publish failure).
*/
def embeddedFacades: T[PathRef] = Task {
val root = compile().classes.path / "dapr4styped"
val entries = os.list(root)
val pkgs = entries.filter(os.isDir).map(_.last).toSet
val unknown = pkgs -- mainFacadePackages -- testOnlyFacadePackages
if (unknown.nonEmpty)
Task.fail(
s"Unclassified ScalablyTyped packages ${unknown.mkString(", ")}: add each to mainFacadePackages or " +
"testOnlyFacadePackages in build.mill.",
)
val missing = mainFacadePackages -- pkgs
if (missing.nonEmpty) Task.fail(s"Expected ScalablyTyped packages not generated: ${missing.mkString(", ")}")
val strays = entries.filterNot(os.isDir)
if (strays.nonEmpty) Task.fail(s"Unexpected top-level dapr4styped entries: ${strays.mkString(", ")}")
val out = Task.dest / "embedded"
for {
pkg <- mainFacadePackages.toSeq
f <- os.walk(root / pkg) if f.ext == "sjsir"
} os.copy(f, out / "dapr4styped" / f.relativeTo(root), createFolders = true)
PathRef(out)
}
}