Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mill support for Chisel3 #1035

Merged
merged 22 commits into from Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a295a6d
Fix bug in VerilogMemDelays (#795)
jackkoenig Apr 26, 2018
037e748
Add support for mill.
ucbjrl May 17, 2018
d608629
Use patched version of mill pending release update.
ucbjrl May 17, 2018
52e1045
Distinguish tags and branches.
ucbjrl May 17, 2018
9c9199a
Taylor mill environment for firrtl-interpreter.
ucbjrl May 18, 2018
11a9ae1
Merge remote-tracking branch 'firrtl-interpreter-mill/mill' into mill
ucbjrl Jun 13, 2018
0035d3f
Full working version, but still some issues.
ucbjrl Jun 15, 2018
91520cf
Cleanup/fixup/reorg
ucbjrl Jun 15, 2018
d620062
Merge branch 'master' into mill
ucbjrl Jun 27, 2018
95281e0
Merge branch 'master' into mill
ucbjrl Jul 6, 2018
3b4b981
Bump downloaded mill version.
ucbjrl Jul 6, 2018
e444c78
Changed default version to 2.12.4 in build.sc
jackkoenig Oct 5, 2018
a956014
Move coreMacros and chiselFrontend mill modules into larger build
jackkoenig Oct 5, 2018
c297368
Remove no longer useful CrossUnRootedSbtModule
jackkoenig Oct 5, 2018
cf8e5f2
Support firrtl as either an ivy and a module dependency
jackkoenig Oct 5, 2018
b360133
Update to same Makefile mill support as FIRRTL
jackkoenig Oct 8, 2018
e15385e
Merge pull request #905 from freechipsproject/mill-ivy-or-module-dep
jackkoenig Oct 10, 2018
7d33781
Merge branch 'master' into mill
ucbjrl Oct 31, 2018
cab2d76
Make it work with generic mill
jackkoenig Feb 1, 2019
86baa35
Update to mill 0.3.5
edwardcwang Feb 2, 2019
8182e77
Merge branch 'master' into mill
ucbjrl Mar 18, 2019
916d444
Update fetch to use official mill-0.3.5; use same Scala version as sbt.
ucbjrl Mar 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
94 changes: 94 additions & 0 deletions CommonBuild.sc
@@ -0,0 +1,94 @@
import ammonite.ops._
import mill._
import mill.scalalib._

def scalacOptionsVersion(scalaVersion: String): Seq[String] = {
Seq() ++ {
// If we're building with Scala > 2.11, enable the compile option
// switch to support our anonymous Bundle definitions:
// https://github.com/scala/bug/issues/10047
if (scalaVersion.startsWith("2.11.")) {
Seq()
} else {
Seq(
"-Xsource:2.11",
"-Ywarn-unused:imports",
"-Ywarn-unused:locals"
)
}
}
}

def javacOptionsVersion(scalaVersion: String): Seq[String] = {
Seq() ++ {
// Scala 2.12 requires Java 8. We continue to generate
// Java 7 compatible code for Scala 2.11
// for compatibility with old clients.
if (scalaVersion.startsWith("2.11.")) {
Seq("-source", "1.7", "-target", "1.7")
} else {
Seq("-source", "1.8", "-target", "1.8")
}
}
}

// Define our own BuildInfo since mill doesn't currently have one.
trait BuildInfo extends ScalaModule { outer =>

def buildInfoObjectName: String = "BuildInfo"

def buildInfoMembers: T[Map[String, String]] = T {
Map.empty[String, String]
}

private def generateBuildInfo(outputPath: Path, members: Map[String, String]) = {
val outputFile = outputPath / "BuildInfo.scala"
val packageName = members.getOrElse("buildInfoPackage", "")
val packageDef = if (packageName != "") {
s"package ${packageName}"
} else {
""
}
val internalMembers =
members
.map {
case (name, value) => s""" val ${name}: String = "${value}""""
}
.mkString("\n")
write(outputFile,
s"""
|${packageDef}
|case object ${buildInfoObjectName}{
|$internalMembers
| override val toString: String = {
| "buildInfoPackage: %s, version: %s, scalaVersion: %s" format (
| buildInfoPackage, version, scalaVersion
| )
| }
|}
""".stripMargin)
outputPath
}

override def generatedSources = T {
super.generatedSources() :+ PathRef(generateBuildInfo(T.ctx().dest, buildInfoMembers()))
}
}

// Define some file filters to exclude unwanted files from created jars.
type JarFileFilter = (Path, RelPath) => Boolean
// Exclude any `.DS_Store` files
val noDS_StoreFiles: JarFileFilter = (p: Path, relPath: RelPath) => {
relPath.last != ".DS_Store"
}

// Exclude non-source files - accept all resource files, but only *.{java,scala} from source paths
val onlySourceFiles: JarFileFilter = (p: Path, relPath: RelPath) => {
p.last == "resources" || (relPath.ext == "scala" || relPath.ext == "java")
}

// Apply a sequence of file filters - only accept files which satisfy all filters.
// We expect this to be curried, the resulting file filter passed to createJar()
def forallFilters(fileFilters: Seq[JarFileFilter])(p: Path, relPath: RelPath): Boolean = {
fileFilters.forall(f => f(p, relPath))
}
78 changes: 47 additions & 31 deletions Makefile
@@ -1,31 +1,35 @@
# Retain all intermediate files.
.SECONDARY:

SBT ?= sbt
SBT_FLAGS ?= -Dsbt.log.noformat=true
MKDIR ?= mkdir -p
CURL ?= curl -L
MILL_BIN ?= $(HOME)/bin/mill
MILL ?= $(MILL_BIN) --color false
MILL_REMOTE_RELEASE ?= https://github.com/ucbjrl/mill/releases/download/v0.2.6-FDF/mill-0.2.6-FDF

# Fetch mill (if we don't have it).
$(MILL_BIN):
$(MKDIR) $(dir $@)
@echo $(CURL) --silent --output $@.curl --write-out "%{http_code}" $(MILL_REMOTE_RELEASE)
STATUSCODE=$(shell $(CURL) --silent --output $@.curl --write-out "%{http_code}" $(MILL_REMOTE_RELEASE)) && \
if test $$STATUSCODE -eq 200; then \
mv $@.curl $@ && chmod +x $@ ;\
else \
echo "Can't fetch $(MILL_REMOTE_RELEASE)" && cat $@.curl && echo ;\
false ;\
fi

mill-tools: $(MILL_BIN)

CHISEL_VERSION = $(shell "$(SBT)" $(SBT_FLAGS) "show version" | tail -n 1 | cut -d ' ' -f 2)

SRC_DIR ?= .
CHISEL_BIN ?= $(abspath $(SRC_DIR)/bin)
export CHISEL_BIN

#$(info Build Chisel $(CHISEL_VERSION))

# The targetDir will be rm -rf'ed when "make clean"
targetDir ?= ./generated
# The TEST_OUTPUT_DIR will be rm -rf'ed when "make clean"
TEST_OUTPUT_DIR ?= ./test-outputs
RM_DIRS := $(TEST_OUTPUT_DIR) test-reports $(targetDir)
#CLEAN_DIRS := doc

test_src_dir := src/test/scala/ChiselTests
test_results := $(filter-out main DirChange Pads SIntOps,$(notdir $(basename $(wildcard $(test_src_dir)/*.scala))))
c_resources_dir := src/main/resources

test_outs := $(addprefix $(targetDir)/, $(addsuffix .out, $(test_results)))
TEST_OUTPUT_DIR ?= ./test_run_dur
RM_DIRS := $(TEST_OUTPUT_DIR)

.PHONY: smoke publish-local pubishLocal check clean jenkins-build coverage scaladoc test checkstyle compile
.PHONY: smoke publish-local pubishLocal check clean jenkins-build coverage scaladoc test checkstyle compile \
mill.build mill.test mill.publishLocal mill.build.all mill.test.all mill.publishLocal.all mill-tools

default: publishLocal

Expand All @@ -38,8 +42,6 @@ publish-local publishLocal:
test:
$(SBT) $(SBT_FLAGS) test

check: test $(test_outs)

checkstyle:
$(SBT) $(SBT_FLAGS) scalastyle test:scalastyle

Expand Down Expand Up @@ -73,20 +75,34 @@ jenkins-build: clean
$(SBT) $(SBT_FLAGS) scalastyle coverage test
$(SBT) $(SBT_FLAGS) coverageReport

$(targetDir)/%.fir: $(test_src_dir)/%.scala
$(SBT) $(SBT_FLAGS) "test:runMain ChiselTests.MiniChisel $(notdir $(basename $<)) $(CHISEL_FLAGS)"
# Compile and package jar
mill.build: mill-tools
$(MILL) chisel3.jar

# Compile and test
mill.test: mill-tools
$(MILL) chisel3.test

# Build and publish jar
mill.publishLocal: mill-tools
$(MILL) chisel3.publishLocal

$(targetDir)/%.flo: $(targetDir)/%.fir
$(CHISEL_BIN)/fir2flo.sh $(targetDir)/$*
# Compile and package all jar
mill.build.all: mill-tools
$(MILL) chisel3[_].jar

$(targetDir)/%: $(targetDir)/%.flo $(targetDir)/emulator.h $(targetDir)/emulator_mod.h $(targetDir)/emulator_api.h
(cd $(targetDir); $(CHISEL_BIN)/flo2app.sh $*)
# Compile and test
mill.test.all: mill-tools
$(MILL) chisel3[_].test

$(targetDir)/%.h: $(c_resources_dir)/%.h
cp $< $@
# Build and publish jar
mill.publishLocal.all: mill-tools
$(MILL) chisel3[_].publishLocal

$(targetDir)/%.out: $(targetDir)/%
$(SBT) $(SBT_FLAGS) "test:runMain ChiselTests.MiniChisel $(notdir $(basename $<)) $(CHISEL_FLAGS) --test --targetDir $(targetDir)"
# Remove all generated code.
# Until "mill clean" makes it into a release.
mill.clean:
$(RM) -rf out

# The "last-resort" rule.
# We assume the target is something like "+clean".
Expand Down
12 changes: 12 additions & 0 deletions build.sbt
Expand Up @@ -125,6 +125,18 @@ lazy val coreMacros = (project in file("coreMacros")).
lazy val chiselFrontend = (project in file("chiselFrontend")).
settings(commonSettings: _*).
settings(publishArtifact := false).
settings(
scalacOptions := scalacOptions.value ++ Seq(
"-deprecation",
"-explaintypes",
"-feature",
"-language:reflectiveCalls",
"-unchecked",
"-Xcheckinit",
"-Xlint:infer-any"
// "-Xlint:missing-interpolator"
)
).
dependsOn(coreMacros)

// This will always be the root project, even if we are a sub-project.
Expand Down