-
Notifications
You must be signed in to change notification settings - Fork 105
/
build.sbt
349 lines (319 loc) · 12.9 KB
/
build.sbt
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
342
343
344
345
346
347
348
349
import scala.sys.process._
import scala.sys.process.ProcessLogger
import com.typesafe.sbt.SbtNativePackager.Universal
import org.scalajs.linker.interface.ModuleSplitStyle
import SbtShared._
def akka(module: String) = "com.typesafe.akka" %% ("akka-" + module) % "2.6.19"
val akkaHttpVersion = "10.2.9"
addCommandAlias("startAll", "sbtRunner/reStart;server/reStart;metalsRunner/reStart;client/fastLinkJS")
addCommandAlias(
"startAllProd",
"sbtRunner/reStart;metalsRunner/reStart;server/buildTreesitterWasm;server/fullLinkJS/reStart"
)
val yarnBuild = taskKey[Unit]("builds es modules with `yarn build`")
ThisBuild / packageTimestamp := None
lazy val scastie = project
.in(file("."))
.aggregate(
(api.projectRefs ++ runtimeScala.projectRefs ++ List(
balancer,
client,
instrumentation,
sbtRunner,
sbtScastie,
server,
storage,
utils,
metalsRunner
).map(_.project)): _*
)
.settings(baseSettings)
.settings(
cachedCiTestFull := {
val _ = cachedCiTestFull.value
val __ = (sbtRunner / docker / dockerfile).value
val ___ = (server / Universal / packageBin).value
}
)
.settings(Deployment.settings(server, sbtRunner, metalsRunner))
lazy val testSettings = Seq(
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.17" % Test
)
lazy val loggingAndTest = Seq(
libraryDependencies ++= Seq(
"ch.qos.logback" % "logback-classic" % "1.4.14",
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.5",
"io.sentry" % "sentry-logback" % "6.34.0"
)
) ++ testSettings
lazy val utils = project
.in(file("utils"))
.settings(baseNoCrossSettings)
.settings(loggingAndTest)
.settings(
resolvers += Resolver.typesafeRepo("releases"),
libraryDependencies ++= Seq(
akka("protobuf"),
akka("stream"),
akka("actor"),
akka("remote"),
akka("slf4j"),
akka("testkit") % Test
)
)
.dependsOn(api.jvm(ScalaVersions.jvm))
lazy val runnerRuntimeDependencies = (api.projectRefs ++ runtimeScala.projectRefs ++ Seq(
sbtScastie.project
)).map(_ / publishLocal)
lazy val runnerRuntimeDependenciesInTest = Seq(
assembly / test := {},
Test / test := (Test / test).dependsOn(runnerRuntimeDependencies: _*).value,
Test / testOnly := (Test / testOnly).dependsOn(runnerRuntimeDependencies: _*).evaluated,
Test / testQuick := (Test / testQuick).dependsOn(runnerRuntimeDependencies: _*).evaluated
)
lazy val smallRunnerRuntimeDependenciesInTest = {
lazy val smallRunnerRuntimeDependencies = Seq(
api.jvm(ScalaVersions.jvm),
api.jvm(ScalaVersions.sbt),
runtimeScala.jvm(ScalaVersions.jvm),
runtimeScala.jvm(ScalaVersions.sbt),
sbtScastie
).map(_ / publishLocal)
Seq(
assembly / test := {},
Test / test := (Test / test).dependsOn(smallRunnerRuntimeDependencies: _*).value,
Test / testOnly := (Test / testOnly).dependsOn(smallRunnerRuntimeDependencies: _*).evaluated,
Test / testQuick := (Test / testQuick).dependsOn(smallRunnerRuntimeDependencies: _*).evaluated
)
}
lazy val dockerOrg = "scalacenter"
lazy val metalsRunner = project
.in(file("metals-runner"))
.settings(baseNoCrossSettings)
.settings(
fork := true, // we need to fork it, as it is dynamically loading classes, and they persist in the sbt shell instance
docker / imageNames := Seq(
ImageName(namespace = Some(dockerOrg), repository = "scastie-metals-runner", tag = Some(gitHashNow)),
ImageName(namespace = Some(dockerOrg), repository = "scastie-metals-runner", tag = Some("latest"))
),
executableScriptName := "server",
javacOptions ++= Seq("-Xms1G", "-Xmx12G", "-XX:+CrashOnOutOfMemoryError"),
docker / dockerfile := Def
.task {
DockerHelper.javaProject(
baseDirectory = (ThisBuild / baseDirectory).value.toPath,
organization = organization.value,
artifactZip = (Universal / packageBin).value.toPath,
configPath = (baseDirectory.value / "src" / "main" / "resources" / "application.conf").toPath
)
}
.dependsOn(runnerRuntimeDependencies: _*)
.value,
maintainer := "scalacenter",
scalaVersion := ScalaVersions.stableLTS,
libraryDependencies ++= Seq(
"org.scalameta" % "metals" % "1.3.5" cross (CrossVersion.for3Use2_13),
"org.eclipse.lsp4j" % "org.eclipse.lsp4j" % "0.21.1",
"org.http4s" %% "http4s-ember-server" % "0.23.24",
"org.http4s" %% "http4s-ember-client" % "0.23.24",
"org.http4s" %% "http4s-dsl" % "0.23.24",
"org.http4s" %% "http4s-circe" % "0.23.24",
"io.circe" %% "circe-generic" % "0.14.6",
"com.evolutiongaming" %% "scache" % "4.2.3",
"org.scalameta" %% "munit" % "0.7.29" % Test,
"org.typelevel" %% "munit-cats-effect-3" % "1.0.7" % Test
)
)
.enablePlugins(JavaServerAppPackaging, sbtdocker.DockerPlugin)
.dependsOn(api.jvm(ScalaVersions.old3))
lazy val sbtRunner = project
.in(file("sbt-runner"))
.settings(baseNoCrossSettings)
.settings(loggingAndTest)
.settings(runnerRuntimeDependenciesInTest)
.settings(
reStart / javaOptions += "-Xmx256m",
Test / parallelExecution := false,
reStart := reStart.dependsOn(runnerRuntimeDependencies: _*).evaluated,
resolvers ++= Resolver.sonatypeOssRepos("public"),
libraryDependencies ++= Seq(
akka("actor"),
akka("testkit") % Test,
akka("cluster"),
akka("slf4j"),
"org.scalameta" %% "scalafmt-core" % "3.7.17"
),
docker / imageNames := Seq(
ImageName(namespace = Some(dockerOrg), repository = "scastie-sbt-runner", tag = Some(gitHashNow)),
ImageName(namespace = Some(dockerOrg), repository = "scastie-sbt-runner", tag = Some("latest"))
),
docker / buildOptions := (docker / buildOptions).value
.copy(additionalArguments = List("--add-host", "jenkins.scala-sbt.org:127.0.0.1")),
docker / dockerfile := Def
.task {
DockerHelper(
baseDirectory = (ThisBuild / baseDirectory).value.toPath,
sbtTargetDir = target.value.toPath,
ivyHome = ivyPaths.value.ivyHome.get.toPath,
organization = organization.value,
artifact = assembly.value.toPath,
sbtScastie = (sbtScastie / moduleName).value,
sbtVersion = sbtVersion.value
)
}
.dependsOn(runnerRuntimeDependencies: _*)
.value,
assembly / assemblyMergeStrategy := {
case PathList("META-INF", xs @ _*) => MergeStrategy.discard
case in @ PathList("reference.conf", xs @ _*) => {
val old = (assembly / assemblyMergeStrategy).value
old(in)
}
case x => MergeStrategy.first
}
)
.dependsOn(api.jvm(ScalaVersions.jvm), instrumentation, utils)
.enablePlugins(sbtdocker.DockerPlugin, BuildInfoPlugin)
lazy val buildTreesitterWasm = taskKey[Seq[File]]("Builds tree-sitter-scala.wasm")
lazy val server = project
.settings(baseNoCrossSettings)
.settings(loggingAndTest)
.settings(
watchSources ++= (client / watchSources).value,
Compile / products += (client / baseDirectory).value / "dist",
fullLinkJS / reStart := reStart.dependsOn(client / Compile / fullLinkJS / yarnBuild).evaluated,
Universal / packageBin := (Universal / packageBin)
.dependsOn(buildTreesitterWasm)
.dependsOn(client / Compile / fullLinkJS / yarnBuild)
.value,
reStart / javaOptions += "-Xmx512m",
maintainer := "scalacenter",
buildTreesitterWasm := {
val treeSitterOutputName = "tree-sitter.wasm"
val treeSitterWasm = baseDirectory.value.getParentFile / "node_modules" / "web-tree-sitter" / treeSitterOutputName
val treeSitterScalaOutputName = "tree-sitter-scala.wasm"
val treeSitterScalaWasm = baseDirectory.value.getParentFile / "tree-sitter-scala" / treeSitterScalaOutputName
val treeSitterScalaHiglightName = "highlights.scm"
val treeSitterScalaHiglight =
baseDirectory.value.getParentFile / "tree-sitter-scala" / "queries" / "scala" / treeSitterScalaHiglightName
val outputWasmDirectory = (Compile / resourceDirectory).value / "public"
val s: TaskStreams = streams.value
val shell: Seq[String] = if (sys.props("os.name").contains("Windows")) Seq("cmd", "/c") else Seq("bash", "-c")
val updateGitSubmodule: Seq[String] = shell :+ "git submodule update --init"
val buildWasm: Seq[String] =
shell :+ """cd tree-sitter-scala && nix-shell -p emscripten --run 'nix-shell --run "tree-sitter build-wasm"'"""
s.log.info("building tree-sitter-scala wasm...")
if ((updateGitSubmodule #&& buildWasm !) == 0) {
s.log.success(s"$treeSitterOutputName build successfuly!")
} else {
throw new IllegalStateException(s"Failed to generate $treeSitterOutputName!")
}
sbt.IO.copyFile(treeSitterScalaHiglight, outputWasmDirectory / treeSitterScalaHiglightName)
sbt.IO.move(treeSitterScalaWasm, outputWasmDirectory / treeSitterScalaOutputName)
sbt.IO.copyFile(treeSitterWasm, outputWasmDirectory / treeSitterOutputName)
s.log.success(
s"Copied $treeSitterScalaHiglight to ${(outputWasmDirectory / treeSitterScalaHiglightName).getAbsolutePath}"
)
s.log.success(
s"Copied $treeSitterScalaWasm to ${(outputWasmDirectory / treeSitterScalaOutputName).getAbsolutePath}"
)
s.log.success(s"Copied $treeSitterWasm to ${(outputWasmDirectory / treeSitterOutputName).getAbsolutePath}")
Seq(outputWasmDirectory / treeSitterScalaOutputName, outputWasmDirectory / treeSitterOutputName)
},
libraryDependencies ++= Seq(
"org.apache.commons" % "commons-text" % "1.11.0",
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
"com.softwaremill.akka-http-session" %% "core" % "0.7.1",
"ch.megard" %% "akka-http-cors" % "1.2.0",
akka("cluster"),
akka("slf4j"),
akka("testkit") % Test,
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion % Test
)
)
.enablePlugins(JavaServerAppPackaging)
.dependsOn(api.jvm(ScalaVersions.jvm), utils, balancer)
lazy val balancer = project
.settings(baseNoCrossSettings)
.settings(loggingAndTest)
.settings(smallRunnerRuntimeDependenciesInTest)
.settings(
libraryDependencies += akka("testkit") % Test
)
.dependsOn(api.jvm(ScalaVersions.jvm), utils, storage, sbtRunner % Test)
lazy val storage = project
.settings(baseNoCrossSettings)
.settings(loggingAndTest)
.settings(
scalacOptions += "-Ywarn-unused",
libraryDependencies ++= Seq(
"org.mongodb.scala" %% "mongo-scala-driver" % "4.11.1",
"net.lingala.zip4j" % "zip4j" % "2.11.5"
)
)
.dependsOn(api.jvm(ScalaVersions.jvm), utils, instrumentation)
lazy val yarnBin =
if (scala.util.Properties.isWin) "yarn.cmd"
else "yarn"
lazy val client = project
.enablePlugins(ScalablyTypedConverterExternalNpmPlugin)
.settings(baseNoCrossSettings)
.settings(baseJsSettings)
.settings(
externalNpm := {
Process(yarnBin, baseDirectory.value.getParentFile) ! ProcessLogger(line => ())
baseDirectory.value.getParentFile
},
stFlavour := Flavour.ScalajsReact,
Compile / fastLinkJS / scalaJSLinkerConfig := {
val dir = (Compile / fastLinkJS / scalaJSLinkerOutputDirectory).value.toURI()
scalaJSLinkerConfig.value
.withModuleKind(ModuleKind.ESModule)
.withRelativizeSourceMapBase(Some(dir))
},
Compile / fullLinkJS / scalaJSLinkerConfig := {
scalaJSLinkerConfig.value.withModuleKind(ModuleKind.ESModule)
},
yarnBuild := {
Process(s"$yarnBin build").!
},
test := {},
Test / loadedTestFrameworks := Map(),
stIgnore := List(
"@sentry/browser",
"@sentry/tracing",
"github-markdown-css",
"react",
"react-dom",
"source-map-support",
"vite"
),
libraryDependencies ++= Seq(
"com.github.japgolly.scalajs-react" %%% "core" % "2.1.1",
"com.github.japgolly.scalajs-react" %%% "extra" % "2.1.1",
"org.scala-js" %%% "scala-js-macrotask-executor" % "1.1.1"
)
)
.enablePlugins(ScalaJSPlugin)
.dependsOn(api.js(ScalaVersions.js))
lazy val instrumentation = project
.settings(baseNoCrossSettings)
.settings(loggingAndTest)
.settings(
libraryDependencies ++= Seq(
"org.scalameta" %% "scalameta" % "4.8.14",
"com.googlecode.java-diff-utils" % "diffutils" % "1.3.0" % Test
)
)
.dependsOn(api.jvm(ScalaVersions.jvm), utils)
lazy val api = SbtShared.api
lazy val runtimeScala = SbtShared.`runtime-scala`
lazy val sbtScastie = project
.in(file("sbt-scastie"))
.settings(orgSettings)
.settings(
moduleName := "sbt-scastie",
sbtPlugin := true
)
.settings(version := versionRuntime)
.dependsOn(api.jvm(ScalaVersions.sbt))