xref: /XiangShan/build.sc (revision 5c06072729ebf9577a23fe84f4eb39de6932028f)
1/***************************************************************************************
2* Copyright (c) 2024 Beijing Institute of Open Source Chip (BOSC)
3* Copyright (c) 2020-2024 Institute of Computing Technology, Chinese Academy of Sciences
4* Copyright (c) 2020-2021 Peng Cheng Laboratory
5*
6* XiangShan is licensed under Mulan PSL v2.
7* You can use this software according to the terms and conditions of the Mulan PSL v2.
8* You may obtain a copy of Mulan PSL v2 at:
9*          http://license.coscl.org.cn/MulanPSL2
10*
11* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
12* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
13* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
14*
15* See the Mulan PSL v2 for more details.
16***************************************************************************************/
17
18import mill._
19import scalalib._
20import $file.`rocket-chip`.common
21import $file.`rocket-chip`.cde.common
22import $file.`rocket-chip`.hardfloat.build
23import $file.huancun.common
24import $file.coupledL2.common
25import $file.openLLC.common
26
27/* for publishVersion */
28import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0`
29import de.tobiasroeser.mill.vcs.version.VcsVersion
30import java.time.LocalDateTime
31import java.time.format.DateTimeFormatter
32import java.util.Locale
33import scala.util.matching.Regex
34
35val defaultScalaVersion = "2.13.14"
36
37def defaultVersions = Map(
38  "chisel"        -> ivy"org.chipsalliance::chisel:6.5.0",
39  "chisel-plugin" -> ivy"org.chipsalliance:::chisel-plugin:6.5.0",
40  "chiseltest"    -> ivy"edu.berkeley.cs::chiseltest:6.0.0"
41)
42
43trait HasChisel extends SbtModule {
44  def chiselModule: Option[ScalaModule] = None
45
46  def chiselPluginJar: T[Option[PathRef]] = None
47
48  def chiselIvy: Option[Dep] = Some(defaultVersions("chisel"))
49
50  def chiselPluginIvy: Option[Dep] = Some(defaultVersions("chisel-plugin"))
51
52  override def scalaVersion = defaultScalaVersion
53
54  override def scalacOptions = super.scalacOptions() ++
55    Agg("-language:reflectiveCalls", "-Ymacro-annotations", "-Ytasty-reader")
56
57  override def ivyDeps = super.ivyDeps() ++ Agg(chiselIvy.get)
58
59  override def scalacPluginIvyDeps = super.scalacPluginIvyDeps() ++ Agg(chiselPluginIvy.get)
60}
61
62object rocketchip
63  extends millbuild.`rocket-chip`.common.RocketChipModule
64    with HasChisel {
65  def scalaVersion: T[String] = T(defaultScalaVersion)
66
67  override def millSourcePath = os.pwd / "rocket-chip"
68
69  def macrosModule = macros
70
71  def hardfloatModule = hardfloat
72
73  def cdeModule = cde
74
75  def mainargsIvy = ivy"com.lihaoyi::mainargs:0.7.0"
76
77  def json4sJacksonIvy = ivy"org.json4s::json4s-jackson:4.0.7"
78
79  object macros extends Macros
80
81  trait Macros
82    extends millbuild.`rocket-chip`.common.MacrosModule
83      with SbtModule {
84
85    def scalaVersion: T[String] = T(defaultScalaVersion)
86
87    def scalaReflectIvy = ivy"org.scala-lang:scala-reflect:${defaultScalaVersion}"
88  }
89
90  object hardfloat
91    extends millbuild.`rocket-chip`.hardfloat.common.HardfloatModule with HasChisel {
92
93    def scalaVersion: T[String] = T(defaultScalaVersion)
94
95    override def millSourcePath = os.pwd / "rocket-chip" / "hardfloat" / "hardfloat"
96
97  }
98
99  object cde
100    extends millbuild.`rocket-chip`.cde.common.CDEModule with ScalaModule {
101
102    def scalaVersion: T[String] = T(defaultScalaVersion)
103
104    override def millSourcePath = os.pwd / "rocket-chip" / "cde" / "cde"
105  }
106}
107
108object utility extends HasChisel {
109
110  override def millSourcePath = os.pwd / "utility"
111
112  override def moduleDeps = super.moduleDeps ++ Seq(
113    rocketchip
114  )
115
116}
117
118object yunsuan extends HasChisel {
119
120  override def millSourcePath = os.pwd / "yunsuan"
121
122}
123
124object huancun extends millbuild.huancun.common.HuanCunModule with HasChisel {
125
126  override def millSourcePath = os.pwd / "huancun"
127
128  def rocketModule: ScalaModule = rocketchip
129
130  def utilityModule: ScalaModule = utility
131
132}
133
134object coupledL2 extends millbuild.coupledL2.common.CoupledL2Module with HasChisel {
135
136  override def millSourcePath = os.pwd / "coupledL2"
137
138  def rocketModule: ScalaModule = rocketchip
139
140  def utilityModule: ScalaModule = utility
141
142  def huancunModule: ScalaModule = huancun
143
144}
145
146object openNCB extends SbtModule with HasChisel {
147
148  override def millSourcePath = os.pwd / "openLLC" / "openNCB"
149
150  override def moduleDeps = super.moduleDeps ++ Seq(
151    rocketchip
152  )
153
154}
155
156object openLLC extends millbuild.openLLC.common.OpenLLCModule with HasChisel {
157
158  override def millSourcePath = os.pwd / "openLLC"
159
160  def coupledL2Module: ScalaModule = coupledL2
161
162  def rocketModule: ScalaModule = rocketchip
163
164  def utilityModule: ScalaModule = utility
165
166  def openNCBModule: ScalaModule = openNCB
167
168}
169
170object difftest extends HasChisel {
171
172  override def millSourcePath = os.pwd / "difftest"
173
174}
175
176object fudian extends HasChisel {
177
178  override def millSourcePath = os.pwd / "fudian"
179
180}
181
182object macros extends ScalaModule {
183
184  override def millSourcePath = os.pwd / "macros"
185
186  override def scalaVersion: T[String] = T(defaultScalaVersion)
187
188  override def ivyDeps = super.ivyDeps() ++ Agg(ivy"org.scala-lang:scala-reflect:${defaultScalaVersion}")
189
190  def scalaReflectIvy = ivy"org.scala-lang:scala-reflect:${defaultScalaVersion}"
191}
192
193// extends this trait to use XiangShan in other projects
194trait XiangShanModule extends ScalaModule {
195
196  def rocketModule: ScalaModule
197
198  def difftestModule: ScalaModule
199
200  def huancunModule: ScalaModule
201
202  def coupledL2Module: ScalaModule
203
204  def openLLCModule: ScalaModule
205
206  def fudianModule: ScalaModule
207
208  def utilityModule: ScalaModule
209
210  def yunsuanModule: ScalaModule
211
212  def macrosModule: ScalaModule
213
214  override def moduleDeps = super.moduleDeps ++ Seq(
215    rocketModule,
216    difftestModule,
217    huancunModule,
218    coupledL2Module,
219    openLLCModule,
220    yunsuanModule,
221    fudianModule,
222    utilityModule,
223    macrosModule,
224  )
225
226  val resourcesPATH = os.pwd.toString() + "/src/main/resources"
227  val envPATH = sys.env("PATH") + ":" + resourcesPATH
228
229  override def forkEnv = Map("PATH" -> envPATH)
230}
231
232object xiangshan extends XiangShanModule with HasChisel {
233
234  override def millSourcePath = os.pwd
235
236  def rocketModule = rocketchip
237
238  def difftestModule = difftest
239
240  def huancunModule = huancun
241
242  def coupledL2Module = coupledL2
243
244  def openLLCModule = openLLC
245
246  def fudianModule = fudian
247
248  def utilityModule = utility
249
250  def yunsuanModule = yunsuan
251
252  def macrosModule = macros
253
254  override def forkArgs = Seq("-Xmx40G", "-Xss256m")
255
256  override def ivyDeps = super.ivyDeps() ++ Agg(
257    defaultVersions("chiseltest"),
258  )
259
260  override def scalacOptions = super.scalacOptions() ++ Agg("-deprecation", "-feature")
261
262  def publishVersion: T[String] = VcsVersion.vcsState().format(
263    revHashDigits = 8,
264    dirtyHashDigits = 0,
265    commitCountPad = -1,
266    countSep = "",
267    tagModifier = (tag: String) => "[Rr]elease.*".r.findFirstMatchIn(tag) match {
268      case Some(_) => "Kunminghu-Release-" + LocalDateTime.now().format(
269                                 DateTimeFormatter.ofPattern("MMM-dd-yyyy").withLocale(new Locale("en")))
270      case None => "Kunminghu-dev"
271    },
272    /* add "username, buildhost, buildtime" for non-release version */
273    untaggedSuffix = " (%s@%s) # %s".format(
274      System.getProperty("user.name"),
275      java.net.InetAddress.getLocalHost().getHostName(),
276      LocalDateTime.now().format(DateTimeFormatter.ofPattern("MMM dd hh:mm:ss yyyy").withLocale(new Locale("en")))),
277  )
278
279  override def resources = T.sources {
280    os.write(T.dest / "publishVersion", publishVersion())
281    super.resources() ++ Seq(PathRef(T.dest))
282  }
283
284  object test extends SbtModuleTests with TestModule.ScalaTest {
285    override def forkArgs = Seq("-Xmx40G", "-Xss256m")
286
287    override def ivyDeps = super.ivyDeps() ++ Agg(
288      defaultVersions("chiseltest")
289    )
290
291    override def scalacOptions = super.scalacOptions() ++ Agg("-deprecation", "-feature")
292
293    val resourcesPATH = os.pwd.toString() + "/src/main/resources"
294    val envPATH = sys.env("PATH") + ":" + resourcesPATH
295
296    override def forkEnv = Map("PATH" -> envPATH)
297  }
298}
299