Skip to content

Commit

Permalink
[nix] move linting into derivation
Browse files Browse the repository at this point in the history
This commit move code linting to derivation, so we can force developer
to format their code at local build.

Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Oct 5, 2024
1 parent 2983276 commit aaa867a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 76 deletions.
74 changes: 0 additions & 74 deletions .github/workflows/lint.yml

This file was deleted.

5 changes: 4 additions & 1 deletion build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import $file.dependencies.`berkeley-hardfloat`.common
import $file.dependencies.rvdecoderdb.common
import $file.common

// Required for scalafmt to recognize which file to format
def buildSources = T.sources(os.pwd / "build.sc")

object v {
val scala = "2.13.14"
val mainargs = ivy"com.lihaoyi::mainargs:0.5.0"
Expand Down Expand Up @@ -150,7 +153,7 @@ trait T1Emulator extends millbuild.common.T1EmulatorModule with ScalafmtModule {
def chiselIvy = None
}

object rocketemu extends RocketEmulator
object rocketemu extends RocketEmulator

trait RocketEmulator extends millbuild.common.RocketEmulatorModule with ScalafmtModule {
def scalaVersion = T(v.scala)
Expand Down
13 changes: 13 additions & 0 deletions difftest/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ lib
, rustPlatform
, rustfmt
, libspike
, libspike_interfaces
, rtlDesignMetadata
Expand Down Expand Up @@ -31,9 +32,21 @@ rustPlatform.buildRustPackage {
./dpi_t1rocket
./Cargo.lock
./Cargo.toml
./.rustfmt.toml
];
};

nativeBuildInputs = [
rustfmt
];

postConfigure = ''
if ! cargo fmt --check; then
echo "Please run 'cd difftest && cargo fmt' before building emulator!" >&2
exit 1
fi
'';

buildFeatures = [ ] ++ lib.optionals (lib.hasPrefix "dpi" moduleType) [ "dpi_common/${emuType}" ] ++ lib.optionals enableTrace [ "dpi_common/trace" ];
buildAndTestSubdir = "./${moduleType}";

Expand Down
8 changes: 8 additions & 0 deletions nix/pkgs/mill-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ let
mill -i __.prepareOffline
mill -i __.scalaCompilerClasspath
# mill doesn't put scalafmt version into module ivy deps.
# It downloads scalafmt only when checkFormat/reformat is explicitly trigger.
# And we don't want to wait too long for a dependencies task, so here is the solution:
# "checkFormat" the "build.sc" file so that mill will download scalafmt for us,
# and we don't need to wait too long for formatting.
mill -i mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll buildSources
runHook postBuild
'';

Expand Down
35 changes: 34 additions & 1 deletion nix/t1/mill-modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ let
./../../t1rocket/src
./../../t1rocketemu/src
./../../rocketemu/src
./../../.scalafmt.conf
];
};

Expand All @@ -43,9 +44,10 @@ let
fileset = unions [
./../../build.sc
./../../common.sc
./../../.scalafmt.conf
];
};
millDepsHash = "sha256-ZK3m6VKG3PChoj6U2b6bVd+Z2/xkZrPxqaLRVvj7QgQ=";
millDepsHash = "sha256-gBxEO6pGD0A1RxZW2isjPcHDf+b9Sr++7eq6Ezngiio=";
nativeBuildInputs = [ dependencies.setupHook ];
};

Expand Down Expand Up @@ -80,11 +82,42 @@ let

outputs = [ "out" "configgen" "elaborator" "t1package" ];

# Check code format before starting build, so that we can enforce all developer run reformat before build.
configurePhase = ''
runHook preConfigure
_targetsToCheck=(
"configgen"
"elaborator"
"omreader"
"omreaderlib"
"rocketemu"
"rocketv"
"t1"
"t1emu"
"t1rocket"
"t1rocketemu"
)
for _t in ''${_targetsToCheck[@]}; do
if ! mill -i "$_t".checkFormat; then
echo "[ERROR] Please run 'mill -i $_t.reformat' before elaborate!" >&2
exit 1
fi
done
unset _targetsToCheck
runHook postConfigure
'';

buildPhase = ''
runHook preBuild
mill -i '__.assembly'
mill -i t1package.sourceJar
mill -i t1package.chiselPluginJar
runHook postBuild
'';

installPhase = ''
Expand Down

0 comments on commit aaa867a

Please sign in to comment.