-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathbuild.sbt
499 lines (457 loc) · 12.7 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
import org.scalajs.jsenv.nodejs._
import sbtcrossproject.CrossProject
Global / concurrentRestrictions += Tags.limit(NativeTags.Link, 1)
lazy val specs2Version = Def.setting("4.20.9")
lazy val twitterUtilVersion = "24.2.0"
lazy val doobieVersion = "0.13.4"
enablePlugins(BuildInfoPlugin)
def hash() = sys.process.Process("git rev-parse HEAD").lineStream_!.head
moduleName := "root"
effSettings
noPublishSettings
commonJvmSettings
libraryDependencies ++= scalameter.value
libraryDependencies += "org.specs2" %% "specs2-html" % specs2Version.value % "test"
libraryDependencies += "org.scala-lang.modules" %% "scala-collection-compat" % "2.13.0" % Test
disableScala3
dependsOn(
all.jvm % "test->test;compile->compile",
doobie,
macros,
monixJVM,
scalazJVM,
)
def scala3migrationOption(xs: Configuration*) = Def.settings {
xs.map { c =>
c / scalacOptions ++= {
if (scalaBinaryVersion.value == "3") {
Seq("-source:3.0-migration")
} else {
Nil
}
}
}
}
def p(id: String) = CrossProject(id, file(id))(JSPlatform, JVMPlatform, NativePlatform)
.settings(moduleName := s"eff-$id")
.jsSettings(commonJsSettings)
.jvmSettings(commonJvmSettings)
.settings(
effSettings,
)
.nativeSettings(commonNativeSettings)
.dependsOn(core % "compile->compile;test->test")
lazy val core = CrossProject("core", file("core"))(JSPlatform, JVMPlatform, NativePlatform)
.settings(moduleName := "eff-core")
.jsSettings(commonJsSettings)
.jvmSettings(commonJvmSettings)
.settings(
effSettings,
scala3migrationOption(Compile),
)
.nativeSettings(commonNativeSettings)
lazy val eval = p("eval")
lazy val option = p("option")
lazy val either = p("either")
lazy val validate = p("validate")
lazy val error = p("error")
lazy val reader = p("reader")
lazy val writer = p("writer")
lazy val choose = p("choose")
lazy val list = p("list")
lazy val state = p("state")
lazy val safe = p("safe").dependsOn(either)
lazy val batch = p("batch").settings(
scala3migrationOption(Compile),
)
lazy val future = p("future").dependsOn(eval)
lazy val all = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("."))
.settings(moduleName := "eff")
.jsSettings(commonJsSettings)
.jvmSettings(commonJvmSettings)
.jvmSettings(notesSettings)
.settings(
effSettings,
)
.nativeSettings(
commonNativeSettings,
Test / testOptions ++= {
if (scala.util.Properties.isLinux) {
Seq(Tests.Exclude(Set("org.atnos.eff.EvalEffectSpec")))
} else {
Nil
}
},
)
.dependsOn(
core % "test->test",
eval,
option,
either,
validate,
error,
reader,
writer,
choose,
list,
state,
safe,
batch,
future
)
lazy val coreJVM = core.jvm
lazy val coreJS = core.js
lazy val doobie = project
.settings(moduleName := "eff-doobie")
.dependsOn(coreJVM % "compile->compile;test->test")
.settings(libraryDependencies ++= doobieJvm)
.settings(effSettings ++ commonJvmSettings)
lazy val catsEffect = crossProject(JVMPlatform)
.in(file("cats"))
.settings(moduleName := "eff-cats-effect")
.dependsOn(future, option % Test)
.settings(
libraryDependencies += "org.typelevel" %%% "cats-effect" % "3.5.7",
)
.jvmSettings(commonJvmSettings)
.settings(effSettings)
lazy val catsEffectJVM = catsEffect.jvm
lazy val macros = project
.in(file("macros"))
.settings(moduleName := "eff-macros")
.dependsOn(coreJVM, all.jvm % "test->test")
.settings(libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value)
.settings(
disableScala3,
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, v)) if v <= 12 =>
Seq(compilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.patch))
case _ =>
// if scala 2.13.0-M4 or later, macro annotations merged into scala-reflect
// https://github.com/scala/scala/pull/6606
Nil
}
}
)
.settings(commonJvmSettings)
.settings(effSettings)
lazy val monix = crossProject(JSPlatform, JVMPlatform)
.in(file("monix"))
.settings(moduleName := "eff-monix")
.dependsOn(
core % "compile->compile;test->test",
option % Test,
)
.settings(
libraryDependencies += "io.monix" %%% "monix-eval" % "3.4.1",
)
.settings(effSettings)
.jvmSettings(commonJvmSettings)
.jsSettings(commonJsSettings)
lazy val monixJVM = monix.jvm
lazy val monixJS = monix.js
lazy val scalaz = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("scalaz"))
.settings(moduleName := "eff-scalaz")
.dependsOn(
core % "test->test",
option % Test,
choose % Test,
either,
validate,
eval,
safe,
)
.settings(
libraryDependencies += "org.scalaz" %%% "scalaz-core" % "7.3.8",
)
.settings(effSettings)
.jvmSettings(commonJvmSettings)
.jsSettings(commonJsSettings)
.nativeSettings(commonNativeSettings)
lazy val scalazJVM = scalaz.jvm
lazy val scalazJS = scalaz.js
lazy val twitter = project
.settings(moduleName := "eff-twitter")
.dependsOn(
core.jvm % "test->test",
option.jvm % Test,
choose.jvm % Test,
future.jvm
)
.settings(libraryDependencies ++= twitterUtilCore)
.settings(effSettings ++ commonJvmSettings)
.settings(
scala3migrationOption(Test),
conflictWarning := {
if (scalaBinaryVersion.value == "3") {
// TODO
ConflictWarning("warn", Level.Warn, false)
} else {
conflictWarning.value
}
},
)
def Scala212 = "2.12.20"
lazy val buildSettings = Seq(
organization := "org.atnos",
scalaVersion := Scala212,
crossScalaVersions := Seq(Scala212, "2.13.16", "3.3.5")
)
lazy val commonSettings = Def.settings(
libraryDependencies += "org.typelevel" %%% "cats-core" % "2.13.0",
scalacOptions ++= commonScalacOptions.value,
(Compile / doc / scalacOptions) ++= {
Seq(
"-sourcepath",
(LocalRootProject / baseDirectory).value.getAbsolutePath,
"-doc-source-url",
s"https://github.com/atnos-org/eff/tree/${hash()}€{FILE_PATH}.scala"
)
},
(Compile / doc / scalacOptions) := (Compile / doc / scalacOptions).value.filter(_ != "-Xfatal-warnings"),
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) =>
Nil
case _ =>
Seq(
compilerPlugin("org.typelevel" %% "kind-projector" % "0.13.3" cross CrossVersion.full)
)
}
}
) ++ warnUnusedImport ++ prompt
lazy val commonJsSettings = Def.settings(
libraryDependencies ++= specs2.value,
parallelExecution := false,
if (sys.props.isDefinedAt("scala_js_wasm")) {
println("enable wasm")
Def.settings(
scalaJSLinkerConfig ~= (
_.withExperimentalUseWebAssembly(true).withModuleKind(ModuleKind.ESModule)
),
jsEnv := {
import org.scalajs.jsenv.nodejs.NodeJSEnv
val config = NodeJSEnv
.Config()
.withArgs(
List(
"--experimental-wasm-exnref",
"--experimental-wasm-imported-strings",
"--turboshaft-wasm",
)
)
new NodeJSEnv(config)
},
)
} else {
Def.settings()
},
scalacOptions ++= {
if (scalaBinaryVersion.value == "3") {
Nil
} else {
Seq("-P:scalajs:nowarnGlobalExecutionContext")
}
},
scalacOptions += {
val a = (LocalRootProject / baseDirectory).value.toURI.toString
val g = "https://raw.githubusercontent.com/atnos-org/eff/" + hash()
val key = CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) =>
"-scalajs-mapSourceURI"
case _ =>
"-P:scalajs:mapSourceURI"
}
s"${key}:$a->$g/"
}
)
lazy val commonJvmSettings = Seq(
libraryDependencies ++= specs2.value,
Test / fork := true,
Global / cancelable := true,
Test / scalacOptions ~= (_.filterNot(_ == "-Xfatal-warnings")),
Test / scalacOptions ++= {
if (scalaBinaryVersion.value == "3") {
Nil
} else {
Seq("-Yrangepos")
}
},
)
lazy val commonNativeSettings = Def.settings(
libraryDependencies ++= specs2.value,
Test / test := {
if ((Test / sources).value.isEmpty) {
()
} else {
(Test / test).value
}
},
)
lazy val effSettings =
buildSettings ++ commonSettings ++ publishSettings
lazy val publishSettings =
Seq(
homepage := Some(url("https://github.com/atnos-org/eff")),
licenses := Seq("MIT" -> url("https://opensource.org/licenses/MIT")),
scmInfo := Some(ScmInfo(url("https://github.com/atnos-org/eff"), "scm:git:[email protected]:atnos-org/eff.git")),
autoAPIMappings := true,
apiURL := Some(url("http://atnos.org/eff/api/")),
pomExtra := (
<developers>
<developer>
<id>etorreborre</id>
<name>Eric Torreborre</name>
<url>https://github.com/etorreborre/</url>
</developer>
</developers>
)
) ++ sharedPublishSettings
lazy val noPublishSettings = Seq(
publish := (()),
publishLocal := (()),
publishArtifact := false
)
lazy val commonScalacOptions = Def.setting {
Seq(
"-deprecation",
"-encoding",
"UTF-8",
"-feature",
"-language:implicitConversions,higherKinds,existentials",
"-unchecked",
) ++ {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) =>
Seq("-Xsource:3-cross")
case Some((2, 12)) =>
Seq("-Xsource:3")
case _ =>
Nil
}
} ++ {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, _)) =>
Seq(
"-Xlint",
"-Xlint:-nullary-unit",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
)
case _ =>
Nil
}
} ++ {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, v)) if v >= 13 =>
Seq(
"-Ymacro-annotations"
)
case Some((3, _)) =>
Seq(
"-no-indent",
"-Ykind-projector",
)
case _ =>
Seq(
"-Xfatal-warnings",
"-Yno-adapted-args",
"-Ypartial-unification",
"-Xfuture"
)
}
}
}
lazy val sharedPublishSettings = Seq(
publishMavenStyle := true,
Test / publishArtifact := false,
pomIncludeRepository := Function.const(false),
publishTo := sonatypePublishToBundle.value,
) ++ notesSettings
lazy val notesSettings = Seq(
ghreleaseRepoOrg := "atnos-org",
ghreleaseRepoName := "eff",
ghreleaseTitle := { (tagName: TagName) => s"eff ${tagName.replace("EFF-", "")}" },
ghreleaseIsPrerelease := { (tagName: TagName) => false },
ghreleaseNotes := { (tagName: TagName) =>
// find the corresponding release notes
val notesFilePath = s"notes/${tagName.replace("EFF-", "")}.markdown"
try scala.io.Source.fromFile(notesFilePath).mkString
catch { case t: Throwable => throw new Exception(s"$notesFilePath not found", t) }
},
// just upload the notes
ghreleaseAssets := Seq()
)
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion)
buildInfoPackage := "org.atnos.eff"
lazy val warnUnusedImport = Seq(
Compile / console / scalacOptions ~= { _.filterNot("-Ywarn-unused-import" == _) },
(Test / console / scalacOptions) := (Compile / console / scalacOptions).value
)
lazy val prompt = ThisBuild / shellPrompt := { state =>
val name = Project.extract(state).currentRef.project
(if (name == "eff") "" else name) + "> "
}
lazy val doobieJvm = Seq("org.tpolecat" %% "doobie-core" % doobieVersion, "org.tpolecat" %% "doobie-h2" % doobieVersion % "test")
lazy val specs2 = Def.setting(
Seq(
"org.specs2" %%% "specs2-core",
"org.specs2" %%% "specs2-matcher-extra",
"org.specs2" %%% "specs2-scalacheck",
"org.specs2" %%% "specs2-junit",
).map(
_ % specs2Version.value % "test"
).map(
_.exclude(
"org.specs2",
"xml_sjs1_" + scalaBinaryVersion.value
).exclude(
"org.specs2",
"xml_native0.5_" + scalaBinaryVersion.value
)
)
)
lazy val scalameter = Def.setting(
if (scalaBinaryVersion.value == "3") {
Nil
} else {
Seq("com.storm-enroute" %% "scalameter" % "0.19" % "test")
}
)
lazy val twitterUtilCore = Seq(
"com.twitter" %% "util-core" % twitterUtilVersion
)
lazy val disableScala3 = Def.settings(
libraryDependencies := {
if (scalaBinaryVersion.value == "3") {
Nil
} else {
libraryDependencies.value
}
},
Seq(Compile, Test).map { x =>
(x / sources) := {
if (scalaBinaryVersion.value == "3") {
Nil
} else {
(x / sources).value
}
}
},
Test / test := {
if (scalaBinaryVersion.value == "3") {
()
} else {
(Test / test).value
}
},
publish / skip := (scalaBinaryVersion.value == "3"),
)
Global / excludeLintKeys ++= Set(
ghreleaseIsPrerelease,
ghreleaseNotes,
ghreleaseTitle,
)