forked from http4s/http4s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
627 lines (582 loc) · 17.8 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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
import com.typesafe.tools.mima.core._
import explicitdeps.ExplicitDepsPlugin.autoImport.moduleFilterRemoveValue
import org.http4s.sbt.Http4sPlugin._
// Global settings
ThisBuild / crossScalaVersions := Seq(scala_3, scala_213)
ThisBuild / tlBaseVersion := "1.0"
ThisBuild / developers += tlGitHubDev("rossabaker", "Ross A. Baker")
ThisBuild / tlCiReleaseBranches := Seq("main")
ThisBuild / tlSitePublishBranch := Some("main")
ThisBuild / semanticdbOptions ++= Seq("-P:semanticdb:synthetics:on").filter(_ => !tlIsScala3.value)
ThisBuild / scalafixAll / skip := tlIsScala3.value
ThisBuild / ScalafixConfig / skip := tlIsScala3.value
ThisBuild / Test / scalafixConfig := Some(file(".scalafix.test.conf"))
ThisBuild / githubWorkflowJobSetup ~= {
_.filterNot(_.name.exists(_.matches("(Download|Setup) Java .+")))
}
ThisBuild / githubWorkflowJobSetup ++= Seq(
WorkflowStep.Use(
UseRef.Public("cachix", "install-nix-action", "v17"),
name = Some("Install Nix"),
),
WorkflowStep.Use(
UseRef.Public("cachix", "cachix-action", "v10"),
name = Some("Install Cachix"),
params = Map("name" -> "http4s", "authToken" -> "${{ secrets.CACHIX_AUTH_TOKEN }}"),
),
)
ThisBuild / githubWorkflowSbtCommand := "nix develop .#${{ matrix.java }} -c sbt"
ThisBuild / githubWorkflowAddedJobs ++= Seq(
WorkflowJob(
id = "coverage",
name = "Generate coverage report",
scalas = List(scala_213),
javas = List(JavaSpec.temurin("8")),
steps = githubWorkflowJobSetup.value.toList ++
List(
WorkflowStep.Sbt(List("coverage", "rootJVM/test", "coverageAggregate")),
WorkflowStep.Use(
UseRef.Public(
"codecov",
"codecov-action",
"v2",
),
cond = Some("github.event_name != 'pull_request'"),
),
),
)
)
ThisBuild / jsEnv := {
import org.scalajs.jsenv.nodejs.NodeJSEnv
new NodeJSEnv(NodeJSEnv.Config().withEnv(Map("TZ" -> "UTC")))
}
lazy val modules: List[CompositeProject] = List(
core,
laws,
tests,
server,
client,
clientTestkit,
emberCore,
emberServer,
emberClient,
theDsl,
jawn,
circe,
bench,
jsArtifactSizeTest,
unidocs,
examples,
examplesDocker,
examplesEmber,
scalafixInternalRules,
scalafixInternalInput,
scalafixInternalOutput,
scalafixInternalTests,
)
lazy val root = tlCrossRootProject
.disablePlugins(ScalafixPlugin)
.settings(
// Root project
name := "http4s",
description := "A minimal, Scala-idiomatic library for HTTP",
startYear := Some(2013),
)
.aggregate(modules: _*)
lazy val core = libraryCrossProject("core")
.enablePlugins(BuildInfoPlugin)
.jvmEnablePlugins(MimeLoaderPlugin)
.settings(
description := "Core http4s library for servers and clients",
startYear := Some(2013),
buildInfoKeys := Seq[BuildInfoKey](
version,
scalaVersion,
BuildInfoKey.map(http4sApiVersion) { case (_, v) => "apiVersion" -> v },
),
buildInfoPackage := organization.value,
libraryDependencies ++= Seq(
caseInsensitive.value,
catsCore.value,
catsEffectStd.value,
catsParse.value.exclude("org.typelevel", "cats-core_2.13"),
fs2Core.value,
fs2Io.value,
ip4sCore.value,
literally.value,
munit.value % Test,
scodecBits.value,
vault.value,
),
libraryDependencies ++= {
if (tlIsScala3.value) Seq.empty
else
Seq(
slf4jApi, // residual dependency from macros
scalaReflect(scalaVersion.value) % Provided,
)
},
unusedCompileDependenciesFilter -= moduleFilter("org.scala-lang", "scala-reflect"),
)
.platformsSettings(JVMPlatform, JSPlatform)(
libraryDependencies ++= Seq(
log4s.value
)
)
.platformsSettings(JSPlatform, NativePlatform)(
libraryDependencies ++= Seq(
log4catsNoop.value,
scalaJavaLocalesEnUS.value,
scalaJavaTime.value,
)
)
.jvmSettings(
libraryDependencies ++= {
Seq(log4catsSlf4j)
},
libraryDependencies ++= {
if (tlIsScala3.value) Seq.empty
else
Seq(
slf4jApi // residual dependency from macros
)
},
)
lazy val laws = libraryCrossProject("laws", CrossType.Pure)
.settings(
description := "Instances and laws for testing http4s code",
startYear := Some(2019),
libraryDependencies ++= Seq(
caseInsensitiveTesting.value,
catsEffect.value,
catsEffectTestkit.value,
catsLaws.value,
disciplineCore.value,
ip4sTestKit.value,
scalacheck.value,
scalacheckEffectMunit.value,
munitCatsEffect.value,
),
unusedCompileDependenciesFilter -= moduleFilter(
organization = "org.typelevel",
name = "scalacheck-effect-munit",
),
)
.dependsOn(core)
// Also defines shared test utils in Compile scope
lazy val tests = libraryCrossProject("tests")
.enablePlugins(NoPublishPlugin)
.settings(
description := "Tests for core project",
startYear := Some(2013),
libraryDependencies ++= Seq(
munitCatsEffect.value,
munitDiscipline.value,
scalacheck.value,
scalacheckEffect.value,
scalacheckEffectMunit.value,
),
)
.nativeSettings(
libraryDependencies ++= Seq(
epollcat.value
)
)
.dependsOn(core, laws)
lazy val server = libraryCrossProject("server")
.settings(
description := "Base library for building http4s servers",
startYear := Some(2014),
)
.settings(BuildInfoPlugin.buildInfoScopedSettings(Test))
.settings(BuildInfoPlugin.buildInfoDefaultSettings)
.settings(
buildInfoKeys := Seq[BuildInfoKey](
BuildInfoKey.map(Test / resourceDirectory) { case (k, v) => k -> v.toString }
),
buildInfoPackage := "org.http4s.server.test",
libraryDependencies += crypto.value,
)
.dependsOn(core, tests % Test, theDsl % Test)
lazy val client = libraryCrossProject("client")
.settings(
description := "Base library for building http4s clients",
startYear := Some(2014),
libraryDependencies += crypto.value,
)
.jvmSettings(
libraryDependencies ++= Seq(
nettyBuffer % Test,
nettyCodecHttp % Test,
)
)
.dependsOn(core, server % Test, tests % Test, theDsl % Test)
lazy val clientTestkit = libraryCrossProject("client-testkit")
.settings(
description := "Client testkit for building http4s clients",
startYear := Some(2014),
libraryDependencies ++= Seq(
munit.value,
munitCatsEffect.value,
),
mimaPreviousArtifacts := Set.empty,
)
.jvmSettings(
libraryDependencies ++= Seq(
nettyBuffer,
nettyCodecHttp,
)
)
.dependsOn(client, theDsl)
lazy val emberCore = libraryCrossProject("ember-core", CrossType.Full)
.settings(
description := "Base library for ember http4s clients and servers",
startYear := Some(2019),
unusedCompileDependenciesFilter -= moduleFilter("io.chrisdavenport", "log4cats-core"),
libraryDependencies ++= Seq(
log4catsCore.value,
log4catsTesting.value % Test,
),
)
.jvmSettings(
libraryDependencies += twitterHpack
)
.platformsSettings(JSPlatform, NativePlatform)(
libraryDependencies += hpack.value
)
.dependsOn(core, tests % Test)
lazy val emberServer = libraryCrossProject("ember-server")
.settings(
description := "ember implementation for http4s servers",
startYear := Some(2019),
Test / parallelExecution := false,
)
.jvmSettings(
libraryDependencies ++= Seq(
log4catsSlf4j,
javaWebSocket % Test,
jnrUnixSocket % Test, // Necessary for jdk < 16
)
)
.jsSettings(
libraryDependencies ++= Seq(
log4catsNoop.value
)
)
.dependsOn(
emberCore % "compile;test->test",
server % "compile;test->test",
emberClient % "test->compile",
)
lazy val emberClient = libraryCrossProject("ember-client")
.settings(
description := "ember implementation for http4s clients",
startYear := Some(2019),
libraryDependencies ++= Seq(
keypool.value
),
)
.jvmSettings(
libraryDependencies ++= Seq(
log4catsSlf4j
)
)
.jsSettings(
libraryDependencies ++= Seq(
log4catsNoop.value
)
)
.dependsOn(emberCore % "compile;test->test", client, clientTestkit % Test)
// `dsl` name conflicts with modern SBT
lazy val theDsl = libraryCrossProject("dsl", CrossType.Pure)
.settings(
description := "Simple DSL for writing http4s services",
startYear := Some(2013),
)
.dependsOn(core, tests % Test)
lazy val jawn = libraryCrossProject("jawn", CrossType.Pure)
.settings(
description := "Base library to parse JSON to various ASTs for http4s",
startYear := Some(2014),
libraryDependencies ++= Seq(
jawnFs2.value,
jawnParser.value,
),
)
.dependsOn(core, tests % Test)
lazy val circe = libraryCrossProject("circe", CrossType.Pure)
.settings(
description := "Provides Circe codecs for http4s",
startYear := Some(2015),
libraryDependencies ++= Seq(
circeCore.value,
circeJawn.value,
circeTesting.value % Test,
),
)
.dependsOn(core, tests % Test, jawn % "compile;test->test")
lazy val bench = http4sProject("bench")
.enablePlugins(JmhPlugin)
.enablePlugins(NoPublishPlugin)
.settings(
description := "Benchmarks for http4s",
startYear := Some(2015),
libraryDependencies += circeParser,
undeclaredCompileDependenciesTest := {},
unusedCompileDependenciesTest := {},
coverageEnabled := false,
)
.dependsOn(core.jvm, circe.jvm, emberCore.jvm)
lazy val jsArtifactSizeTest = http4sProject("js-artifact-size-test")
.enablePlugins(ScalaJSPlugin, NoPublishPlugin)
.settings(
// CI automatically links SJS test artifacts in a separate step, to avoid OOMs while running tests
// By placing the app in Test scope it gets linked as part of that CI step
Test / scalaJSUseMainModuleInitializer := true,
Test / scalaJSUseTestModuleInitializer := false,
Test / scalaJSStage := FullOptStage,
Test / test := {
val log = streams.value.log
val file = (Test / fullOptJS).value.data
val size = io.Using.fileInputStream(file) { in =>
var size = 0L
IO.gzip(in, _ => size += 1)
size
}
val sizeKB = size / 1000
// not a hard target. increase *moderately* if need be
// linking MimeDB results in a 100 KB increase. don't let that happen :)
val targetKB = 350
val msg = s"fullOptJS+gzip generated ${sizeKB} KB artifact (target: <$targetKB KB)"
if (sizeKB < targetKB)
log.info(msg)
else
sys.error(msg)
},
)
.dependsOn(client.js, circe.js)
lazy val unidocs = http4sProject("unidocs")
.enablePlugins(TypelevelUnidocPlugin)
.settings(
moduleName := "http4s-docs",
description := "Unified API documentation for http4s",
ScalaUnidoc / unidoc / unidocProjectFilter := inAnyProject --
inProjects( // TODO would be nice if these could be introspected from noPublishSettings
(List[ProjectReference](
bench,
examples,
examplesDocker,
examplesEmber,
scalafixInternalInput,
scalafixInternalOutput,
scalafixInternalRules,
scalafixInternalTests,
docs,
) ++ root.js.aggregate ++ root.native.aggregate): _*
),
coverageEnabled := false,
)
lazy val docs = http4sProject("site")
.enablePlugins(Http4sSitePlugin)
.settings(
libraryDependencies ++= Seq(
circeGeneric,
circeLiteral,
cryptobits,
),
description := "Documentation for http4s",
tlFatalWarningsInCi := false,
fork := false,
)
.dependsOn(
client.jvm,
core.jvm,
theDsl.jvm,
emberServer.jvm,
emberClient.jvm,
circe.jvm,
)
lazy val examples = http4sProject("examples")
.enablePlugins(NoPublishPlugin)
.settings(
description := "Common code for http4s examples",
startYear := Some(2013),
libraryDependencies ++= Seq(
circeGeneric % Runtime,
logbackClassic % Runtime,
),
coverageEnabled := false,
)
.dependsOn(server.jvm, theDsl.jvm, circe.jvm)
lazy val examplesEmber = exampleProject("examples-ember")
.settings(Revolver.settings)
.settings(
description := "Examples of http4s server and clients on ember",
startYear := Some(2020),
fork := true,
scalacOptions -= "-Xfatal-warnings",
coverageEnabled := false,
)
.dependsOn(emberServer.jvm, emberClient.jvm)
lazy val examplesDocker = http4sProject("examples-docker")
.in(file("examples/docker"))
.enablePlugins(JavaAppPackaging, DockerPlugin, NoPublishPlugin)
.settings(
description := "Builds a docker image for a ember-server",
startYear := Some(2017),
Docker / packageName := "http4s/ember-server",
Docker / maintainer := "http4s",
dockerUpdateLatest := true,
dockerExposedPorts := List(8080),
coverageEnabled := false,
)
.dependsOn(emberServer.jvm, theDsl.jvm)
lazy val scalafixInternalRules = project
.in(file("scalafix-internal/rules"))
.disablePlugins(ScalafixPlugin)
.settings(
name := "http4s-scalafix-internal",
mimaPreviousArtifacts := Set.empty,
startYear := Some(2021),
libraryDependencies ++= Seq(
"ch.epfl.scala" %% "scalafix-core" % _root_.scalafix.sbt.BuildInfo.scalafixVersion
).filter(_ => !tlIsScala3.value),
)
lazy val scalafixInternalInput = project
.in(file("scalafix-internal/input"))
.enablePlugins(NoPublishPlugin)
.disablePlugins(ScalafixPlugin)
.settings(headerSources / excludeFilter := AllPassFilter, scalacOptions -= "-Xfatal-warnings")
.dependsOn(core.jvm)
lazy val scalafixInternalOutput = project
.in(file("scalafix-internal/output"))
.enablePlugins(NoPublishPlugin)
.disablePlugins(ScalafixPlugin)
.settings(headerSources / excludeFilter := AllPassFilter, scalacOptions -= "-Xfatal-warnings")
.dependsOn(core.jvm)
lazy val scalafixInternalTests = project
.in(file("scalafix-internal/tests"))
.enablePlugins(NoPublishPlugin)
.enablePlugins(ScalafixTestkitPlugin)
.settings(
libraryDependencies := {
if (tlIsScala3.value)
libraryDependencies.value.filterNot(_.name == "scalafix-testkit")
else
libraryDependencies.value
},
Compile / compile :=
(Compile / compile).dependsOn(scalafixInternalInput / Compile / compile).value,
scalafixTestkitOutputSourceDirectories :=
(scalafixInternalOutput / Compile / sourceDirectories).value,
scalafixTestkitInputSourceDirectories :=
(scalafixInternalInput / Compile / sourceDirectories).value,
scalafixTestkitInputClasspath :=
(scalafixInternalInput / Compile / fullClasspath).value,
scalafixTestkitInputScalacOptions := (scalafixInternalInput / Compile / scalacOptions).value,
scalacOptions += "-Yrangepos",
)
.settings(headerSources / excludeFilter := AllPassFilter)
.disablePlugins(ScalafixPlugin)
.dependsOn(scalafixInternalRules)
def http4sProject(name: String) =
Project(name, file(name))
.settings(commonSettings)
.settings(
moduleName := s"http4s-$name"
)
.enablePlugins(Http4sPlugin)
.dependsOn(scalafixInternalRules % ScalafixConfig)
def http4sCrossProject(name: String, crossType: CrossType) =
sbtcrossproject
.CrossProject(name, file(name))(JVMPlatform, JSPlatform, NativePlatform)
.withoutSuffixFor(JVMPlatform)
.crossType(crossType)
.settings(commonSettings)
.settings(
moduleName := s"http4s-$name",
Test / test := {
val result = (Test / test).value
if (crossType == CrossType.Full) { // Check for misplaced srcs
val dir = baseDirectory.value / ".." / "src"
if (dir.exists) sys.error(s"Misplaced sources in ${dir.toPath().normalize()}")
}
result
},
)
.jsSettings(
Test / scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule))
)
.nativeSettings(
tlVersionIntroduced := List("2.12", "2.13", "3").map(_ -> "0.23.16").toMap,
unusedCompileDependenciesTest := {},
Test / envVars += "S2N_DONT_MLOCK" -> "1",
)
.enablePlugins(Http4sPlugin)
.configurePlatforms(JSPlatform, NativePlatform)(_.disablePlugins(DoctestPlugin))
.configure(_.dependsOn(scalafixInternalRules % ScalafixConfig))
def libraryProject(name: String) = http4sProject(name)
def libraryCrossProject(name: String, crossType: CrossType = CrossType.Full) =
http4sCrossProject(name, crossType)
def exampleProject(name: String) =
http4sProject(name)
.in(file(name.replace("examples-", "examples/")))
.enablePlugins(NoPublishPlugin)
.settings(libraryDependencies += logbackClassic % Runtime)
.dependsOn(examples)
lazy val commonSettings = Seq(
libraryDependencies ++= Seq(
catsLaws.value,
logbackClassic,
scalacheck.value,
).map(_ % Test)
)
lazy val skipUnusedDependenciesTestOnScala3 = Seq(
unusedCompileDependenciesTest := Def.taskDyn {
val skip = tlIsScala3.value
Def.task {
if (!skip) unusedCompileDependenciesTest.value
}
}
)
def initCommands(additionalImports: String*) =
initialCommands := (List(
"fs2._",
"cats._",
"cats.data._",
"cats.effect._",
"cats.implicits._",
) ++ additionalImports).mkString("import ", ", ", "")
// Everything is driven through release steps and the http4s* variables
// This won't actually release unless on Travis.
addCommandAlias("ci", ";clean ;release with-defaults")
lazy val enableFatalWarnings: String =
"""set ThisBuild / scalacOptions += "-Xfatal-warnings""""
lazy val disableFatalWarnings: String =
"""set ThisBuild / scalacOptions -= "-Xfatal-warnings""""
addCommandAlias(
"quicklint",
List(
enableFatalWarnings,
"scalafixAll --triggered",
"scalafixAll",
"scalafmtAll",
"scalafmtSbt",
disableFatalWarnings,
).mkString(" ;"),
)
// Use this command for checking before submitting a PR
addCommandAlias(
"lint",
List(
enableFatalWarnings,
"clean",
"+test:compile",
"scalafixAll --triggered",
"scalafixAll",
"+scalafmtAll",
"scalafmtSbt",
"+mimaReportBinaryIssues",
disableFatalWarnings,
).mkString(" ;"),
)