forked from chipsalliance/chisel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.mill
279 lines (224 loc) · 9.3 KB
/
build.mill
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
package build
import mill._
import mill.scalalib._
import mill.scalalib.scalafmt._
import $packages._
import build._
object v extends Module {
val javaVersion = {
val rawVersion = sys.props("java.specification.version")
// Older versions of Java started with 1., e.g. 1.8 == 8
rawVersion.stripPrefix("1.").toInt
}
val firtoolVersion = {
val j = _root_.upickle.default.read[Map[String, String]](os.read(millSourcePath / os.up / "etc" / "circt.json"))
j("version").stripPrefix("firtool-")
}
// Java 21 only works with 2.13.11+, but Project Panama uses Java 21
// Only publish plugin for 2.13.11+ when using Java > 11, but still
// publish all versions when Java version <= 11.
val pluginScalaCrossVersions = {
val latest213 = 15
val java21Min213 = 11
val minVersion = if (javaVersion > 11) java21Min213 else 0
val versions = minVersion to latest213
val versionSeq = versions.map(v => s"2.13.$v").toSeq
versionSeq ++ Seq("3.3.4")
}
val scalaCrossVersions = Seq(
"2.13.15",
"3.3.4"
)
def isScala3(ver: String): Boolean = ver.startsWith("3.")
def buildUnits(): Seq[ScalaModule] = {
scalaCrossVersions.flatMap { ver =>
Seq(chisel(ver), stdlib.cross(ver), unipublish)
} ++ scalaCrossVersions.filterNot(isScala3(_)).flatMap { ver2 =>
Seq(
chisel(ver2).test,
firrtl.cross(ver2).test,
svsim.cross(ver2).test,
`integration-tests`.cross(ver2).test,
lit.utility.cross(ver2),
panamaconverter.cross(ver2),
panamalib.cross(ver2),
panamaom.cross(ver2)
)
}
}
val scalaVersion = scalaCrossVersions.head
val jmhVersion = "1.37"
val osLib = ivy"com.lihaoyi::os-lib:0.10.0"
val upickle = ivy"com.lihaoyi::upickle:3.3.1"
val firtoolResolver = ivy"org.chipsalliance::firtool-resolver:2.0.0"
val scalatest = ivy"org.scalatest::scalatest:3.2.19"
val scalacheck = ivy"org.scalatestplus::scalacheck-1-18:3.2.19.0"
val json4s = ivy"org.json4s::json4s-native:4.0.7"
val dataclass = ivy"io.github.alexarchambault::data-class:0.2.6"
val commonText = ivy"org.apache.commons:commons-text:1.12.0"
val scopt = ivy"com.github.scopt::scopt:4.1.0"
def scalaReflect(scalaVersion: String) = ivy"org.scala-lang:scala-reflect:$scalaVersion"
def scalaCompiler(scalaVersion: String) = ivy"org.scala-lang:scala-compiler:$scalaVersion"
def scalaLibrary(scalaVersion: String) = ivy"org.scala-lang:scala-library:$scalaVersion"
def circt(version: String, os: String, platform: String) =
s"https://github.com/llvm/circt/releases/download/firtool-${version}/circt-full-shared-${os}-${platform}.tar.gz"
val scala2WarnConf = 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",
"cat=deprecation&origin=chisel3\\.ltl.*:s",
// Deprecated for external users, will eventually be removed.
"cat=deprecation&msg=Looking up Modules is deprecated:s",
// Only for testing of deprecated APIs
"cat=deprecation&msg=Use of @instantiable on user-defined types is deprecated:s"
)
// ScalacOptions
val scala2CommonOptions = Seq(
"-deprecation",
"-feature",
"-unchecked",
"-Werror",
"-Ymacro-annotations",
"-explaintypes",
"-Xcheckinit",
"-Xlint:infer-any",
"-Xlint:missing-interpolator",
"-language:reflectiveCalls",
s"-Wconf:${scala2WarnConf.mkString(",")}"
)
}
def compileAll() = Task.Command {
Task.traverse(v.buildUnits())(_.compile)()
}
trait HasScala2MacroAnno extends CrossModuleBase {
override def scalacOptions = Task {
if (!v.isScala3(crossScalaVersion)) {
super.scalacOptions() ++ Agg("-Ymacro-annotations")
} else super.scalacOptions()
}
}
trait HasScala2Plugin extends CrossModuleBase {
import build_.plugin.Plugin
def pluginModule: Plugin
override def scalacOptions = Task {
if (!v.isScala3(crossScalaVersion)) {
super.scalacOptions() ++ Agg(s"-Xplugin:${pluginModule.jar().path}")
} else super.scalacOptions()
}
override def scalacPluginClasspath = Task {
if (!v.isScala3(crossScalaVersion)) {
super.scalacPluginClasspath() ++ Agg(pluginModule.jar())
} else super.scalacPluginClasspath()
}
}
trait HasJextractGeneratedSources extends JavaModule {
def jextractBinary: T[os.Path]
def includePaths: T[Seq[PathRef]]
def libraryPaths: T[Seq[PathRef]]
def header: T[PathRef]
def includeFunctions: T[Seq[String]]
def includeConstants: T[Seq[String]]
def includeStructs: T[Seq[String]]
def includeTypedefs: T[Seq[String]]
def includeUnions: T[Seq[String]]
def includeVars: T[Seq[String]]
def linkLibraries: T[Seq[String]]
def target: T[String]
def headerClassName: T[String]
def dumpAllIncludes = Task {
val f = os.temp()
os.proc(
Seq(jextractBinary().toString, header().path.toString)
++ includePaths().flatMap(p => Seq("-I", p.path.toString))
++ Seq("--dump-includes", f.toString)
).call()
os.read.lines(f).filter(s => s.nonEmpty && !s.startsWith("#"))
}
override def generatedSources: T[Seq[PathRef]] = Task {
super.generatedSources() ++ {
// @formatter:off
os.proc(
Seq(jextractBinary().toString, header().path.toString)
++ includePaths().flatMap(p => Seq("-I", p.path.toString))
++ Seq(
"-t", target(),
"--header-class-name", headerClassName(),
"--source",
"--output", Task.dest.toString
) ++ includeFunctions().flatMap(f => Seq("--include-function", f)) ++
includeConstants().flatMap(f => Seq("--include-constant", f)) ++
includeStructs().flatMap(f => Seq("--include-struct", f)) ++
includeTypedefs().flatMap(f => Seq("--include-typedef", f)) ++
includeUnions().flatMap(f => Seq("--include-union", f)) ++
includeVars().flatMap(f => Seq("--include-var", f)) ++
linkLibraries().flatMap(l => Seq("-l", l))
).call(Task.dest)
// @formatter:on
Seq(PathRef(Task.dest))
}
}
override def javacOptions = Task(super.javacOptions() ++ Seq("--enable-preview", "--release", "21"))
}
trait HasCIRCTPanamaBindingModule extends JavaModule {
import build_.circtpanamabinding.CIRCTPanamaBinding
def circtPanamaBindingModule: CIRCTPanamaBinding
override def moduleDeps = super.moduleDeps ++ Some(circtPanamaBindingModule)
//
override def javacOptions = Task(super.javacOptions() ++ Seq("--enable-preview", "--release", "21"))
override def forkArgs: T[Seq[String]] = Task(
super.forkArgs() ++ Seq("--enable-native-access=ALL-UNNAMED", "--enable-preview")
++ circtPanamaBindingModule
.libraryPaths()
.map(p => s"-Djava.library.path=${p.path}")
)
}
trait HasPanamaLibModule extends ScalaModule with HasCIRCTPanamaBindingModule {
import build_.panamalib.PanamaLib
def panamaLibModule: PanamaLib
def circtPanamaBindingModule = panamaLibModule.circtPanamaBindingModule
override def moduleDeps = super.moduleDeps ++ Some(panamaLibModule)
}
trait HasPanamaOMModule extends ScalaModule with HasCIRCTPanamaBindingModule {
import build_.panamaom.PanamaOM
def panamaOMModule: PanamaOM
def circtPanamaBindingModule = panamaOMModule.circtPanamaBindingModule
override def moduleDeps = super.moduleDeps ++ Some(panamaOMModule)
}
trait HasPanamaConverterModule extends ScalaModule with HasCIRCTPanamaBindingModule {
import build_.panamaconverter.PanamaConverter
def panamaConverterModule: PanamaConverter
def circtPanamaBindingModule = panamaConverterModule.circtPanamaBindingModule
override def moduleDeps = super.moduleDeps ++ Some(panamaConverterModule)
}
// TODO: move chisel src to subfolder once we have dropped sbt flow
object chisel extends Cross[Chisel](v.scalaCrossVersions)
trait Chisel extends CrossSbtModule with HasScala2MacroAnno with HasScala2Plugin with ScalafmtModule {
override def millSourcePath = super.millSourcePath / os.up
def svsimModule = svsim.cross(crossScalaVersion)
def coreModule = core.cross(crossScalaVersion)
def pluginModule = plugin.cross()
override def scalacOptions = Task {
if (v.isScala3(crossScalaVersion)) {
Seq.empty[String]
} else {
super.scalacOptions() ++ v.scala2CommonOptions
}
}
override def moduleDeps = super.moduleDeps ++ Seq(coreModule, svsimModule)
object test extends SbtTests with TestModule.ScalaTest with ScalafmtModule {
def ivyDeps = Agg(v.scalatest, v.scalacheck)
// TODO: enable sandbox and run tests in parallel
override def testSandboxWorkingDir = false
// Suppress Scala 3 behavior requiring explicit types on implicit definitions
// Note this must come before the -Wconf is warningSuppression
override def scalacOptions = Task { super.scalacOptions() :+ "-Wconf:cat=other-implicit-type:s" }
}
}
object unipublish extends release.Unipublish