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