From 164490c8fbf132ca65644d05d6ff8d0d7a3beb20 Mon Sep 17 00:00:00 2001 From: Adam Izraelevitz Date: Wed, 29 Jul 2020 20:48:31 -0700 Subject: Improved Chisel Naming via Compiler Plugins + Prefixing (#1448) Added prefixing and a compiler plugin to improve naming. Only works for Scala 2.12 and above. Co-authored-by: Jack Koenig --- build.sbt | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'build.sbt') diff --git a/build.sbt b/build.sbt index ea0c0a15..74406b2b 100644 --- a/build.sbt +++ b/build.sbt @@ -125,6 +125,54 @@ lazy val chiselSettings = Seq ( } ) +autoCompilerPlugins := true + +// Plugin must be fully cross-versioned (published for Scala minor version) +// The plugin only works in Scala 2.12+ +lazy val pluginScalaVersions = Seq( + "2.11.12", // Only to support chisel3 cross building for 2.11, plugin does nothing in 2.11 + // scalamacros paradise version used is not published for 2.12.0 and 2.12.1 + "2.12.2", + "2.12.3", + "2.12.4", + "2.12.5", + "2.12.6", + "2.12.7", + "2.12.8", + "2.12.9", + "2.12.10", + "2.12.11" +) + +lazy val plugin = (project in file("plugin")). + settings(name := "chisel3-plugin"). + settings(commonSettings: _*). + settings(publishSettings: _*). + settings( + libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value, + scalacOptions += "-Xfatal-warnings", + crossScalaVersions := pluginScalaVersions, + // Must be published for Scala minor version + crossVersion := CrossVersion.full, + crossTarget := { + // workaround for https://github.com/sbt/sbt/issues/5097 + target.value / s"scala-${scalaVersion.value}" + }, + // Only publish for Scala 2.12 + publish / skip := !scalaVersion.value.startsWith("2.12") + ) + +lazy val usePluginSettings = Seq( + scalacOptions in Compile ++= { + val jar = (plugin / Compile / Keys.`package`).value + val addPlugin = "-Xplugin:" + jar.getAbsolutePath + // add plugin timestamp to compiler options to trigger recompile of + // main after editing the plugin. (Otherwise a 'clean' is needed.) + val dummy = "-Jdummy=" + jar.lastModified + Seq(addPlugin, dummy) + } +) + lazy val macros = (project in file("macros")). settings(name := "chisel3-macros"). settings(commonSettings: _*). @@ -162,9 +210,10 @@ lazy val chisel = (project in file(".")). settings(commonSettings: _*). settings(chiselSettings: _*). settings(publishSettings: _*). + settings(usePluginSettings: _*). dependsOn(macros). dependsOn(core). - aggregate(macros, core). + aggregate(macros, core, plugin). settings( scalacOptions in Test ++= Seq("-language:reflectiveCalls"), scalacOptions in Compile in doc ++= Seq( -- cgit v1.2.3