-
Notifications
You must be signed in to change notification settings - Fork 3
/
flake.nix
152 lines (150 loc) · 5.06 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
utils.url = "github:numtide/flake-utils";
devshell.url = "github:numtide/devshell";
fenix.url = "github:nix-community/fenix";
fenix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, utils, devshell, fenix, ... }@inputs:
utils.lib.eachSystem [ "aarch64-linux" "i686-linux" "x86_64-linux" ]
(system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ devshell.overlays.default ];
};
rust-toolchain = with fenix.packages.${system};
combine [
stable.rustc
stable.cargo
stable.clippy
latest.rustfmt
# rust-analyzer
targets.thumbv6m-none-eabi.stable.rust-std
];
in
rec {
devShells.default = (pkgs.devshell.mkShell {
imports = [ "${devshell}/extra/git/hooks.nix" ];
name = "a653rs-dev-shell";
packages = with pkgs; [
clang
rust-toolchain
cargo-outdated
cargo-udeps
cargo-audit
cargo-expand
cargo-all-features
cargo-watch
cargo-release
nixpkgs-fmt
rust-analyzer
];
git.hooks = {
enable = true;
pre-commit.text = ''
# echo "Build all feature combinations:"
# RUSTFLAGS=-Awarnings verify-features
# echo "Build no_std:"
# RUSTFLAGS=-Awarnings verify-no_std
# echo "Build documentation:"
# RUSTFLAGS=-Awarnings verify-doc
# echo "Run 'nix flake check'"
nix flake check
'';
};
commands = [
{ package = "git-cliff"; }
{ package = "treefmt"; }
{
name = "udeps";
command = ''
PATH=${fenix.packages.${system}.latest.rustc}/bin:$PATH
cargo udeps $@
'';
help = pkgs.cargo-udeps.meta.description;
}
{
name = "outdated";
command = "cargo outdated $@";
help = pkgs.cargo-outdated.meta.description;
}
{
name = "audit";
command = "cargo audit $@";
help = pkgs.cargo-audit.meta.description;
}
{
name = "expand";
command = ''
PATH=${fenix.packages.${system}.latest.rustc}/bin:$PATH
cargo expand $@
'';
help = pkgs.cargo-expand.meta.description;
}
{
name = "verify-no_std";
command = ''
cd $PRJ_ROOT
cargo check-all-features --target thumbv6m-none-eabi $@
'';
help =
"Verify that the library builds for no_std without std-features";
category = "test";
}
{
name = "verify-doc";
command = ''
cd $PRJ_ROOT
cargo doc --all-features --workspace $@
RUSTDOCFLAGS="-A rustdoc::private_intra_doc_links " cargo doc --no-default-features --workspace $@
'';
help =
"Verify that the documentation builds without problems";
category = "test";
}
{
name = "verify-features";
command = ''
cd $PRJ_ROOT
cargo check-all-features $@
'';
help =
"Verify that a653rs builds for all feature combinations";
category = "test";
}
{
name = "verify-tests";
command = ''
cd $PRJ_ROOT
cargo test-all-features $@
'';
help =
"Verify that a653rs tests run for all feature combinations";
category = "test";
}
{
name = "verify-examples";
command = ''
cd $PRJ_ROOT
cargo check-all-features --examples $@
'';
help =
"Verify that a653rs examples run for all feature combinations";
category = "test";
}
];
});
checks = {
nixpkgs-fmt = pkgs.runCommand "nixpkgs-fmt"
{
nativeBuildInputs = [ pkgs.nixpkgs-fmt ];
} "nixpkgs-fmt --check ${./.}; touch $out";
cargo-fmt = pkgs.runCommand "cargo-fmt"
{
nativeBuildInputs = [ rust-toolchain ];
} "cd ${./.}; cargo fmt --check; touch $out";
};
});
}