-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
163 lines (158 loc) · 5.97 KB
/
Copy pathflake.nix
File metadata and controls
163 lines (158 loc) · 5.97 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
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
152
153
154
155
156
157
158
159
160
161
162
163
# SPDX-FileCopyrightText: 2025 xfnw
# SPDX-License-Identifier: MIT
{
inputs = {
crane.url = "github:ipetkov/crane";
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
outputs = { self, crane, flake-utils, nixpkgs }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
inherit (pkgs.lib) attrValues concatLines fileset genAttrs map optionalString;
crane' = crane.mkLib pkgs;
# simplified crane'.buildDepsOnly that allows artifacts
buildDepsOnly =
{
pname,
version,
cargoExtraArgs ? "--locked",
cargoBuildCommand ? "cargoWithProfile build",
cargoCheckCommand ? "cargoWithProfile check",
cargoCheckExtraArgs ? "--all-targets",
cargoTestCommand ? "cargoWithProfile test",
cargoTestExtraArgs ? "--no-run",
...
}@args: let
src = crane'.mkDummySrc args;
dargs = args // { inherit src; };
doCheck = args.doCheck or true;
in crane'.mkCargoDerivation (args // {
inherit src doCheck;
pnameSuffix = "-deps";
cargoArtifacts = args.cargoArtifacts or null;
cargoVendorDir = args.cargoVendorDir or (crane'.vendorCargoDeps dargs);
env.CRANE_BUILD_DEPS_ONLY = 1;
buildPhaseCargoCommand = ''
${optionalString doCheck "${cargoCheckCommand} ${cargoExtraArgs} ${cargoCheckExtraArgs}"}
${cargoBuildCommand} ${cargoExtraArgs}
'';
checkPhaseCargoCommand = ''
${cargoTestCommand} ${cargoExtraArgs} ${cargoTestExtraArgs}
'';
doInstallCargoArtifacts = true;
});
src = ./.;
common = {
pname = "workspace";
version = "0";
inherit src;
cargoVendorDir = crane'.vendorMultipleCargoDeps {
cargoLockList = [
./Cargo.lock
./crates/vancouver/tests/data/violation/Cargo.lock
];
};
};
cargoArtifacts = buildDepsOnly common;
commonFileSet = fileset.union ./Cargo.toml ./Cargo.lock;
buildPackage = pname: deps: let
inherit (crane'.crateNameFromCargoToml {
src = "${src}/crates/${pname}";
}) version;
cargoExtraArgs = "--offline -p ${pname}";
depsFileSet = fileset.unions ([
commonFileSet
] ++ map (p: ./crates/${p}) deps);
depsSrc = fileset.toSource {
root = ./.;
fileset = depsFileSet;
};
src = fileset.toSource {
root = ./.;
fileset = fileset.union depsFileSet ./crates/${pname};
};
in crane'.buildPackage (common // {
inherit pname version src cargoExtraArgs;
cargoArtifacts = buildDepsOnly (common // {
inherit pname version src cargoExtraArgs cargoArtifacts;
extraDummyScript = ''
# mkDummySrc tries to eat workspace lints. put them back
ln -sf ${depsSrc}/Cargo.toml $out/Cargo.toml
${concatLines (map (crate: ''
rm -r $out/crates/${crate}
ln -s ${depsSrc}/crates/${crate} $out/crates
'') deps)}
'';
doCheck = false; # the workspace deps build checks deps already
});
doCheck = false; # tests are run as a flake check
});
members = {
cabot = buildPackage "cabot" [ "fixed-hex" "cabotfs" "foxerror" "irc-connect" ];
gekker = buildPackage "gekker" [ "irc-connect" ];
maw = buildPackage "maw" [ ];
offerparty = buildPackage "offerparty" [ "foxerror" "irc-connect" ];
vancouver = buildPackage "vancouver" [ "foxerror" ];
vasm = buildPackage "vasm" [ "foxerror" ];
};
in {
checks = {
clippy = crane'.cargoClippy (common // {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- -D warnings";
});
doc = crane'.cargoDoc (common // {
inherit cargoArtifacts;
env.RUSTDOCFLAGS = "-D warnings";
});
test = crane'.cargoTest (common // {
inherit cargoArtifacts;
});
fmt = crane'.cargoFmt common;
reuse = pkgs.runCommand "workspace-reuse" { } ''
cd ${src}
${pkgs.reuse}/bin/reuse lint
touch $out
'';
};
packages = members // {
default = crane'.buildPackage (common // {
inherit cargoArtifacts;
src = fileset.toSource {
root = ./.;
fileset = fileset.union commonFileSet ./crates;
};
doCheck = false; # tests are run as a flake check
});
doc = crane'.cargoDoc (common // {
inherit cargoArtifacts;
cargoDocExtraArgs = "";
});
coverage = crane'.mkCargoDerivation (common // {
pnameSuffix = "-coverage";
# we rebuild everything regardless
cargoArtifacts = null;
doInstallCargoArtifacts = false;
buildPhaseCargoCommand = "cargo test";
installPhaseCommand = ''
${pkgs.grcov}/bin/grcov "$TMPDIR/prof" \
--llvm --llvm-path ${pkgs.llvm}/bin \
--binary-path target/debug/deps \
-s . -t html -o $out
'';
env = {
# TODO: add --persist-doctests once stabilized,
# so we can get doctest coverage too
# https://github.com/rust-lang/rust/issues/56925
RUSTFLAGS = "-Cinstrument-coverage";
LLVM_PROFILE_FILE = "%t/prof/%p-%m.profraw";
};
});
};
devShells.default = crane'.devShell {
checks = self.checks.${system};
};
});
}