Skip to content

Commit 31ba852

Browse files
authored
Remove all panama related stuff (#5104)
Rework lit tests and add to CI.
1 parent 3355f26 commit 31ba852

31 files changed

+321
-4667
lines changed

.github/workflows/test.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,52 @@ jobs:
9191
- name: Test
9292
run: ./mill -j0 firrtl.cross[].test -oF + svsim.cross[].test -oF + chisel[_].test -oF
9393

94+
lit:
95+
name: Run lit tests
96+
runs-on: ${{ inputs.system }}
97+
98+
steps:
99+
- name: Checkout
100+
uses: actions/checkout@v5
101+
with:
102+
ref: ${{ inputs.ref }}
103+
- name: Setup Scala
104+
uses: VirtusLab/scala-cli-setup@77834b5926f3eb70869d8009530c65585f7a039b # v1.9.1
105+
with:
106+
jvm: adoptium:17
107+
- name: Install FileCheck
108+
run: |
109+
sudo apt update
110+
sudo apt install llvm-19-tools
111+
echo "/usr/lib/llvm-19/bin" >> $GITHUB_PATH
112+
- name: Install Lit
113+
run: |
114+
pip3 install --user lit
115+
PIP3_BIN_DIR="$(python3 -m site --user-base)/bin"
116+
echo "$PIP3_BIN_DIR" >> $GITHUB_PATH
117+
- name: Install CIRCT
118+
id: install-circt
119+
if: ${{ inputs.circt }}
120+
uses: circt/install-circt@3f8dda6e1c1965537b5801a43c81c287bac4eae4 # v1.1.1
121+
with:
122+
version: ${{ inputs.circt }}
123+
github-token: ${{ github.token }}
124+
# TODO have install-circt do this
125+
- name: Set CHISEL_FIRTOOL_PATH
126+
if: steps.install-circt.outcome == 'success'
127+
run: |
128+
dir=$(dirname $(which firtool))
129+
echo "CHISEL_FIRTOOL_PATH=$dir" >> "$GITHUB_ENV"
130+
- name: Print firtool version
131+
if: steps.install-circt.outcome == 'success'
132+
run: |
133+
echo "The CIRCT version used is:" >> $GITHUB_STEP_SUMMARY
134+
echo \`\`\` >> $GITHUB_STEP_SUMMARY
135+
$CHISEL_FIRTOOL_PATH/firtool -version >> $GITHUB_STEP_SUMMARY
136+
echo \`\`\` >> $GITHUB_STEP_SUMMARY
137+
- name: Test
138+
run: ./mill lit.cross[].run
139+
94140
mima:
95141
name: binary compatibility checking
96142
runs-on: ${{ inputs.system }}

CONTRIBUTING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ To switch the JDK in your shell to the latest patch release of Temurin Java 11:
4444
eval $(cs java --jvm temurin:11 --env)
4545
```
4646

47+
LLVM lit can be installed with pip3 (you may need to update your `PATH` environment variable to include the install directory)
48+
```sh
49+
pip3 install lit
50+
```
51+
52+
LLVM FileCheck can be installed by compiling LLVM or CIRCT from source, or from Jack's pre-built binaries at https://github.com/jackkoenig/filecheck.
53+
4754
### Useful commands
4855

4956
Mill's `resolve` command plus the wildcard `_` are useful for discovering available projects, tasks, and commands.
@@ -89,6 +96,20 @@ Chisel uses ScalaTest so you can run individual tests using standard ScalaTest c
8996
./mill chisel[].test.testOnly chiselTests.VecLiteralSpec -- -z "lits must fit in vec element width"
9097
```
9198

99+
### lit + FileCheck Tests
100+
101+
Some of our tests use LLVM's [lit](https://llvm.org/docs/CommandGuide/lit.html) and [FileCheck](https://llvm.org/docs/CommandGuide/FileCheck.html).
102+
103+
These tests are also run with mill:
104+
```sh
105+
./mill lit.cross[].run
106+
```
107+
108+
If a test fails, you can use `--filter` to select for the failing test and use `-v` to show the debug information from `FileCheck`:
109+
```sh
110+
./mill lit.cross[].run --filter Module -v
111+
```
112+
92113
### Formatting
93114

94115
Chisel enforces formatting using Scalafmt.

build.mill

Lines changed: 45 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -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

circtpanamabinding/includeConstants.txt

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)