Skip to content

Commit

Permalink
ci: check code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Apr 23, 2024
1 parent 91c5267 commit c97d72f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 20 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,5 @@ jobs:
#- uses: cachix/install-nix-action@v22
- uses: actions/checkout@v4
- run: nix build -L .#charon
- run: nix build -L .#checks.x86_64-linux.tests
- run: nix build -L .#checks.x86_64-linux.tests-polonius
- run: nix build -L .#charon-ml
- run: nix build -L .#checks.x86_64-linux.charon-ml-tests
- run: nix flake check -L
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ default: build-charon-rust
.PHONY: all
all: build test nix

.PHONY: format
format:
cd charon && $(MAKE) format
cd charon-ml && $(MAKE) format

# We use Rust nightly in order to:
# - be able to write a Rustc plugin
# - use Polonius in some tests
Expand Down
2 changes: 1 addition & 1 deletion charon-ml/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tests: build copy-tests
# Reformat the code
.PHONY: format
format:
dune build @fmt --auto-promote
dune fmt

.PHONY: copy-tests
copy-tests:
Expand Down
52 changes: 36 additions & 16 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,27 @@

rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.template;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
charon =
let
# Clean up the source directory.
sourceFilter = path: type:

cleanedUpSrc = pkgs.lib.cleanSourceWith {
src = ./charon;
filter = path: type:
(craneLib.filterCargoSources path type)
|| (pkgs.lib.hasPrefix (toString ./charon/tests) path)
|| (path == toString ./charon/rust-toolchain);
cleanedUpSrc = pkgs.lib.cleanSourceWith {
src = ./charon;
filter = sourceFilter;
};
cargoArtifacts = craneLib.buildDepsOnly { src = cleanedUpSrc; };
in craneLib.buildPackage {
src = cleanedUpSrc;
inherit cargoArtifacts;
# Check the `ui_llbc` files are correct instead of overwriting them.
cargoTestCommand = "IN_CI=1 cargo test --profile release";
};
};
craneArgs = {
src = cleanedUpSrc;
cargoArtifacts = craneLib.buildDepsOnly { src = cleanedUpSrc; };
};

charon = craneLib.buildPackage (craneArgs // {
# Check the `ui_llbc` files are correct instead of overwriting them.
cargoTestCommand = "IN_CI=1 cargo test --profile release";
});

# Check rust files are correctly formatted.
charon-check-fmt = craneLib.cargoFmt craneArgs;

tests =
let cargoArtifacts = craneLib.buildDepsOnly { src = ./tests; };
in craneLib.buildPackage {
Expand Down Expand Up @@ -207,6 +210,23 @@
};
charon-ml = mk-charon-ml false;
charon-ml-tests = mk-charon-ml true;

charon-ml-check-fmt = pkgs.stdenv.mkDerivation {
name = "charon-ml-check-fmt";
src = ./charon-ml;
buildInputs = [
ocamlPackages.dune_3
ocamlPackages.ocaml
ocamlPackages.ocamlformat
];
buildPhase = ''
if ! dune build @fmt; then
echo 'ERROR: Ocaml code is not formatted. Run `make format` to format the project files'.
exit 1
fi
'';
installPhase = "touch $out";
};
in {
packages = {
inherit charon charon-ml rustc-tests;
Expand All @@ -229,6 +249,6 @@
self.packages.${system}.charon-ml
];
};
checks = { inherit tests tests-polonius charon-ml-tests; };
checks = { inherit tests tests-polonius charon-ml-tests charon-check-fmt charon-ml-check-fmt; };
});
}

0 comments on commit c97d72f

Please sign in to comment.