Skip to content

Commit 3214395

Browse files
feat: add nix pkg for doc and clippy checks
Signed-off-by: Florian Hartung <florian.hartung@dlr.de>
1 parent d735bd3 commit 3214395

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

flake.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@
300300
useNextest = false;
301301
};
302302

303+
workspace-checks = self.packages.${system}.rust-workspace;
304+
303305
# check that the requirements can be parsed
304306
requirements = pkgs.runCommand "check-requirement" { nativeBuildInputs = [ pkgs.strictdoc ]; } ''
305307
shopt -s globstar

pkgs/rust-workspace.nix

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
lib,
3+
rustPlatform,
4+
clippy,
5+
}:
6+
7+
let
8+
cargoToml = builtins.fromTOML (builtins.readFile ../Cargo.toml);
9+
in
10+
rustPlatform.buildRustPackage rec {
11+
pname = "rust-workspace";
12+
version = cargoToml.package.version;
13+
14+
src =
15+
let
16+
# original source to read from
17+
src = ./..;
18+
19+
# File suffices to include
20+
extensions = [
21+
"lock"
22+
"rs"
23+
"toml"
24+
"wast"
25+
];
26+
# Files to explicitly include
27+
include = [ ];
28+
# Files to explicitly exclude
29+
exclude = [
30+
"flake.lock"
31+
"treefmt.toml"
32+
];
33+
34+
filter = (
35+
path: type:
36+
let
37+
inherit (builtins) baseNameOf toString;
38+
inherit (lib.lists) any;
39+
inherit (lib.strings) hasSuffix removePrefix;
40+
inherit (lib.trivial) id;
41+
42+
# consumes a list of bools, returns true if any of them is true
43+
anyof = any id;
44+
45+
basename = baseNameOf (toString path);
46+
relative = removePrefix (toString src + "/") (toString path);
47+
in
48+
(anyof [
49+
(type == "directory")
50+
(any (ext: hasSuffix ".${ext}" basename) extensions)
51+
(any (file: file == relative) include)
52+
])
53+
&& !(anyof [ (any (file: file == relative) exclude) ])
54+
);
55+
in
56+
lib.sources.cleanSourceWith { inherit src filter; };
57+
58+
cargoLock.lockFile = src + "/Cargo.lock";
59+
60+
dontBuild = true;
61+
doCheck = true;
62+
checkPhase = ''
63+
RUSTDOCFLAGS="-Dwarnings" cargo doc --workspace --all-features --document-private-items
64+
RUSTFLAGS="-Dwarnings" ${clippy}/bin/cargo-clippy --workspace --all-features
65+
'';
66+
installPhase = ''
67+
mkdir "$out"
68+
'';
69+
70+
meta = {
71+
description = "Checks for the Rust workspace";
72+
license = with lib.licenses; [
73+
asl20
74+
# OR
75+
mit
76+
];
77+
maintainers = [ ];
78+
};
79+
}

0 commit comments

Comments
 (0)