-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathbuild.sbt
More file actions
256 lines (230 loc) · 10.2 KB
/
build.sbt
File metadata and controls
256 lines (230 loc) · 10.2 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
import org.scalajs.linker.interface.{ModuleKind, OutputPatterns}
import sbtcrossproject.CrossPlugin.autoImport.{CrossType, crossProject}
import scala.util.chaining.scalaUtilChainingOps
val V = new {
val distage = "1.2.25"
val logstage = distage
val scalatest = "3.2.20"
val scalacheck = "1.19.0"
val http4s = "0.23.34"
val doobie = "1.0.0-RC12"
val catsCore = "2.13.0"
val zio = "2.1.25"
val zioCats = "23.1.0.13"
val kindProjector = "0.13.4"
val circeGeneric = "0.14.15"
val graalMetadata = "0.11.5"
val catsEffect = "3.5.4"
}
val Deps = new {
val scalatest = "org.scalatest" %% "scalatest" % V.scalatest
val scalacheck = "org.scalacheck" %% "scalacheck" % V.scalacheck
val distageCore = "io.7mind.izumi" %% "distage-core" % V.distage
val distageConfig = "io.7mind.izumi" %% "distage-extension-config" % V.distage
val distageRoles = "io.7mind.izumi" %% "distage-framework" % V.distage
val distageDocker = "io.7mind.izumi" %% "distage-framework-docker" % V.distage
val distageTestkit = "io.7mind.izumi" %% "distage-testkit-scalatest" % V.distage
val logstageSlf4j = "io.7mind.izumi" %% "logstage-adapter-slf4j" % V.logstage
val http4sDsl = "org.http4s" %% "http4s-dsl" % V.http4s
val http4sServer = "org.http4s" %% "http4s-ember-server" % V.http4s
val http4sClient = "org.http4s" %% "http4s-ember-client" % V.http4s
val http4sCirce = "org.http4s" %% "http4s-circe" % V.http4s
val circeGeneric = "io.circe" %% "circe-generic" % V.circeGeneric
val doobie = "org.tpolecat" %% "doobie-core" % V.doobie
val doobiePostgres = "org.tpolecat" %% "doobie-postgres" % V.doobie
val doobieHikari = "org.tpolecat" %% "doobie-hikari" % V.doobie
val kindProjector = "org.typelevel" % "kind-projector" % V.kindProjector cross CrossVersion.full
val zio = "dev.zio" %% "zio" % V.zio
val zioCats = "dev.zio" %% "zio-interop-cats" % V.zioCats
val catsCore = "org.typelevel" %% "cats-core" % V.catsCore
val graalMetadata = "org.graalvm.buildtools" % "graalvm-reachability-metadata" % V.graalMetadata
// Standard set of deps for JVM-only sub-projects (monomorphic-cats,
// monofunctor-tagless, and the JVM half of bifunctor-tagless).
val CoreDeps = Seq(
distageCore,
distageRoles,
distageConfig,
logstageSlf4j,
distageDocker,
distageTestkit % Test,
scalatest % Test,
scalacheck % Test,
http4sDsl,
http4sServer,
http4sClient % Test,
http4sCirce,
circeGeneric,
doobie,
doobiePostgres,
doobieHikari,
catsCore,
graalMetadata,
)
}
inThisBuild(
Seq(
crossScalaVersions := Seq("2.13.18", "3.3.7"),
// crossScalaVersions := Seq("3.3.7", "2.13.18"), // uncomment to use Scala 3 in IDE
scalaVersion := crossScalaVersions.value.head,
version := "1.0.0",
organization := "io.7mind",
)
)
// -----------------------------------------------------------------------------
// bifunctor-tagless: a cross-built project (JVM + Scala.js)
//
// The shared half holds everything that compiles to both targets: the model,
// the API classes (which return http4s `HttpRoutes`), the repository traits
// and their in-memory dummy implementations, and the `LocalDispatcher` that
// invokes the assembled routes in-process. The JVM half adds the postgres
// repositories, the http4s ember server with CORS + static-file serving, and
// the role/launcher infrastructure. The JS half adds a `@JSExportTopLevel`
// entrypoint that boots the same distage graph with `Repo -> Dummy` and
// surfaces the dispatcher to the browser as `window.LeaderboardSim`.
// -----------------------------------------------------------------------------
lazy val `bifunctor-tagless` = crossProject(JVMPlatform, JSPlatform)
.crossType(CrossType.Full)
.in(file("bifunctor-tagless"))
.settings(
sharedScalaSettings,
libraryDependencies ++= Seq(
"io.7mind.izumi" %%% "distage-core" % V.distage,
"io.7mind.izumi" %%% "distage-extension-plugins" % V.distage,
"io.7mind.izumi" %%% "distage-extension-logstage" % V.distage,
"io.7mind.izumi" %%% "logstage-core" % V.logstage,
"org.http4s" %%% "http4s-dsl" % V.http4s,
"org.http4s" %%% "http4s-circe" % V.http4s,
"io.circe" %%% "circe-generic" % V.circeGeneric,
"org.typelevel" %%% "cats-core" % V.catsCore,
"dev.zio" %%% "zio" % V.zio,
// `zio-managed` is required transitively by `zio-interop-cats`'s
// ZManaged bridge classes; under scala.js the linker validates all
// referenced classes, so we must pull the artifact in explicitly.
"dev.zio" %%% "zio-managed" % V.zio,
"dev.zio" %%% "zio-interop-cats" % V.zioCats,
),
)
.jvmConfigure(_.pipe(jvmSharedSettings(Seq(Deps.zio, Deps.zioCats))))
.jsSettings(
scalaJSUseMainModuleInitializer := false,
// NoModule output: the linker emits a plain script that publishes
// `@JSExportTopLevel` bindings on the global scope. We deliberately do
// NOT use ESModule here because browsers refuse to load ES modules from
// `file://` (the simulation page is meant to be usable both via the
// http4s server and by opening index.html directly from disk).
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.NoModule) },
)
// sbt-scalajs-crossproject derives the per-platform project IDs from the
// cross-project's name: `bifunctor-taglessJVM` and `bifunctor-taglessJS`.
// These aliases give us Project handles to reference in tasks below.
lazy val `bifunctor-taglessJVM` = `bifunctor-tagless`.jvm
lazy val `bifunctor-taglessJS` = `bifunctor-tagless`.js
// Task: link the Scala.js bundle in `bifunctor-tagless-js` and copy the
// resulting main.js into the JVM project's resources/webapp/ so the http4s
// server (and a browser opening index.html directly) can find it.
lazy val copySimJs = taskKey[Seq[File]]("Link the simulation JS and copy it into the JVM resources/webapp/ directory.")
copySimJs := {
val _ = (`bifunctor-taglessJS` / Compile / fullLinkJS).value
val srcDir = (`bifunctor-taglessJS` / Compile / fullLinkJS / scalaJSLinkerOutputDirectory).value
val outDir = (`bifunctor-taglessJVM` / baseDirectory).value / "src" / "main" / "resources" / "webapp"
IO.createDirectory(outDir)
val srcs = (srcDir ** "*.js").get ++ (srcDir ** "*.js.map").get
srcs.map { f =>
val dst = outDir / f.getName
IO.copyFile(f, dst, preserveLastModified = true)
dst
}
}
lazy val `monofunctor-tagless` = project
.in(file("monofunctor-tagless"))
.pipe(sharedSettings(Seq(Deps.zio, Deps.zioCats)))
lazy val `monomorphic-cats` = project
.in(file("monomorphic-cats"))
.pipe(sharedSettings(Seq()))
lazy val `graal-resources` = project
.in(file("graal-resources"))
.settings(Compile / resourceDirectory := baseDirectory.value)
lazy val `distage-example` = project
.in(file("."))
.aggregate(
`bifunctor-taglessJVM`,
`bifunctor-taglessJS`,
`monofunctor-tagless`,
`monomorphic-cats`,
`graal-resources`,
)
.enablePlugins(GraalVMNativeImagePlugin, UniversalPlugin)
// Scalac/source settings shared by every Scala project in this build, both
// JVM-only ones and the cross-built bifunctor-tagless halves.
def sharedScalaSettings: Seq[Setting[_]] = Seq(
libraryDependencies ++= {
if (scalaVersion.value.startsWith("2")) {
Seq(compilerPlugin(Deps.kindProjector))
} else {
Seq.empty
}
},
scalacOptions --= Seq("-Xfatal-warnings", "-Ykind-projector", "-Wnonunit-statement"),
scalacOptions ++= {
if (scalaVersion.value.startsWith("2")) {
Seq(
"-Xsource:3",
"-P:kind-projector:underscore-placeholders",
"-Wmacros:after",
)
} else {
Seq(
"-Ykind-projector:underscores",
"-Yretain-trees",
)
}
},
scalacOptions ++= Seq(
s"-Xmacro-settings:product-name=${name.value}",
s"-Xmacro-settings:product-version=${version.value}",
s"-Xmacro-settings:product-group=${organization.value}",
s"-Xmacro-settings:scala-version=${scalaVersion.value}",
s"-Xmacro-settings:scala-versions=${crossScalaVersions.value.mkString(":")}",
s"-Xmacro-settings:sbt-version=${sbtVersion.value}",
s"-Xmacro-settings:git-repo-clean=${git.gitUncommittedChanges.value}",
s"-Xmacro-settings:git-branch=${git.gitCurrentBranch.value}",
s"-Xmacro-settings:git-described-version=${git.gitDescribedVersion.value.getOrElse("")}",
s"-Xmacro-settings:git-head-commit=${git.gitHeadCommit.value.getOrElse("")}",
),
)
// JVM-only project settings (the http4s ember server, doobie, GraalVM native
// image, etc). Applied to the JVM half of `bifunctor-tagless` and — via
// `sharedSettings` below — to the plain JVM-only projects.
//
// Intentionally does NOT include `sharedScalaSettings`: the cross-built
// bifunctor-tagless applies those once on the cross project so they reach
// both halves, and applying them a second time here would set scalacOptions
// like `-Yretain-trees` twice and trip sbt-tpolecat's "set repeatedly"
// guard.
def jvmSharedSettings(additionalDeps: Seq[ModuleID])(project: Project): Project = {
project
.settings(
libraryDependencies ++= Deps.CoreDeps ++ additionalDeps,
GraalVMNativeImage / mainClass := Some("leaderboard.GenericLauncher"),
graalVMNativeImageOptions ++= Seq(
"--no-fallback",
"-H:+ReportExceptionStackTraces",
"--report-unsupported-elements-at-runtime",
"--enable-https",
"--enable-http",
"-J-Xmx8G",
),
graalVMNativeImageGraalVersion := Some("ol9-java17-22.3.1"),
run / fork := true,
)
.dependsOn(`graal-resources`)
.enablePlugins(GraalVMNativeImagePlugin, UniversalPlugin)
}
// Plain (non-cross) Scala project — used by `monomorphic-cats` and
// `monofunctor-tagless`, which stay JVM-only. These need both
// `sharedScalaSettings` (scalac flags + macro settings) and the JVM-only
// extras above.
def sharedSettings(additionalDeps: Seq[ModuleID])(project: Project): Project =
jvmSharedSettings(additionalDeps)(project).settings(sharedScalaSettings)
// for quick experiments with distage snapshots
ThisBuild / resolvers += Resolver.sonatypeCentralSnapshots