Skip to content

Commit 440eb14

Browse files
authored
Merge pull request #5 from chipsalliance/ci
[ci] add github ci
2 parents 6ea7e8a + 06b23a9 commit 440eb14

18 files changed

+372
-82
lines changed

.github/workflows/checkfmt.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Check the format of a PR
2+
on:
3+
pull_request:
4+
types:
5+
- opened
6+
- synchronize
7+
- reopened
8+
- ready_for_review
9+
- labeled
10+
env:
11+
USER: runner
12+
13+
# Cancel the current workflow when new commit pushed
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
20+
check-format:
21+
name: "Check format"
22+
runs-on: [self-hosted, linux, nixos]
23+
strategy:
24+
fail-fast: false
25+
defaults:
26+
run:
27+
working-directory: ./templates/chisel
28+
steps:
29+
- uses: actions/checkout@v4
30+
with:
31+
ref: ${{ github.event.pull_request.head.sha }}
32+
- name: "Check Scala format"
33+
continue-on-error: true
34+
run: |
35+
nix develop -c bash -c 'mill -i gcd.checkFormat && mill -i elaborator.checkFormat'
36+
- name: "Check Rust format"
37+
continue-on-error: true
38+
run: |
39+
cd gcdemu
40+
nix develop -c cargo fmt --check
41+
cd ..
42+
- name: "Check nix format"
43+
continue-on-error: true
44+
run: |
45+
nix fmt -- --check nix flake.nix
46+

.github/workflows/daily-bump.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Dependencies Bump
2+
on:
3+
schedule:
4+
# Run this job everyday at 5:30 AM UTC+8
5+
- cron: '30 21 * * *'
6+
7+
jobs:
8+
bump-deps:
9+
name: "Bump Chisel and CIRCT"
10+
if: ${{ !cancelled() }}
11+
runs-on: [self-hosted, linux, nixos]
12+
permissions:
13+
contents: write
14+
defaults:
15+
run:
16+
working-directory: ./templates/chisel
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
ref: master
22+
- name: Bump nixpkgs
23+
run: |
24+
nix flake update
25+
- name: Bump Chisel
26+
run: |
27+
cd nix/pkgs/dependencies
28+
nix run '.#nvfetcher' -- -f '^chisel$'
29+
- name: Bump all mill deps
30+
run: |
31+
oldHash=$(nix derivation show .#gcd.gcd-compiled.millDeps | jq -r 'to_entries[0].value.env.outputHash')
32+
nix build '.#gcd.gcd-compiled.millDeps' --rebuild > milldeps-log.txt 2>&1 || true
33+
newHash=$(cat milldeps-log.txt \
34+
| grep -P '^\s+got:\s+sha256-.*$' \
35+
| cut -d':' -f2 \
36+
| xargs)
37+
if [ -z "$newHash" ] || [ "$newHash" = "$oldHash" ]; then
38+
echo "Original build logs for debug: "
39+
cat milldeps-log.txt
40+
echo "Hash unchanged, exit"
41+
exit 0
42+
fi
43+
echo "Updating hash $oldHash to $newHash"
44+
sed -i "s|$oldHash|$newHash|" nix/gcd/gcd.nix
45+
- name: Commit changes
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.BIYUN_GITHUB_ACTION }}
48+
run: |
49+
git config user.name github-actions[bot]
50+
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
51+
52+
currentDate=$(date +%F)
53+
branch="dependencies-bumping-$currentDate"
54+
git checkout -b "$branch"
55+
56+
git add 'nix/pkgs/dependencies'
57+
git add 'flake.lock'
58+
59+
if ! git diff --quiet --cached --exit-code; then
60+
updatedFiles=$(git diff --cached --name-only)
61+
echo "File changed"
62+
git commit -m "[deps] Bump dependencies"
63+
git push origin "$branch" --force-with-lease
64+
nix run '.#gh' -- \
65+
pr create --title "Bump dependencies" --body "Updated: $updatedFiles"
66+
fi

