Skip to content

Commit

Permalink
finish mill build system.
Browse files Browse the repository at this point in the history
  • Loading branch information
sequencer committed Oct 28, 2020
1 parent a002166 commit 69e6315
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
out/
target/
project/target
docs/generated
Expand All @@ -10,4 +11,5 @@ docs-target/
.addons-dont-touch
/lib/
/test_lib/
/testbuild/
rocketchip.jar
2 changes: 1 addition & 1 deletion api-config-chipsalliance
62 changes: 62 additions & 0 deletions build.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import mill._
import mill.scalalib._
import mill.scalalib.publish._
import coursier.maven.MavenRepository
import $file.common
import $file.firrtl.build
import $file.chisel3.build
import $file.hardfloat.build
import $file.`api-config-chipsalliance`.`build-rules`.mill.build

object firrtlRocket extends firrtl.build.firrtlCrossModule("2.12.11") {
override def millSourcePath = os.pwd / "firrtl"
}

object chisel3Rocket extends chisel3.build.chisel3CrossModule("2.12.12") {
override def millSourcePath = os.pwd / "chisel3"

def firrtlModule: Option[PublishModule] = Some(firrtlRocket)
}

object configRocket extends `api-config-chipsalliance`.`build-rules`.mill.build.config with PublishModule {
override def millSourcePath = os.pwd / "api-config-chipsalliance" / "design" / "craft"

override def scalaVersion = T {
rocketchip.scalaVersion()
}

override def pomSettings = T {
rocketchip.pomSettings()
}

override def publishVersion = T {
rocketchip.publishVersion()
}
}

object hardfloatRocket extends hardfloat.build.hardfloat {
override def millSourcePath = os.pwd / "hardfloat"

override def scalaVersion = T {
rocketchip.scalaVersion()
}

def chisel3Module: Option[PublishModule] = Some(chisel3Rocket)
}

object rocketchip extends common.CommonRocketChip {
m =>
override def scalaVersion: T[String] = T {
"2.12.10"
}

def chisel3Module = Some(chisel3Rocket)

def hardfloatModule = hardfloatRocket

def configModule = configRocket

def scalacPluginClasspath = super.scalacPluginClasspath() ++ Agg(
chisel3Rocket.plugin.jar()
)
}
126 changes: 126 additions & 0 deletions common.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import mill._
import mill.scalalib._
import mill.scalalib.publish._
import coursier.maven.MavenRepository

val defaultVersions = Map(
"chisel3" -> "3.4.0",
"chisel3-plugin" -> "3.4.0"
)

def getVersion(dep: String, org: String = "edu.berkeley.cs", cross: Boolean = false) = {
val version = sys.env.getOrElse(dep + "Version", defaultVersions(dep))
if (cross)
ivy"$org:::$dep:$version"
else
ivy"$org::$dep:$version"
}

/** The reason to split build.sc to two file is
* [[CommonRocketChip]] doesn't need to import `$file.chisel3` and `$file.firrtl`.
*
* You can extends from [[CommonRocketChip]] to use rocket-chip as build-from-source dependency.
* When doing this, you may like to override `chisel3Module`, `hardfloatModule`, `configModule`,
* setting them to your favorite commit of those packages.
*
* If you don't override `chisel3Module`, which will default to be `None`,
* and mill will automatically use chisel3 from ivy.
*/
trait CommonRocketChip extends SbtModule with PublishModule {
m =>

object macros extends SbtModule with PublishModule {
override def scalaVersion = T {
m.scalaVersion()
}

override def ivyDeps = T {
m.ivyDeps()
}

override def pomSettings = T {
m.pomSettings()
}

override def publishVersion = T {
m.publishVersion()
}
}

object test extends Tests {
override def scalacPluginClasspath = m.scalacPluginClasspath

override def ivyDeps = m.ivyDeps() ++ Agg(
ivy"org.scalatest::scalatest:3.2.0"
)

def testFrameworks = T {
Seq("org.scalatest.tools.Framework")
}

// a sbt-like testOnly command.
// for example, mill -i "chisel3[2.12.12].test.testOnly" "chiselTests.BitwiseOpsSpec"
def testOnly(args: String*) = T.command {
super.runMain("org.scalatest.run", args: _*)
}
}

override def millSourcePath = super.millSourcePath / os.up

def chisel3Module: Option[PublishModule] = None

def hardfloatModule: PublishModule

def configModule: PublishModule

def chisel3IvyDeps = if (chisel3Module.isEmpty) Agg(
getVersion("chisel3")
) else Agg.empty[Dep]

override def mainClass = T {
Some("freechips.rocketchip.system.Generator")
}

override def moduleDeps = Seq(macros) ++ chisel3Module :+ hardfloatModule :+ configModule

override def scalacOptions = T {
Seq("-deprecation", "-unchecked", "-Xsource:2.11")
}

override def ivyDeps = T {
Agg(
ivy"${scalaOrganization()}:scala-reflect:${scalaVersion()}",
ivy"org.json4s::json4s-jackson:3.6.1",
ivy"org.scalatest::scalatest:3.2.0"
) ++ chisel3IvyDeps
}

private val macroParadise = ivy"org.scalamacros:::paradise:2.1.1"

private val chisel3Plugin = getVersion("chisel3-plugin")

override def repositories = super.repositories ++ Seq(
MavenRepository("https://oss.sonatype.org/content/repositories/snapshots"),
MavenRepository("https://oss.sonatype.org/content/repositories/releases")
)

override def compileIvyDeps = Agg(macroParadise)

override def scalacPluginIvyDeps = Agg(macroParadise) ++ (if(chisel3Module.isDefined) Agg() else Agg(chisel3Plugin))

def publishVersion = T {
"1.2-SNAPSHOT"
}

def pomSettings = T {
PomSettings(
description = artifactName(),
organization = "edu.berkeley.cs",
url = "https://github.com/chipsalliance/rocket-chip",
licenses = Seq(License.`Apache-2.0`, License.`BSD-3-Clause`),
versionControl = VersionControl.github("chipsalliance", "rocket-chip"),
developers = Seq.empty
)
}
override def artifactName = "rocketchip"
}
2 changes: 1 addition & 1 deletion hardfloat

0 comments on commit 69e6315

Please sign in to comment.