xref: /XiangShan/build.sc (revision 51e45dbbf87325e45ff2af6ca86ed6c7eed04464)
1/***************************************************************************************
2* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
3* Copyright (c) 2020-2021 Peng Cheng Laboratory
4*
5* XiangShan is licensed under Mulan PSL v2.
6* You can use this software according to the terms and conditions of the Mulan PSL v2.
7* You may obtain a copy of Mulan PSL v2 at:
8*          http://license.coscl.org.cn/MulanPSL2
9*
10* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13*
14* See the Mulan PSL v2 for more details.
15***************************************************************************************/
16
17import mill._
18import scalalib._
19import $file.`rocket-chip`.common
20import $file.`rocket-chip`.cde.common
21import $file.`rocket-chip`.hardfloat.build
22import $file.huancun.common
23import $file.coupledL2.common
24
25val defaultScalaVersion = "2.13.10"
26
27def defaultVersions(chiselVersion: String) = Map(
28  "chisel" -> (chiselVersion match {
29    case "chisel"  => ivy"org.chipsalliance::chisel:6.0.0-M3"
30    case "chisel3" => ivy"edu.berkeley.cs::chisel3:3.6.0"
31  }),
32  "chisel-plugin" -> (chiselVersion match {
33    case "chisel"  => ivy"org.chipsalliance:::chisel-plugin:6.0.0-M3"
34    case "chisel3" => ivy"edu.berkeley.cs:::chisel3-plugin:3.6.0"
35  }),
36  "chiseltest" -> (chiselVersion match {
37    case "chisel"  => ivy"edu.berkeley.cs::chiseltest:5.0.2"
38    case "chisel3" => ivy"edu.berkeley.cs::chiseltest:0.6.2"
39  })
40)
41
42trait HasChisel extends SbtModule with Cross.Module[String] {
43  def chiselModule: Option[ScalaModule] = None
44
45  def chiselPluginJar: T[Option[PathRef]] = None
46
47  def chiselIvy: Option[Dep] = Some(defaultVersions(crossValue)("chisel"))
48
49  def chiselPluginIvy: Option[Dep] = Some(defaultVersions(crossValue)("chisel-plugin"))
50
51  override def scalaVersion = defaultScalaVersion
52
53  override def scalacOptions = super.scalacOptions() ++
54    Agg("-language:reflectiveCalls", "-Ymacro-annotations", "-Ytasty-reader")
55
56  override def ivyDeps = super.ivyDeps() ++ Agg(chiselIvy.get)
57
58  override def scalacPluginIvyDeps = super.scalacPluginIvyDeps() ++ Agg(chiselPluginIvy.get)
59}
60
61object rocketchip extends Cross[RocketChip]("chisel", "chisel3")
62
63trait 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(crossValue)
73
74  def cdeModule = cde
75
76  def mainargsIvy = ivy"com.lihaoyi::mainargs:0.5.4"
77
78  def json4sJacksonIvy = ivy"org.json4s::json4s-jackson:4.0.6"
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 extends Cross[Hardfloat](crossValue)
92
93  trait Hardfloat
94    extends millbuild.`rocket-chip`.hardfloat.common.HardfloatModule with HasChisel {
95
96    def scalaVersion: T[String] = T(defaultScalaVersion)
97
98    override def millSourcePath = os.pwd / "rocket-chip" / "hardfloat" / "hardfloat"
99
100  }
101
102  object cde extends CDE
103
104  trait CDE extends millbuild.`rocket-chip`.cde.common.CDEModule with ScalaModule {
105
106    def scalaVersion: T[String] = T(defaultScalaVersion)
107
108    override def millSourcePath = os.pwd / "rocket-chip" / "cde" / "cde"
109  }
110}
111
112object utility extends Cross[Utility]("chisel", "chisel3")
113trait Utility extends HasChisel {
114
115  override def millSourcePath = os.pwd / "utility"
116
117  override def moduleDeps = super.moduleDeps ++ Seq(
118    rocketchip(crossValue)
119  )
120
121}
122
123object huancun extends Cross[HuanCun]("chisel", "chisel3")
124trait HuanCun extends millbuild.huancun.common.HuanCunModule with HasChisel {
125
126  override def millSourcePath = os.pwd / "huancun"
127
128  def rocketModule: ScalaModule = rocketchip(crossValue)
129
130  def utilityModule: ScalaModule = utility(crossValue)
131
132}
133
134object coupledL2 extends Cross[CoupledL2]("chisel", "chisel3")
135trait CoupledL2 extends millbuild.coupledL2.common.CoupledL2Module with HasChisel {
136
137  override def millSourcePath = os.pwd / "coupledL2"
138
139  def rocketModule: ScalaModule = rocketchip(crossValue)
140
141  def utilityModule: ScalaModule = utility(crossValue)
142
143  def huancunModule: ScalaModule = huancun(crossValue)
144
145}
146
147object difftest extends Cross[Difftest]("chisel", "chisel3")
148trait Difftest extends HasChisel {
149
150  override def millSourcePath = os.pwd / "difftest"
151
152}
153
154object fudian extends Cross[FuDian]("chisel", "chisel3")
155trait FuDian extends HasChisel {
156
157  override def millSourcePath = os.pwd / "fudian"
158
159}
160
161// extends this trait to use XiangShan in other projects
162trait XiangShanModule extends ScalaModule {
163
164  def rocketModule: ScalaModule
165
166  def difftestModule: ScalaModule
167
168  def huancunModule: ScalaModule
169
170  def coupledL2Module: ScalaModule
171
172  def fudianModule: ScalaModule
173
174  def utilityModule: ScalaModule
175
176  override def moduleDeps = super.moduleDeps ++ Seq(
177    rocketModule,
178    difftestModule,
179    huancunModule,
180    coupledL2Module,
181    fudianModule,
182    utilityModule,
183  )
184
185}
186
187object xiangshan extends Cross[XiangShan]("chisel", "chisel3")
188trait XiangShan extends XiangShanModule with HasChisel {
189
190  override def millSourcePath = os.pwd
191
192  def rocketModule = rocketchip(crossValue)
193
194  def difftestModule = difftest(crossValue)
195
196  def huancunModule = huancun(crossValue)
197
198  def coupledL2Module = coupledL2(crossValue)
199
200  def fudianModule = fudian(crossValue)
201
202  def utilityModule = utility(crossValue)
203
204  override def forkArgs = Seq("-Xmx20G", "-Xss256m")
205
206  override def sources = T.sources {
207    super.sources() ++ Seq(PathRef(millSourcePath / s"src-${crossValue}" / "main" / "scala"))
208  }
209
210  object test extends SbtModuleTests with TestModule.ScalaTest {
211    override def forkArgs = Seq("-Xmx20G", "-Xss256m")
212
213    override def sources = T.sources {
214      super.sources() ++ Seq(PathRef(millSourcePath / s"src-${crossValue}" / "test" / "scala"))
215    }
216
217    override def ivyDeps = super.ivyDeps() ++ Agg(
218      defaultVersions(crossValue)("chiseltest")
219    )
220  }
221}
222