-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrust-workspace.nix
More file actions
101 lines (84 loc) · 2.36 KB
/
rust-workspace.nix
File metadata and controls
101 lines (84 loc) · 2.36 KB
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
/*
This exposes all crates in the workspace as a single package attribute.
It also enforces various tests.
Losely following the tutorial at https://crane.dev/examples/quick-start-workspace.html
*/
{
flake,
pkgs,
system,
...
}:
let
craneLib = flake.lib.mkCraneLib { inherit pkgs system; };
src = pkgs.lib.cleanSourceWith {
src = flake;
filter =
path: type: (pkgs.lib.hasInfix "/fixtures/" path) || (craneLib.filterCargoSources path type);
};
nativeRuntimeInputs = [
pkgs.facter
]
++ (pkgs.lib.lists.optionals pkgs.stdenv.hostPlatform.isLinux [
pkgs.nixos-facter
]);
commonArgs = {
inherit src;
strictDeps = true;
buildInputs = pkgs.lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here
pkgs.libiconv
];
# Additional environment variables can be set directly
# MY_CUSTOM_VAR = "some value";
meta.platforms = pkgs.lib.platforms.linux ++ pkgs.lib.platforms.darwin;
};
# Build *just* the cargo dependencies (of the entire workspace),
# so we can reuse all of that work (e.g. via cachix) when running in CI
# It is *highly* recommended to use something like cargo-hakari to avoid
# cache misses when building individual top-level-crates
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
in
craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
# NB: we disable tests since we'll run them all via cargo-nextest
doCheck = false;
buildInputs = [ pkgs.makeWrapper ];
postInstall = ''
wrapProgram $out/bin/flt \
--suffix PATH : ${pkgs.lib.makeBinPath nativeRuntimeInputs}
'';
passthru.tests = {
clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
doc = craneLib.cargoDoc (
commonArgs
// {
inherit cargoArtifacts;
}
);
# Audit licenses
deny = craneLib.cargoDeny {
inherit src;
};
nextest = craneLib.cargoNextest (
commonArgs
// {
inherit cargoArtifacts;
nativeBuildInputs = nativeRuntimeInputs;
RUST_BACKTRACE = 1;
# native test binaries go here
partitions = 1;
partitionType = "count";
}
);
};
}
)