-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sc
221 lines (168 loc) · 6.58 KB
/
build.sc
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
import mill._
import mill.scalalib._
import mill.scalalib.publish._
import mill.scalalib.scalafmt._
import coursier.maven.MavenRepository
import $ivy.`com.lihaoyi::mill-contrib-buildinfo:$MILL_VERSION`
import mill.contrib.buildinfo.BuildInfo
object chisel3 extends mill.Cross[chisel3CrossModule]("2.13.10", "2.12.17")
// The following stanza is searched for and used when preparing releases.
// Please retain it.
// Provide a managed dependency on X if -DXVersion="" is supplied on the command line.
val defaultVersions = Map(
"firrtl" -> "1.6-SNAPSHOT",
)
def getVersion(dep: String, org: String = "edu.berkeley.cs") = {
val version = sys.env.getOrElse(dep + "Version", defaultVersions(dep))
ivy"$org::$dep:$version"
}
// Do not remove the above logic, it is needed by the release automation
object v {
val firrtl = getVersion("firrtl")
val chiseltest = ivy"edu.berkeley.cs::chiseltest:0.6-SNAPSHOT"
val scalatest = ivy"org.scalatest::scalatest:3.2.15"
val scalacheck = ivy"org.scalatestplus::scalacheck-1-14:3.2.2.0"
val osLib = ivy"com.lihaoyi::os-lib:0.8.1"
val upickle = ivy"com.lihaoyi::upickle:2.0.0"
val macroParadise = ivy"org.scalamacros:::paradise:2.1.1"
}
// Since chisel contains submodule core and macros, a CommonModule is needed
trait CommonModule extends CrossSbtModule with PublishModule with ScalafmtModule {
def firrtlModule: Option[PublishModule] = None
def firrtlIvyDeps = if (firrtlModule.isEmpty)
Agg(
v.firrtl
)
else Agg.empty[Dep]
def chiseltestModule: Option[PublishModule] = None
def chiseltestIvyDeps = if (chiseltestModule.isEmpty)
Agg(
v.chiseltest
)
else Agg.empty[Dep]
override def moduleDeps = super.moduleDeps ++ firrtlModule
override def ivyDeps = super.ivyDeps() ++ Agg(
v.osLib,
v.upickle
) ++ firrtlIvyDeps
def publishVersion = "3.6-SNAPSHOT"
// 2.12.10 -> Array("2", "12", "10") -> "12" -> 12
protected def majorVersion = crossScalaVersion.split('.')(1).toInt
override def repositories = super.repositories ++ Seq(
MavenRepository("https://oss.sonatype.org/content/repositories/snapshots"),
MavenRepository("https://oss.sonatype.org/content/repositories/releases")
)
override def scalacOptions = T {
super.scalacOptions() ++ Agg(
"-deprecation",
"-feature"
) ++ (if (majorVersion == 13) Agg("-Ymacro-annotations") else Agg.empty[String])
}
override def compileIvyDeps = if (majorVersion == 13) super.compileIvyDeps else Agg(v.macroParadise)
override def scalacPluginIvyDeps = if (majorVersion == 13) super.compileIvyDeps else Agg(v.macroParadise)
def pomSettings = PomSettings(
description = artifactName(),
organization = "edu.berkeley.cs",
url = "https://www.chisel-lang.org",
licenses = Seq(License.`Apache-2.0`),
versionControl = VersionControl.github("freechipsproject", "chisel3"),
developers = Seq(
Developer("jackbackrack", "Jonathan Bachrach", "https://eecs.berkeley.edu/~jrb/")
)
)
}
class chisel3CrossModule(val crossScalaVersion: String) extends CommonModule with BuildInfo {
m =>
/** Default behavior assumes `build.sc` in the upper path of `src`.
* This override makes `src` folder stay with `build.sc` in the same directory,
* If chisel3 is used as a sub-project, [[millSourcePath]] should be overridden to the folder where `src` located.
*/
override def millSourcePath = super.millSourcePath / os.up
override def mainClass = T {
Some("chisel3.stage.ChiselMain")
}
override def moduleDeps = super.moduleDeps ++ Seq(macros, core)
override def scalacPluginClasspath = T {
super.scalacPluginClasspath() ++ Agg(
plugin.jar()
)
}
override def scalacOptions = T {
super.scalacOptions() ++ Agg(s"-Xplugin:${plugin.jar().path}")
}
object stdlib extends CommonModule {
override def moduleDeps = super.moduleDeps ++ Agg(m)
override def millSourcePath = m.millSourcePath / "stdlib"
override def crossScalaVersion = m.crossScalaVersion
override def scalacPluginClasspath = T { m.scalacPluginClasspath() }
}
object test extends Tests with TestModule.ScalaTest with ScalafmtModule {
override def scalacPluginClasspath = T { m.scalacPluginClasspath() }
override def ivyDeps = m.ivyDeps() ++ Agg(
v.scalatest,
v.scalacheck
)
override def moduleDeps = super.moduleDeps
}
object `integration-tests` extends Tests with TestModule.ScalaTest with ScalafmtModule {
override def sources = T.sources(millSourcePath / "integration-tests" / "src" / "test" / "scala")
override def ivyDeps = m.ivyDeps() ++ Agg(
v.scalatest,
v.scalacheck
) ++ m.chiseltestIvyDeps
override def moduleDeps = super.moduleDeps ++ Seq(stdlib) ++ chiseltestModule
}
override def buildInfoPackageName = Some("chisel3")
override def buildInfoMembers = T {
Map(
"buildInfoPackage" -> artifactName(),
"version" -> publishVersion(),
"scalaVersion" -> scalaVersion()
)
}
object macros extends CommonModule {
/** millOuterCtx.segment.pathSegments didn't detect error here. */
override def millSourcePath = m.millSourcePath / "macros"
override def crossScalaVersion = m.crossScalaVersion
override def firrtlModule = m.firrtlModule
}
object core extends CommonModule {
/** millOuterCtx.segment.pathSegments didn't detect error here. */
override def millSourcePath = m.millSourcePath / "core"
override def crossScalaVersion = m.crossScalaVersion
override def moduleDeps = super.moduleDeps ++ Seq(macros)
override def firrtlModule = m.firrtlModule
def scalacOptions = T {
super.scalacOptions() ++ Seq(
"-deprecation",
"-explaintypes",
"-feature",
"-language:reflectiveCalls",
"-unchecked",
"-Xcheckinit",
"-Xlint:infer-any"
)
}
override def generatedSources = T {
Seq(generatedBuildInfo()._2)
}
}
object plugin extends CommonModule {
/** millOuterCtx.segment.pathSegments didn't detect error here. */
override def millSourcePath = m.millSourcePath / "plugin"
override def crossScalaVersion = m.crossScalaVersion
override def firrtlModule = m.firrtlModule
override def ivyDeps = Agg(
ivy"${scalaOrganization()}:scala-library:$crossScalaVersion"
) ++ (if (majorVersion == 13) Agg(ivy"${scalaOrganization()}:scala-compiler:$crossScalaVersion")
else Agg.empty[Dep])
def scalacOptions = T {
Seq(
"-Xfatal-warnings"
)
}
override def artifactName = "chisel3-plugin"
}
// make mill publish sbt compatible package
override def artifactName = "chisel3"
}