.github/workflows/main.yml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Build and Run Simulation
2+
on:
3+
pull_request:
4+
types:
5+
- opened
6+
- synchronize
7+
- reopened
8+
- ready_for_review
9+
- labeled
10+
env:
11+
USER: runner
12+
13+
# Cancel the current workflow when new commit pushed
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
20+
build-simulators:
21+
name: "Build Simulators"
22+
runs-on: [self-hosted, linux, nixos, BIGRAM]
23+
strategy:
24+
fail-fast: false
25+
defaults:
26+
run:
27+
working-directory: ./templates/chisel
28+
steps:
29+
- uses: actions/checkout@v4
30+
with:
31+
ref: ${{ github.event.pull_request.head.sha }}
32+
- name: "Build vcs simulator"
33+
run: |
34+
nix build '.#gcd.vcs' --impure
35+
- name: "Build vcs simulator with trace"
36+
run: |
37+
nix build '.#gcd.vcs-trace' --impure
38+
- name: "Build verilator simulator"
39+
run: |
40+
nix build '.#gcd.verilated'
41+
- name: "Build verilator simulator with trace"
42+
run: |
43+
nix build '.#gcd.verilated-trace'
44+
45+
run-vcs:
46+
name: "Run VCS"
47+
strategy:
48+
fail-fast: false
49+
runs-on: [self-hosted, linux, nixos]
50+
defaults:
51+
run:
52+
working-directory: ./templates/chisel
53+
steps:
54+
- uses: actions/checkout@v4
55+
with:
56+
ref: ${{ github.event.pull_request.head.sha }}
57+
- name: "Run VCS"
58+
run: |
59+
nix build '.#gcd.vcs.tests.simple-sim' --impure -L
60+
61+
run-verilator:
62+
name: "Run Verilator"
63+
strategy:
64+
fail-fast: false
65+
runs-on: [self-hosted, linux, nixos]
66+
defaults:
67+
run:
68+
working-directory: ./templates/chisel
69+
steps:
70+
- uses: actions/checkout@v4
71+
with:
72+
ref: ${{ github.event.pull_request.head.sha }}
73+
- name: "Run verilator"
74+
run: |
75+
nix run '.#gcd.verilated'

templates/chisel/.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
.bloop
2+
.bsp
3+
.jvm-opts
4+
.mill-jvm-opts
25
.metals/
36
.vscode/
7+
48
out/
59
result*
10+
gcd-sim-result/
611
/dependencies/
712
target/
13+
14+
*.vcd
15+
*.fst
16+
*.fsdb
17+
*.log

templates/chisel/.scalafmt.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ lineEndings = preserve
1010
includeCurlyBraceInSelectChains = false
1111
danglingParentheses.preset = true
1212

