-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.sbt
305 lines (280 loc) · 12.2 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
import org.scalajs.linker.interface.OutputPatterns
import sbtwelcome.*
import java.net.URI
Global / onChangedBuildSource := ReloadOnSourceChanges
autoCompilerPlugins := true
val scalusStableVersion = "0.8.4"
ThisBuild / scalaVersion := "3.3.4"
ThisBuild / organization := "org.scalus"
ThisBuild / organizationName := "Scalus"
ThisBuild / organizationHomepage := Some(url("https://scalus.org/"))
ThisBuild / developers := List(
Developer(
id = "atlanter",
name = "Alexander Nemish",
email = "[email protected]",
url = url("https://github.com/nau")
)
)
ThisBuild / description := "Scalus - DApps Development Platform for Cardano"
ThisBuild / licenses := List(
"Apache 2" -> new URI("http://www.apache.org/licenses/LICENSE-2.0.txt").toURL
)
ThisBuild / homepage := Some(url("https://github.com/nau/scalus"))
ThisBuild / versionScheme := Some("early-semver")
ThisBuild / sonatypeCredentialHost := "s01.oss.sonatype.org"
sonatypeRepository := "https://s01.oss.sonatype.org/service/local"
Test / publishArtifact := false
ThisBuild / javaOptions += "-Xss64m"
Compile / doc / scalacOptions ++= Seq(
"-groups",
"-project-version",
scalusStableVersion,
"-project-footer",
"Lantr.io"
)
lazy val root: Project = project
.in(file("."))
.aggregate(
scalusPlugin,
scalus.js,
scalus.jvm,
`examples-js`,
examples,
bench,
`scalus-bloxbean-cardano-client-lib`,
docs
)
.settings(
publish / skip := true
)
lazy val commonScalacOptions = Seq(
"-deprecation",
"-feature",
"-explain",
"-Wunused:imports",
"-Wunused:params",
"-Xcheck-macros"
// "-rewrite",
// "-source:future-migration"
)
lazy val copySharedFiles = taskKey[Unit]("Copy shared files")
// Scala 3 Compiler Plugin for Scalus
lazy val scalusPlugin = project
.in(file("scalus-plugin"))
.settings(
name := "scalus-plugin",
scalacOptions ++= commonScalacOptions,
scalacOptions += "-Wunused:all",
// Manually set a fixed version to avoid recompilation on every commit
// as sbt-ci-release plugin increments the version on every commit
// thus recompiling the plugin and all dependent projects
// COMMENT THIS LINE TO ENABLE VERSION INCREMENT during Scalus plugin development
// version := "0.6.2-SNAPSHOT",
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.2.19" % "test",
libraryDependencies += "org.scalatestplus" %%% "scalacheck-1-16" % "3.2.14.0" % "test",
libraryDependencies += "org.scala-lang" %% "scala3-compiler" % scalaVersion.value // % "provided"
)
.settings(
/*
Include common sources in the plugin
we can't add the scalus project as a dependency because this is a Scala compiler plugin
and apparently it's not supported
Another option is to use sbt-assembly to create a fat jar with all the dependencies
I copy the shared files to the plugin project because when I use managedSources in the plugin
IntelliJ IDEA only sees these files being used in the plugin project and not in the main project
This breaks navigation and refactoring in the main project.
By copying the shared files to the plugin project, IntelliJ IDEA sees them as used in the plugin project
*/
copySharedFiles := {
val targetDir = (Compile / sourceDirectory).value / "shared" / "scala"
val log = streams.value.log
val sharedFiles =
Seq(
"scalus/utils/Hex.scala",
"scalus/builtin/ByteString.scala",
"scalus/builtin/Data.scala",
"scalus/builtin/List.scala",
"scalus/sir/SIR.scala",
"scalus/sir/FlatInstances.scala",
"scalus/uplc/Constant.scala",
"scalus/uplc/DefaultFun.scala",
"scalus/uplc/DefaultUni.scala",
"scalus/uplc/CommonFlatInstances.scala",
"scalus/flat/package.scala"
)
sharedFiles.foreach { file =>
val baseDir = baseDirectory.value / ".." / "shared" / "src" / "main" / "scala"
val source = baseDir / file
val target = targetDir / file
if (source.exists) {
IO.copyFile(source, target)
log.info(s"Copied $file to target $target")
} else {
log.error(s"Source file not found: $file")
}
}
},
Compile / unmanagedSourceDirectories += (Compile / sourceDirectory).value / "shared" / "scala",
clean := {
(Compile / clean).value
streams.value.log.info("Cleaning shared files")
IO.delete((Compile / sourceDirectory).value / "shared")
},
Compile / compile := (Compile / compile).dependsOn(copySharedFiles).value
)
// Used only for Scalus compiler plugin development
// I use it to not recompile all the tests in the main project
// TODO remove or comment out
lazy val scalusPluginTests = project
.in(file("scalus-plugin-tests"))
.dependsOn(scalus.jvm)
.settings(
name := "scalus-plugin-tests",
publish / skip := true,
PluginDependency,
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.2.19" % "test",
libraryDependencies += "org.scalatestplus" %%% "scalacheck-1-16" % "3.2.12.0" % "test"
)
// Scalus Compiler Plugin Dependency
lazy val PluginDependency: List[Def.Setting[?]] = List(scalacOptions ++= {
val jar = (scalusPlugin / Compile / packageBin).value
// add plugin timestamp to compiler options to trigger recompile of
// main after editing the plugin. (Otherwise a 'clean' is needed.)
// NOTE: uncomment for faster Scalus Plugin development
// this will recompile the plugin when the jar is modified
// Seq(s"-Xplugin:${jar.getAbsolutePath}", s"-Jdummy=${jar.lastModified}")
Seq(s"-Xplugin:${jar.getAbsolutePath}")
})
// Scalus Core and Standard Library for JVM and JS
lazy val scalus = crossProject(JSPlatform, JVMPlatform)
.in(file("."))
.settings(
name := "scalus",
scalaVersion := scalaVersion.value,
scalacOptions ++= commonScalacOptions,
scalacOptions += "-Xmax-inlines:100", // needed for upickle derivation of CostModel
// scalacOptions += "-Yretain-trees",
libraryDependencies += "org.typelevel" %%% "cats-core" % "2.12.0",
libraryDependencies += "org.typelevel" %%% "cats-parse" % "1.1.0",
libraryDependencies += "org.typelevel" %%% "paiges-core" % "0.4.4",
libraryDependencies += "com.lihaoyi" %%% "upickle" % "4.1.0",
libraryDependencies ++= Seq(
"io.bullet" %%% "borer-core" % "1.15.0",
"io.bullet" %%% "borer-derivation" % "1.15.0" % "provided"
),
PluginDependency,
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.2.19" % "test",
libraryDependencies += "org.scalatestplus" %%% "scalacheck-1-16" % "3.2.14.0" % "test"
)
.jvmSettings(
Test / fork := true,
// Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-S", "-8077211454138081902"),
libraryDependencies += "org.slf4j" % "slf4j-simple" % "2.0.16" % "provided",
libraryDependencies += "org.bouncycastle" % "bcprov-jdk18on" % "1.79",
libraryDependencies += "foundation.icon" % "blst-java" % "0.3.2",
libraryDependencies += "org.bitcoin-s" % "bitcoin-s-crypto_2.13" % "1.9.9",
libraryDependencies += "org.bitcoin-s" % "bitcoin-s-secp256k1jni" % "1.9.9"
)
.jsSettings(
// Add JS-specific settings here
Compile / npmDependencies += "@noble/curves" -> "1.4.2",
scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.CommonJSModule)
// Use .mjs extension.
// .withOutputPatterns(OutputPatterns.fromJSFile("%s.mjs"))
},
scalaJSUseMainModuleInitializer := false
)
.jsConfigure { project => project.enablePlugins(ScalaJSBundlerPlugin) }
lazy val examples = project
.in(file("examples"))
.dependsOn(scalus.jvm, `scalus-bloxbean-cardano-client-lib`)
.settings(
PluginDependency,
scalacOptions ++= commonScalacOptions,
publish / skip := true,
libraryDependencies += "com.bloxbean.cardano" % "cardano-client-backend-blockfrost" % "0.6.3"
)
lazy val `examples-js` = project
.enablePlugins(ScalaJSPlugin, ScalaJSBundlerPlugin)
.in(file("examples-js"))
.dependsOn(scalus.js)
.settings(
publish / skip := true,
scalacOptions ++= commonScalacOptions,
Compile / npmDependencies += "@noble/curves" -> "1.4.2",
scalaJSUseMainModuleInitializer := false,
scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.CommonJSModule)
},
PluginDependency
)
// Bloxbean Cardano Client Lib integration and Tx Evaluator implementation
lazy val `scalus-bloxbean-cardano-client-lib` = project
.in(file("bloxbean-cardano-client-lib"))
.dependsOn(scalus.jvm)
.settings(
publish / skip := false,
scalacOptions ++= commonScalacOptions,
libraryDependencies += "com.bloxbean.cardano" % "cardano-client-lib" % "0.6.3",
libraryDependencies += "org.slf4j" % "slf4j-api" % "2.0.16",
libraryDependencies += "org.slf4j" % "slf4j-simple" % "2.0.16" % "test",
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.2.19" % "test",
libraryDependencies += "com.bloxbean.cardano" % "cardano-client-backend-blockfrost" % "0.6.3" % "test",
libraryDependencies += "com.bloxbean.cardano" % "yaci" % "0.3.4.1" % "test",
Test / fork := true, // needed for BlocksValidation to run in sbt
inConfig(Test)(PluginDependency)
)
// Documentation
// We use Docusaurus for documentation
// and Mdoc for Scala code examples
lazy val docs = project // documentation project
.in(file("scalus-docs")) // important: it must not be docs/
.dependsOn(scalus.jvm)
.enablePlugins(MdocPlugin, DocusaurusPlugin, ScalaUnidocPlugin)
.settings(
publish / skip := true,
moduleName := "scalus-docs",
mdocVariables := Map(
"VERSION" -> scalusStableVersion,
"SCALA3_VERSION" -> scalaVersion.value
),
ScalaUnidoc / unidoc / unidocProjectFilter := inProjects(scalus.jvm),
ScalaUnidoc / unidoc / target := (LocalRootProject / baseDirectory).value / "website" / "static" / "api",
cleanFiles += (ScalaUnidoc / unidoc / target).value,
docusaurusCreateSite := docusaurusCreateSite.dependsOn(Compile / unidoc).value,
docusaurusPublishGhpages := docusaurusPublishGhpages.dependsOn(Compile / unidoc).value,
PluginDependency
)
// Benchmarks for Cardano Plutus VM Evaluator
lazy val bench = project
.in(file("bench"))
.dependsOn(scalus.jvm)
.enablePlugins(JmhPlugin)
.settings(
name := "scalus-bench",
PluginDependency,
publish / skip := true
)
addCommandAlias(
"precommit",
"clean;docs/clean;scalusPluginTests/clean;scalafmtAll;scalafmtSbt;Test/compile;scalusPluginTests/Test/compile;test;docs/mdoc"
)
logo :=
s"""
| ${scala.Console.RED}███████╗ ██████╗ █████╗ ██╗ ██╗ ██╗███████╗
| ${scala.Console.RED}██╔════╝██╔════╝██╔══██╗██║ ██║ ██║██╔════╝
| ${scala.Console.RED}███████╗██║ ███████║██║ ██║ ██║███████╗
| ${scala.Console.RED}╚════██║██║ ██╔══██║██║ ██║ ██║╚════██║
| ${scala.Console.RED}███████║╚██████╗██║ ██║███████╗╚██████╔╝███████║
| ${scala.Console.RED}╚══════╝ ╚═════╝╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚══════╝
|
| Version: ${version.value} ${scala.Console.YELLOW}Scala ${scalaVersion.value}${scala.Console.RESET}
|
|""".stripMargin
usefulTasks := Seq(
UsefulTask("~compile", "Compile with file-watch enabled"),
UsefulTask("precommit", "Format all, clean compile and test everything"),
UsefulTask("docs/docusaurusCreateSite", "Generate Scalus documentation website")
)