forked from chipsalliance/chisel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
531 lines (499 loc) · 19.5 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
// See LICENSE for license details.
enablePlugins(SiteScaladocPlugin)
addCommandAlias("fmt", "; scalafmtAll ; scalafmtSbt")
addCommandAlias("fmtCheck", "; scalafmtCheckAll ; scalafmtSbtCheck")
// Previous versions are read from project/previous-versions.txt
// If this file is empty or does not exist, no binary compatibility checking will be done
// Add waivers to the directory defined by key `mimaFiltersDirectory` in files named: <since version>.backwards.excludes
// eg. unipublish/src/main/mima-filters/5.0.0.backwards.excludes
val previousVersions = settingKey[Set[String]]("Previous versions for binary compatibility checking")
ThisBuild / previousVersions := {
val file = new java.io.File("project", "previous-versions.txt")
if (file.isFile) {
scala.io.Source.fromFile(file).getLines.toSet
} else {
Set()
}
}
val emitVersion = taskKey[Unit]("Write the version to version.txt")
emitVersion := {
IO.write(new java.io.File("version.txt"), version.value)
}
val emitLatestVersion = taskKey[Unit]("Write the latest stable version to latest-version.txt")
emitLatestVersion := {
import Version.SemanticVersion
val latest = Releases.getLatest(Releases.releases(streams.value.log))
IO.write(new java.io.File("latest-version.txt"), latest.serialize)
}
lazy val minimalSettings = Seq(
organization := "org.chipsalliance",
scalacOptions := Seq("-deprecation", "-feature"),
scalaVersion := "2.13.14"
)
lazy val commonSettings = minimalSettings ++ Seq(
resolvers ++= Resolver.sonatypeOssRepos("snapshots"),
resolvers ++= Resolver.sonatypeOssRepos("releases"),
autoAPIMappings := true,
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value,
// Macros paradise is integrated into 2.13 but requires a scalacOption
scalacOptions += "-Ymacro-annotations"
)
lazy val fatalWarningsSettings = Seq(
scalacOptions ++= {
if (sys.props.contains("disableFatalWarnings")) {
Nil
} else {
"-Werror" :: Nil
}
}
)
lazy val warningSuppression = Seq(
scalacOptions += "-Wconf:" + Seq(
"msg=APIs in chisel3.internal:s",
"msg=Importing from firrtl:s",
"msg=migration to the MLIR:s",
"msg=method hasDefiniteSize in trait IterableOnceOps is deprecated:s", // replacement `knownSize` is not in 2.12
"msg=object JavaConverters in package collection is deprecated:s",
"msg=undefined in comment for method cf in class PrintableHelper:s",
// This is deprecated for external users but not internal use
"cat=deprecation&origin=firrtl\\.options\\.internal\\.WriteableCircuitAnnotation:s",
"cat=deprecation&origin=chisel3\\.util\\.experimental\\.BoringUtils.*:s",
"cat=deprecation&origin=chisel3\\.experimental\\.IntrinsicModule:s"
).mkString(",")
)
// This should only be mixed in by projects that are published
// See 'unipublish' project below
lazy val publishSettings = Seq(
versionScheme := Some("semver-spec"),
publishMavenStyle := true,
Test / publishArtifact := false,
pomIncludeRepository := { x => false },
homepage := Some(url("https://www.chisel-lang.org")),
organizationHomepage := Some(url("https://www.chipsalliance.org")),
licenses := List(License.Apache2),
developers := List(
Developer("jackkoenig", "Jack Koenig", "[email protected]", url("https://github.com/jackkoenig")),
Developer("azidar", "Adam Izraelevitz", "[email protected]", url("https://github.com/azidar")),
Developer("seldridge", "Schuyler Eldridge", "[email protected]", url("https://github.com/seldridge"))
),
sonatypeCredentialHost := "s01.oss.sonatype.org",
sonatypeRepository := "https://s01.oss.sonatype.org/service/local",
// We are just using 'publish / skip' as a hook to run checks required for publishing,
// but that are not necessarily required for local development or running testing in CI
publish / skip := {
// Check that SBT Dynver can properly derive a version which requires unshallow clone
val v = version.value
if (dynverGitDescribeOutput.value.hasNoTags) {
sys.error(s"Failed to derive version from git tags. Maybe run `git fetch --unshallow`? Version: $v")
}
(publish / skip).value
},
publishTo := {
val v = version.value
val nexus = "https://s01.oss.sonatype.org/"
if (v.trim.endsWith("SNAPSHOT")) {
Some("snapshots".at(nexus + "content/repositories/snapshots"))
} else {
Some("releases".at(nexus + "service/local/staging/deploy/maven2"))
}
}
)
// FIRRTL SETTINGS
lazy val firrtlSettings = Seq(
name := "firrtl",
addCompilerPlugin(scalafixSemanticdb),
scalacOptions := Seq(
"-deprecation",
"-unchecked",
"-language:reflectiveCalls",
"-language:existentials",
"-language:implicitConversions",
"-Yrangepos" // required by SemanticDB compiler plugin
),
// Always target Java8 for maximum compatibility
javacOptions ++= Seq("-source", "1.8", "-target", "1.8"),
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scalatest" %% "scalatest" % "3.2.18" % "test",
"org.scalatestplus" %% "scalacheck-1-18" % "3.2.18.0" % "test",
"com.github.scopt" %% "scopt" % "4.1.0",
"org.json4s" %% "json4s-native" % "4.0.7",
"org.apache.commons" % "commons-text" % "1.12.0",
"io.github.alexarchambault" %% "data-class" % "0.2.6",
"com.lihaoyi" %% "os-lib" % "0.10.0"
),
scalacOptions += "-Ymacro-annotations",
// starting with scala 2.13 the parallel collections are separate from the standard library
libraryDependencies += "org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.4"
)
lazy val assemblySettings = Seq(
assembly / assemblyJarName := "firrtl.jar",
assembly / test := {},
assembly / assemblyOutputPath := file("./utils/bin/firrtl.jar")
)
lazy val testAssemblySettings = Seq(
Test / assembly / test := {}, // Ditto above
Test / assembly / assemblyMergeStrategy := {
case PathList("firrtlTests", xs @ _*) => MergeStrategy.discard
case x =>
val oldStrategy = (Test / assembly / assemblyMergeStrategy).value
oldStrategy(x)
},
Test / assembly / assemblyJarName := s"firrtl-test.jar",
Test / assembly / assemblyOutputPath := file("./utils/bin/" + (Test / assembly / assemblyJarName).value)
)
lazy val svsim = (project in file("svsim"))
.settings(minimalSettings)
.settings(
// Published as part of unipublish
publish / skip := true,
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.2.18" % "test",
"org.scalatestplus" %% "scalacheck-1-18" % "3.2.18.0" % "test"
)
)
lazy val firrtl = (project in file("firrtl"))
.enablePlugins(ScalaUnidocPlugin)
.settings(
fork := true,
Test / testForkedParallel := true
)
.settings(commonSettings)
.settings(firrtlSettings)
.settings(assemblySettings)
.settings(inConfig(Test)(baseAssemblySettings))
.settings(testAssemblySettings)
.settings(
// Published as part of unipublish
publish / skip := true
)
.enablePlugins(BuildInfoPlugin)
.settings(
buildInfoPackage := name.value,
buildInfoUsePackageAsPath := true,
buildInfoKeys := Seq[BuildInfoKey](buildInfoPackage, version, scalaVersion, sbtVersion)
)
.settings(warningSuppression: _*)
.settings(fatalWarningsSettings: _*)
lazy val chiselSettings = Seq(
name := "chisel",
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.2.18" % "test",
"org.scalatestplus" %% "scalacheck-1-18" % "3.2.18.0" % "test",
"com.lihaoyi" %% "upickle" % "3.3.0",
"org.chipsalliance" %% "firtool-resolver" % "2.0.0"
)
) ++ (
// Tests from other projects may still run concurrently
// if we're not running with -DminimalResources.
// Another option would be to experiment with:
// concurrentRestrictions in Global += Tags.limit(Tags.Test, 1),
sys.props.contains("minimalResources") match {
case true => Seq(Test / parallelExecution := false)
case false => Seq(fork := true, Test / testForkedParallel := true)
}
)
autoCompilerPlugins := true
autoAPIMappings := true
// Plugin must be fully cross-versioned (published for Scala minor version)
lazy val pluginScalaVersions = Seq(
"2.13.0",
"2.13.1",
"2.13.2",
"2.13.3",
"2.13.4",
"2.13.5",
"2.13.6",
"2.13.7",
"2.13.8",
"2.13.9",
"2.13.10",
"2.13.11",
"2.13.12",
"2.13.13",
"2.13.14"
)
lazy val plugin = (project in file("plugin"))
.settings(name := "chisel-plugin")
.settings(commonSettings: _*)
.settings(publishSettings: _*)
.settings(
libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value,
crossScalaVersions := pluginScalaVersions,
// Must be published for Scala minor version
crossVersion := CrossVersion.full,
crossTarget := {
// workaround for https://github.com/sbt/sbt/issues/5097
target.value / s"scala-${scalaVersion.value}"
}
)
.settings(fatalWarningsSettings: _*)
.settings(
mimaPreviousArtifacts := previousVersions.value.map { version =>
(organization.value % name.value % version).cross(CrossVersion.full)
}
)
lazy val usePluginSettings = Seq(
Compile / scalacOptions ++= {
val jar = (plugin / Compile / Keys.`package`).value
val addPlugin = "-Xplugin:" + jar.getAbsolutePath
// add plugin timestamp to compiler options to trigger recompile of
// main after editing the plugin. (Otherwise a 'clean' is needed.)
val dummy = "-Jdummy=" + jar.lastModified
Seq(addPlugin, dummy)
}
)
lazy val macros = (project in file("macros"))
.settings(name := "chisel-macros")
.settings(commonSettings: _*)
.settings(
// Published as part of unipublish
publish / skip := true
)
lazy val core = (project in file("core"))
.settings(commonSettings: _*)
.enablePlugins(BuildInfoPlugin)
.settings(
buildInfoPackage := "chisel3",
buildInfoUsePackageAsPath := true,
buildInfoKeys := {
// This remains an Option for backwards compatibility reasons
val firtoolVersion = BuildInfoKey("firtoolVersion", Option(FirtoolVersion.version))
Seq[BuildInfoKey](buildInfoPackage, version, scalaVersion, sbtVersion, firtoolVersion)
}
)
.settings(
// Published as part of unipublish
publish / skip := true
)
.settings(warningSuppression: _*)
.settings(fatalWarningsSettings: _*)
.settings(
name := "chisel-core",
libraryDependencies ++= Seq(
"com.lihaoyi" %% "upickle" % "3.3.0",
"com.lihaoyi" %% "os-lib" % "0.10.0"
),
scalacOptions := scalacOptions.value ++ Seq(
"-explaintypes",
"-feature",
"-language:reflectiveCalls",
"-unchecked",
"-Xcheckinit",
"-Xlint:infer-any"
// , "-Xlint:missing-interpolator"
)
)
.dependsOn(macros)
.dependsOn(firrtl)
// This will always be the root project, even if we are a sub-project.
lazy val root = RootProject(file("."))
lazy val chisel = (project in file("."))
.settings(commonSettings: _*)
.settings(chiselSettings: _*)
.settings(
// Published as part of unipublish
publish / skip := true
)
.settings(usePluginSettings: _*)
.dependsOn(macros)
.dependsOn(core)
.dependsOn(firrtl)
.dependsOn(svsim)
.aggregate(macros, core, plugin, firrtl, svsim)
.settings(
// Suppress Scala 3 behavior requiring explicit types on implicit definitions
// Note this must come before the -Wconf is warningSuppression
Test / scalacOptions += "-Wconf:cat=other-implicit-type:s"
)
.settings(warningSuppression: _*)
.settings(fatalWarningsSettings: _*)
.settings(
Test / scalacOptions ++= Seq("-language:reflectiveCalls")
)
def addUnipublishDeps(proj: Project)(deps: Project*): Project = {
def inTestScope(module: ModuleID): Boolean = module.configurations.exists(_ == "test")
deps.foldLeft(proj) {
case (p, dep) =>
p.settings(
libraryDependencies ++= (dep / libraryDependencies).value.filterNot(inTestScope),
Compile / packageBin / mappings ++= (dep / Compile / packageBin / mappings).value,
Compile / packageSrc / mappings ++= (dep / Compile / packageSrc / mappings).value
)
}
}
// This is a pseudo-project that unifies all compilation units (excluding the plugin) into a single artifact
// It should be used for all publishing and MiMa binary compatibility checking
lazy val unipublish =
addUnipublishDeps(project in file("unipublish"))(
firrtl,
svsim,
macros,
core,
chisel
)
.aggregate(plugin) // Also publish the plugin when publishing this project
.settings(name := (chisel / name).value)
.enablePlugins(ScalaUnidocPlugin)
.settings(
// Plugin isn't part of Chisel's public API, exclude from ScalaDoc
// Even though this project doesn't depend on docs, Unidoc pulls it in unless we exclude it
ScalaUnidoc / unidoc / unidocProjectFilter := inAnyProject -- inProjects(plugin) -- inProjects(docs)
)
.settings(commonSettings: _*)
.settings(publishSettings: _*)
.settings(usePluginSettings: _*)
.settings(warningSuppression: _*)
.settings(fatalWarningsSettings: _*)
.settings(
mimaPreviousArtifacts := previousVersions.value.map { version =>
organization.value %% name.value % version
},
// This is a pseudo-project with no class files, use the package jar instead
mimaCurrentClassfiles := (Compile / packageBin).value,
// Forward doc command to unidoc
Compile / doc := (ScalaUnidoc / doc).value,
// Include unidoc as the ScalaDoc for publishing
Compile / packageDoc / mappings := (ScalaUnidoc / packageDoc / mappings).value,
Compile / doc / scalacOptions ++= Seq(
"-diagrams",
"-groups",
"-skip-packages",
"chisel3.internal",
"-diagrams-max-classes",
"25",
"-doc-version",
version.value,
"-doc-title",
name.value,
"-doc-root-content",
baseDirectory.value + "/root-doc.txt",
"-sourcepath",
(ThisBuild / baseDirectory).value.toString,
"-doc-source-url", {
val branch =
if (version.value.endsWith("-SNAPSHOT")) {
"main"
} else {
s"v${version.value}"
}
s"https://github.com/chipsalliance/chisel/tree/$branch/€{FILE_PATH_EXT}#L€{FILE_LINE}"
},
"-language:implicitConversions"
) ++
// Suppress compiler plugin for source files in core
// We don't need this in regular compile because we just don't add the chisel-plugin to core's scalacOptions
// This works around an issue where unidoc uses the exact same arguments for all source files.
// This is probably fundamental to how ScalaDoc works so there may be no solution other than this workaround.
// See https://github.com/sbt/sbt-unidoc/issues/107
(core / Compile / sources).value.map("-P:chiselplugin:INTERNALskipFile:" + _)
++ Seq("-implicits")
)
// End-to-end tests that check the functionality of the emitted design with simulation
lazy val integrationTests = (project in file("integration-tests"))
.dependsOn(chisel % "compile->compile;test->test")
.dependsOn(firrtl) // SBT doesn't seem to be propagating transitive library dependencies...
.dependsOn(standardLibrary)
.settings(commonSettings: _*)
.settings(warningSuppression: _*)
.settings(fatalWarningsSettings: _*)
.settings(chiselSettings: _*)
.settings(usePluginSettings: _*)
// the chisel standard library
lazy val standardLibrary = (project in file("stdlib"))
.dependsOn(chisel)
.settings(commonSettings: _*)
.settings(chiselSettings: _*)
.settings(usePluginSettings: _*)
val determineContributors = taskKey[Unit]("determine contributors for subprojects")
val generateScalaDocLinks = taskKey[Unit]("generate links to API Docs for releases")
val firtoolVersionsTableTask = taskKey[Seq[File]]("generate markdown table mapping Chisel versions to firtool versions")
import Version._
lazy val docs = project // new documentation project
.in(file("docs-target")) // important: it must not be docs/
.dependsOn(chisel)
.enablePlugins(MdocPlugin)
.settings(usePluginSettings: _*)
.settings(commonSettings)
.settings(
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.14",
scalacOptions ++= Seq(
"-language:reflectiveCalls",
"-language:implicitConversions",
"-Wconf:msg=firrtl:s,cat=other-implicit-type:s"
),
mdocIn := file("docs/src"),
mdocOut := file("docs/generated"),
// None of our links are hygienic because they're primarily used on the website with .html
mdocExtraArguments := Seq("--cwd", "docs", "--no-link-hygiene"),
mdocVariables := Map(
"BUILD_DIR" -> "docs-target" // build dir for mdoc programs to dump temp files
)
)
.settings(fatalWarningsSettings: _*)
.settings(
firtoolVersionsTableTask / fileInputs ++= {
val rootGlob = (root / baseDirectory).value.toGlob
Seq(rootGlob / "build.sbt", rootGlob / "project" / "*.sbt", rootGlob / "project" / "*.scala")
},
firtoolVersionsTableTask := {
val logger = streams.value.log
val file = (Compile / sourceManaged).value / "FirtoolVersionsTable.scala"
// Only write the file if an input has changed
if (!file.exists || firtoolVersionsTableTask.inputFileChanges.hasChanges) {
// Escaping newlines makes it easier to generate the file
val releaseTable = FirtoolVersionsTable.generateTable(true, logger).replaceAll("\n", "\\\\n")
val prereleaseTable = FirtoolVersionsTable.generateTable(false, logger).replaceAll("\n", "\\\\n")
logger.info(s"Writing $file...")
IO.write(
file,
s"""|object FirtoolVersionsTable {
| def releaseTable = "$releaseTable"
| def prereleaseTable = "$prereleaseTable"
|}""".stripMargin
)
}
Seq(file)
},
Compile / sourceGenerators += firtoolVersionsTableTask.taskValue
)
.settings(
determineContributors := {
import java.io.{File, PrintWriter}
val uniqueContributors =
// Even though we no longer host all these projects,
// we still honor their contributions
Seq(
GitHubRepository("chipsalliance", "chisel"),
GitHubRepository("chipsalliance", "chisel-template"),
GitHubRepository("chipsalliance", "firrtl"),
GitHubRepository("chipsalliance", "treadle"),
GitHubRepository("ucb-bar", "chiseltest"),
GitHubRepository("ucb-bar", "chisel2-deprecated"),
GitHubRepository("freechipsproject", "chisel-bootcamp"),
GitHubRepository("freechipsproject", "chisel-testers"),
GitHubRepository("freechipsproject", "diagrammer"),
GitHubRepository("freechipsproject", "firrtl-interpreter"),
GitHubRepository("freechipsproject", "www.chisel-lang.org")
)
.flatMap(Contributors.contributors)
.map(b => (b.login, b.html_url))
.distinct
val writer = new PrintWriter(new File("website/src/pages/generated/contributors.md"))
writer.write(s"""|<!-- Automatically generated by build.sbt 'contributors' task -->
|${Contributors.contributorsMarkdown(uniqueContributors)}""".stripMargin)
writer.close()
},
generateScalaDocLinks := {
import java.io.{File, PrintWriter}
import java.nio.file.{Files}
val outputFile = new File(s"website/src/pages/generated/scaladoc_links.md")
val snapshot = version.value
val markdown = Releases.generateMarkdown(streams.value.log)(snapshot)
Files.createDirectories(outputFile.toPath.getParent)
val writer = new PrintWriter(outputFile)
writer.write(s"""|<!-- Automatically generated by build.sbt 'generateScalaDocLinks' task -->
|$markdown""".stripMargin)
writer.close()
}
)