13-
align.tokens.add = [
13+
align.tokens."+" = [
1414
{
1515
code = ":"
1616
}

templates/chisel/build.sc

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ trait GCD extends millbuild.common.HasChisel with ScalafmtModule {
3737
}
3838

3939
object elaborator extends Elaborator
40-
trait Elaborator extends millbuild.common.ElaboratorModule {
40+
trait Elaborator extends millbuild.common.ElaboratorModule with ScalafmtModule {
4141
def scalaVersion = T(deps.scalaVer)
4242

4343
def panamaconverterModule = panamaconverter

templates/chisel/configs/GCDTestBenchMain.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
"width": 16,
1111
"useAsyncReset": false
1212
},
13-
"timeout": 5000,
13+
"timeout": 70000,
1414
"testSize": 100
1515
}

templates/chisel/elaborator/src/GCD.scala

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ object GCDMain extends Elaborator {
1111
case class GCDParameterMain(
1212
@arg(name = "xLen") xLen: Int,
1313
@arg(name = "useAsyncReset") useAsyncReset: Boolean) {
14+
require(xLen > 0, "xLen must be a non-negative integer")
15+
require(chisel3.util.isPow2(xLen), "xLen must be a power of 2")
1416
def convert: GCDParameter = GCDParameter(xLen, useAsyncReset)
1517
}
1618

templates/chisel/flake.nix

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
overlays = [ overlay ];
2121
inherit system;
2222
};
23-
in {
23+
in
24+
{
2425
formatter = pkgs.nixpkgs-fmt;
2526
legacyPackages = pkgs;
2627
devShells.default = pkgs.mkShell ({

templates/chisel/gcdemu/src/drive.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ impl Driver {
107107
WATCHDOG_FINISH
108108
} else if tick - self.last_input_cycle > self.timeout {
109109
error!(
110-
"[{}] watchdog timeout, last input tick = {}",
111-
tick, self.last_input_cycle
110+
"[{}] watchdog timeout, last input tick = {}, {} tests completed",
111+
tick, self.last_input_cycle, self.test_num
112112
);
113113
WATCHDOG_TIMEOUT
114114
} else {

templates/chisel/nix/gcd/default.nix

+45-46
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,55 @@
33

44
{ lib, newScope, }:
55
lib.makeScope newScope (scope:
6-
let
7-
designTarget = "GCD";
8-
tbTarget = "GCDTestBench";
9-
dpiLibName = "gcdemu";
10-
in {
11-
# RTL
12-
gcd-compiled = scope.callPackage ./gcd.nix { target = designTarget; };
13-
elaborate = scope.callPackage ./elaborate.nix {
14-
elaborator = scope.gcd-compiled.elaborator;
15-
};
16-
mlirbc = scope.callPackage ./mlirbc.nix { };
17-
rtl = scope.callPackage ./rtl.nix { };
6+
let
7+
designTarget = "GCD";
8+
tbTarget = "GCDTestBench";
9+
dpiLibName = "gcdemu";
10+
in
11+
{
12+
# RTL
13+
gcd-compiled = scope.callPackage ./gcd.nix { target = designTarget; };
14+
elaborate = scope.callPackage ./elaborate.nix {
15+
elaborator = scope.gcd-compiled.elaborator;
16+
};
17+
mlirbc = scope.callPackage ./mlirbc.nix { };
18+
rtl = scope.callPackage ./rtl.nix { };
1819

19-
# Testbench
20-
tb-compiled = scope.callPackage ./gcd.nix { target = tbTarget; };
21-
tb-elaborate = scope.callPackage ./elaborate.nix {
22-
elaborator = scope.tb-compiled.elaborator;
23-
};
24-
tb-mlirbc =
25-
scope.callPackage ./mlirbc.nix { elaborate = scope.tb-elaborate; };
26-
tb-rtl = scope.callPackage ./rtl.nix { mlirbc = scope.tb-mlirbc; };
27-
tb-dpi-lib = scope.callPackage ./dpi-lib.nix { inherit dpiLibName; };
20+
# Testbench
21+
tb-compiled = scope.callPackage ./gcd.nix { target = tbTarget; };
22+
tb-elaborate = scope.callPackage ./elaborate.nix {
23+
elaborator = scope.tb-compiled.elaborator;
24+
};
25+
tb-mlirbc =
26+
scope.callPackage ./mlirbc.nix { elaborate = scope.tb-elaborate; };
27+
tb-rtl = scope.callPackage ./rtl.nix { mlirbc = scope.tb-mlirbc; };
28+
tb-dpi-lib = scope.callPackage ./dpi-lib.nix { inherit dpiLibName; };
2829

29-
verilated = scope.callPackage ./verilated.nix {
30-
rtl = scope.tb-rtl.override { enable-layers = [ "Verification" ]; };
31-
dpi-lib = scope.tb-dpi-lib;
32-
};
33-
verilated-trace = scope.verilated.override {
34-
dpi-lib = scope.verilated.dpi-lib.override { enable-trace = true; };
35-
};
36-
vcs = scope.callPackage ./vcs.nix {
37-
dpi-lib = scope.tb-dpi-lib.override {
38-
sv2023 = false;
39-
vpi = true;
40-
};
41-
rtl = scope.tb-rtl.override {
42-
enable-layers =
43-
[ "Verification" "Verification.Assert" "Verification.Cover" ];
44-
};
30+
verilated = scope.callPackage ./verilated.nix {
31+
rtl = scope.tb-rtl.override { enable-layers = [ "Verification" ]; };
32+
dpi-lib = scope.tb-dpi-lib;
33+
};
34+
verilated-trace = scope.verilated.override {
35+
dpi-lib = scope.verilated.dpi-lib.override { enable-trace = true; };
36+
};
37+
vcs = scope.callPackage ./vcs.nix {
38+
dpi-lib = scope.tb-dpi-lib.override {
39+
sv2023 = false;
40+
vpi = true;
41+
timescale = 1000;
4542
};
46-
vcs-trace = scope.vcs.override {
47-
dpi-lib = scope.vcs.dpi-lib.override {
48-
enable-trace = true;
49-
timescale = 1000;
50-
};
43+
rtl = scope.tb-rtl.override {
44+
enable-layers =
45+
[ "Verification" "Verification.Assert" "Verification.Cover" ];
5146
};
47+
};
48+
vcs-trace = scope.vcs.override {
49+
dpi-lib = scope.vcs.dpi-lib.override { enable-trace = true; };
50+
};
5251

53-
# TODO: designConfig should be read from OM
54-
tbConfig = with builtins;
55-
fromJSON (readFile ./../../configs/${tbTarget}Main.json);
52+
# TODO: designConfig should be read from OM
53+
tbConfig = with builtins;
54+
fromJSON (readFile ./../../configs/${tbTarget}Main.json);
5655

57-
})
56+
})
5857

templates/chisel/nix/gcd/dpi-lib.nix

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# SPDX-FileCopyrightText: 2024 Jiuyang Liu <[email protected]>
33

4-
{ lib, rustPlatform, tbConfig, dpiLibName, sv2023 ? true, vpi ? false
5-
, enable-trace ? false, timescale ? 1 }:
4+
{ lib
5+
, rustPlatform
6+
, tbConfig
7+
, dpiLibName
8+
, sv2023 ? true
9+
, vpi ? false
10+
, enable-trace ? false
11+
, timescale ? 1
12+
}:
613

714
rustPlatform.buildRustPackage rec {
815
name = "dpi-lib";

0 commit comments

Comments
 (0)