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