This repository has been archived by the owner on Aug 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 178
/
Copy pathbuild.sc
155 lines (128 loc) · 4.39 KB
/
build.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// SPDX-License-Identifier: Apache-2.0
import mill._
import mill.scalalib._
import mill.scalalib.publish._
import mill.modules.Util
import $ivy.`com.lihaoyi::mill-contrib-buildinfo:$MILL_VERSION`
import mill.contrib.buildinfo.BuildInfo
object firrtl extends mill.Cross[firrtlCrossModule]("2.11.12", "2.12.12", "2.13.2")
class firrtlCrossModule(val crossScalaVersion: String) extends CrossSbtModule with PublishModule with BuildInfo {
override def millSourcePath = super.millSourcePath / os.up
// 2.12.12 -> Array("2", "12", "12") -> "12" -> 12
private def majorVersion = crossScalaVersion.split('.')(1).toInt
def publishVersion = "1.4-SNAPSHOT"
override def mainClass = T {
Some("firrtl.stage.FirrtlMain")
}
private def javacCrossOptions = majorVersion match {
case i if i < 12 => Seq("-source", "1.7", "-target", "1.7")
case _ => Seq("-source", "1.8", "-target", "1.8")
}
override def scalacOptions = T {
super.scalacOptions() ++ Seq(
"-deprecation",
"-unchecked",
"-Yrangepos" // required by SemanticDB compiler plugin
)
}
override def javacOptions = T {
super.javacOptions() ++ javacCrossOptions
}
override def ivyDeps = T {
super.ivyDeps() ++ Agg(
ivy"${scalaOrganization()}:scala-reflect:${scalaVersion()}",
ivy"com.github.scopt::scopt:3.7.1",
ivy"net.jcazevedo::moultingyaml:0.4.2",
ivy"org.json4s::json4s-native:3.6.9",
ivy"org.apache.commons:commons-text:1.8",
ivy"org.antlr:antlr4-runtime:$antlr4Version",
ivy"com.google.protobuf:protobuf-java:$protocVersion"
) ++ {
if (majorVersion > 12)
Agg(ivy"org.scala-lang.modules::scala-parallel-collections:0.2.0")
else
Agg()
}
}
object test extends Tests {
private def ivyCrossDeps = majorVersion match {
case i if i < 12 => Agg(ivy"junit:junit:4.12")
case _ => Agg()
}
override def ivyDeps = T {
Agg(
ivy"org.scalatest::scalatest:3.2.0",
ivy"org.scalatestplus::scalacheck-1-14:3.1.3.0"
) ++ ivyCrossDeps
}
def testFrameworks = T {
Seq("org.scalatest.tools.Framework")
}
// a sbt-like testOnly command.
// for example, mill -i "firrtl[2.12.12].test.testOnly" "firrtlTests.AsyncResetSpec"
def testOnly(args: String*) = T.command {
super.runMain("org.scalatest.run", args: _*)
}
}
override def buildInfoPackageName = Some("firrtl")
override def buildInfoMembers: T[Map[String, String]] = T {
Map(
"buildInfoPackage" -> artifactName(),
"version" -> publishVersion(),
"scalaVersion" -> scalaVersion()
)
}
override def generatedSources = T {
generatedAntlr4Source() ++ generatedProtoSources() :+ generatedBuildInfo()._2
}
/* antlr4 */
def antlr4Version = "4.7.1"
def antlrSource = T.source {
millSourcePath / "src" / "main" / "antlr4" / "FIRRTL.g4"
}
def downloadAntlr4Jar = T.persistent {
Util.download(s"https://www.antlr.org/download/antlr-$antlr4Version-complete.jar")
}
def generatedAntlr4Source = T.sources {
os.proc("java",
"-jar", downloadAntlr4Jar().path.toString,
"-o", T.ctx.dest.toString,
"-lib", antlrSource().path.toString,
"-package", "firrtl.antlr",
"-no-listener", "-visitor",
antlrSource().path.toString
).call()
T.ctx.dest
}
/* protoc */
def protocVersion = "3.5.1"
def protobufSource = T.source {
millSourcePath / "src" / "main" / "proto" / "firrtl.proto"
}
def downloadProtocJar = T.persistent {
Util.download(s"https://repo.maven.apache.org/maven2/com/github/os72/protoc-jar/$protocVersion/protoc-jar-$protocVersion.jar")
}
def generatedProtoSources = T.sources {
os.proc("java",
"-jar", downloadProtocJar().path.toString,
"-I", protobufSource().path / os.up,
s"--java_out=${T.ctx.dest.toString}",
protobufSource().path.toString()
).call()
T.ctx.dest / "firrtl"
}
def pomSettings = T {
PomSettings(
description = artifactName(),
organization = "edu.berkeley.cs",
url = "https://github.com/freechipsproject/firrtl",
licenses = Seq(License.`BSD-3-Clause`),
versionControl = VersionControl.github("freechipsproject", "firrtl"),
developers = Seq(
Developer("jackbackrack", "Jonathan Bachrach", "https://eecs.berkeley.edu/~jrb/")
)
)
}
// make mill publish sbt compatible package
override def artifactName = "firrtl"
}