@@ -28,7 +28,7 @@ object v extends Module {
2828 val j = _root_.upickle.default.read[Map[String, String]](circtJson)
2929 j("version").stripPrefix("firtool-")
3030 }
31- // Java 21 only works with 2.13.11+, but Project Panama uses Java 21
31+ // Java 21+ requires Scala 2.13.11+.
3232 // Only publish plugin for 2.13.11+ when using Java > 11, but still
3333 // publish all versions when Java version <= 11.
3434 val pluginScalaCrossVersions = {
@@ -60,10 +60,7 @@ object v extends Module {
6060 } ++ scalaCrossVersions.filterNot(isScala3(_)).flatMap { ver2 =>
6161 Seq(
6262 `integration-tests`.cross(ver2).test,
63- lit.utility.cross(ver2),
64- panamaconverter.cross(ver2),
65- panamalib.cross(ver2),
66- panamaom.cross(ver2)
63+ lit.utility.cross(ver2)
6764 )
6865 }
6966 }
@@ -217,112 +214,57 @@ trait HasCommonOptions extends CrossModuleBase {
217214 }
218215}
219216
220- trait HasJextractGeneratedSources extends JavaModule {
217+ // Build rules for managing circt artifacts
218+ object circt extends Module {
219+ val architecture = System.getProperty("os.arch")
220+ val operationSystem = System.getProperty("os.name")
221221
222- def jextractBinary: T[os.Path]
222+ val mac = operationSystem.toLowerCase.startsWith("mac")
223+ val linux = operationSystem.toLowerCase.startsWith("linux")
224+ val windows = operationSystem.toLowerCase.startsWith("win")
225+ val amd64 = architecture.matches("^(x8664|amd64|ia32e|em64t|x64|x86_64)$")
226+ val aarch64 = architecture.equals("aarch64") | architecture.startsWith("armv8")
223227
224- def includePaths: T[Seq[PathRef]]
225-
226- def libraryPaths: T[Seq[PathRef]]
227-
228- def header: T[PathRef]
229-
230- def includeFunctions: T[Seq[String]]
231-
232- def includeConstants: T[Seq[String]]
233-
234- def includeStructs: T[Seq[String]]
235-
236- def includeTypedefs: T[Seq[String]]
237-
238- def includeUnions: T[Seq[String]]
239-
240- def includeVars: T[Seq[String]]
241-
242- def linkLibraries: T[Seq[String]]
243-
244- def target: T[String]
245-
246- def headerClassName: T[String]
228+ def circt(version: String, os: String, platform: String) =
229+ s"https://github.com/llvm/circt/releases/download/firtool-${version}/circt-full-shared-${os}-${platform}.tar.gz"
247230
248- def dumpAllIncludes = Task {
249- val f = os.temp()
250- os.proc(
251- Seq(jextractBinary().toString, header().path.toString)
252- ++ includePaths().flatMap(p => Seq("-I", p.path.toString))
253- ++ Seq("--dump-includes", f.toString)
254- ).call()
255- os.read.lines(f).filter(s => s.nonEmpty && !s.startsWith("#"))
231+ // Copy-pasted from Mill 0.12.14 and updated to Mill 1.0.0 (MIT License)
232+ def download(url: String, dest: os.RelPath)(implicit ctx: mill.api.TaskCtx.Dest): PathRef = {
233+ val out = ctx.dest / dest
234+ val website = new java.net.URI(url).toURL
235+ val websiteInputStream = website.openStream
236+ try {
237+ java.nio.file.Files.copy(websiteInputStream, out.toNIO)
238+ PathRef(out)
239+ } finally {
240+ websiteInputStream.close()
241+ }
256242 }
257243
258- override def generatedSources: T[Seq[PathRef]] = Task {
259- super.generatedSources() ++ {
260- // @formatter:off
261- os.proc(
262- Seq(jextractBinary().toString, header().path.toString)
263- ++ includePaths().flatMap(p => Seq("-I", p.path.toString))
264- ++ Seq(
265- "-t", target(),
266- "--header-class-name", headerClassName(),
267- "--source",
268- "--output", Task.dest.toString
269- ) ++ includeFunctions().flatMap(f => Seq("--include-function", f)) ++
270- includeConstants().flatMap(f => Seq("--include-constant", f)) ++
271- includeStructs().flatMap(f => Seq("--include-struct", f)) ++
272- includeTypedefs().flatMap(f => Seq("--include-typedef", f)) ++
273- includeUnions().flatMap(f => Seq("--include-union", f)) ++
274- includeVars().flatMap(f => Seq("--include-var", f)) ++
275- linkLibraries().flatMap(l => Seq("-l", l))
276- ).call(Task.dest)
277- // @formatter:on
278- Seq(PathRef(Task.dest))
244+ // use Task(persistent = true) to avoid download repeatedly
245+ def installDir: T[os.Path] = Task(persistent = true) {
246+ Task.ctx().env.get("CIRCT_INSTALL_PATH") match {
247+ case Some(dir) => os.Path(dir)
248+ case None =>
249+ Task.ctx().log.info("Use CIRCT_INSTALL_PATH to vendor circt")
250+ val tarPath = Task.dest / "circt.tar.gz"
251+ if (!os.exists(tarPath)) {
252+ val url = circt(
253+ v.firtoolVersion,
254+ if (linux) "linux" else if (mac) "macos" else throw new Exception("unsupported os"),
255+ // circt does not yet publish for macos-aarch64, use x64 for now
256+ if (amd64 || mac) "x64" else throw new Exception("unsupported arch")
257+ )
258+ Task.ctx().log.info(s"Downloading circt from ${url}")
259+ download(url, os.rel / "circt.tar.gz")
260+ Task.ctx().log.info(s"Download Successfully")
261+ }
262+ os.proc("tar", "xvf", tarPath, "--strip-components=1").call(Task.dest)
263+ Task.dest
279264 }
280265 }
281266
282- override def javacOptions = Task(super.javacOptions() ++ Seq("--enable-preview", "--release", "21"))
283- }
284-
285- trait HasCIRCTPanamaBindingModule extends JavaModule {
286- import build_.circtpanamabinding.CIRCTPanamaBinding
287- def circtPanamaBindingModule: CIRCTPanamaBinding
288-
289- override def moduleDeps = super.moduleDeps ++ Some(circtPanamaBindingModule)
290- //
291- override def javacOptions = Task(super.javacOptions() ++ Seq("--enable-preview", "--release", "21"))
292-
293- override def forkArgs: T[Seq[String]] = Task(
294- super.forkArgs() ++ Seq("--enable-native-access=ALL-UNNAMED", "--enable-preview")
295- ++ circtPanamaBindingModule
296- .libraryPaths()
297- .map(p => s"-Djava.library.path=${p.path}")
298- )
299- }
300-
301- trait HasPanamaLibModule extends ScalaModule with HasCIRCTPanamaBindingModule {
302- import build_.panamalib.PanamaLib
303- def panamaLibModule: PanamaLib
304-
305- def circtPanamaBindingModule = panamaLibModule.circtPanamaBindingModule
306-
307- override def moduleDeps = super.moduleDeps ++ Some(panamaLibModule)
308- }
309-
310- trait HasPanamaOMModule extends ScalaModule with HasCIRCTPanamaBindingModule {
311- import build_.panamaom.PanamaOM
312- def panamaOMModule: PanamaOM
313-
314- def circtPanamaBindingModule = panamaOMModule.circtPanamaBindingModule
315-
316- override def moduleDeps = super.moduleDeps ++ Some(panamaOMModule)
317- }
318-
319- trait HasPanamaConverterModule extends ScalaModule with HasCIRCTPanamaBindingModule {
320- import build_.panamaconverter.PanamaConverter
321- def panamaConverterModule: PanamaConverter
322-
323- def circtPanamaBindingModule = panamaConverterModule.circtPanamaBindingModule
324-
325- override def moduleDeps = super.moduleDeps ++ Some(panamaConverterModule)
267+ def binDir = Task(installDir() / "bin")
326268}
327269
328270// TODO: move chisel src to subfolder once we have dropped sbt flow
0 commit comments