Skip to content

Commit

Permalink
Lint Rust with Nix to avoid building the workspace twice
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Mar 14, 2024
1 parent ebe78d9 commit fc8190e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ jobs:
env:
SKIP_HAPP_BUILD: 1 # Prevent hApp builds from running when linting
run: |
nix develop --command bash -c "source ./scripts/checks.sh && check_rust_static"
# Currently the only check is clippy, could bundle the other checks into the flake and remove the steps above?
nix flake check
- name: Build and unit tests
run: |
Expand Down
1 change: 1 addition & 0 deletions nix/modules/rust.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

rustWithWasmTarget = rustPkgs.rust-bin.stable."${rustVersion}".minimal.override {
targets = [ "wasm32-unknown-unknown" ];
extensions = [ "clippy" ];
};

craneLib = (inputs.crane.mkLib rustPkgs).overrideToolchain rustWithWasmTarget;
Expand Down
62 changes: 41 additions & 21 deletions nix/modules/workspace.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,50 @@
if system == "x86_64-darwin"
then pkgs.openssl # pkgsStatic is considered a cross build and this is not yet supported
else pkgs.pkgsStatic.openssl;

commonArgs = {
pname = "workspace";
version = "0.1.0";

src = craneLib.cleanCargoSource (craneLib.path ./../..);
strictDeps = true;

buildInputs = with pkgs; [
# Some Holochain crates link against openssl
openssl
opensslStatic
];

nativeBuildInputs = with pkgs; [
# To build openssl-sys
perl
pkg-config
# Because the holochain_client depends on Kitsune/tx5
go
];
};

cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
pname = "${commonArgs.pname}-deps";
});

workspace = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
});

workspaceClippy = craneLib.cargoClippy (commonArgs // {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets --all-features -- --deny warnings";
});
in
{
packages = {
workspace = craneLib.buildPackage {
pname = "workspace";
version = "0.1.0";

src = craneLib.cleanCargoSource (craneLib.path ./../..);
strictDeps = true;

buildInputs = with pkgs; [
# Some Holochain crates link against openssl
openssl
opensslStatic
];

nativeBuildInputs = with pkgs; [
# To build openssl-sys
perl
pkg-config
# Because the holochain_client depends on Kitsune/tx5
go
];
};
default = workspace;
inherit workspace;
};

checks = {
inherit workspaceClippy;
};
};
}
2 changes: 1 addition & 1 deletion scripts/checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ check_rust_fmt() {
}

check_rust_static() {
cargo clippy --workspace --all-targets --all-features -- -D warnings
cargo clippy --workspace --all-targets --all-features -- --deny warnings
}

check_all() {
Expand Down

0 comments on commit fc8190e

Please sign in to comment.