This repository has been archived by the owner on Sep 17, 2022. It is now read-only.
forked from nix-community/naersk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.nix
281 lines (240 loc) · 7.82 KB
/
test.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
{ system ? builtins.currentSystem
, fast ? false
, nixpkgs ? "nixpkgs"
}:
let
sources = import ./nix/sources.nix;
pkgs = import ./nix { inherit system nixpkgs; };
naersk = pkgs.callPackage ./default.nix
{ inherit (pkgs.rustPackages) cargo rustc; };
# very temporary musl tests, just to make sure 1_41_0 builds on 20.03
# (okay, it's actually a wasm test)
muslTests =
{
wasm_rust_1_41_0 =
let
pkgs' = pkgs.appendOverlays
[
(
self: super: rec {
rust_1_41_0 = (
self.callPackage ./rust/1_41_0.nix {
inherit (self.darwin.apple_sdk.frameworks) CoreFoundation Security;
inherit (self) path;
}
);
rust = rust_1_41_0;
rustPackages = self.rust.packages.stable;
inherit (self.rustPackages) rustPlatform;
}
)
];
naersk' = pkgs'.callPackage ./default.nix {};
in
naersk'.buildPackage
{
src = ./test/simple-dep;
CARGO_BUILD_TARGET = "wasm32-unknown-unknown";
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_LINKER = "${pkgs'.llvmPackages_9.lld}/bin/lld";
};
musl_rust_1_41_0 =
let
pkgs' = pkgs.appendOverlays
[
(
self: super: rec {
rust_1_41_0 = (
self.callPackage ./rust/1_41_0.nix {
inherit (self.darwin.apple_sdk.frameworks) CoreFoundation Security;
inherit (self) path;
}
);
rust = rust_1_41_0;
rustPackages = self.rust.packages.stable;
inherit (self.rustPackages) rustPlatform;
}
)
];
naersk' = pkgs'.callPackage ./default.nix {};
in
naersk'.buildPackage
{
src = ./test/simple-dep;
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
};
};
# local tests, that run pretty fast
fastTests =
rec
{
readme = pkgs.runCommand "readme-gen" {}
''
cat ${./README.tpl.md} > $out
${docparse}/bin/docparse ${./config.nix} >> gen
sed -e '/GEN_CONFIGURATION/{r gen' -e 'd}' -i $out
'';
docparse = naersk.buildPackage {
root = ./docparse;
src = builtins.filterSource (
p: t:
let
p' = pkgs.lib.removePrefix (toString ./docparse + "/") p;
in
p' == "Cargo.lock" || p' == "Cargo.toml" || p' == "src" || p' == "src/main.rs"
) ./docparse;
};
readme_test = pkgs.runCommand "readme-test" {}
''
diff ${./README.md} ${readme}
touch $out
'';
# Tests that the builtDependencies derivation can successfully be unpacked
# and that it actually contains cargo's output artifacts. If the result is
# ever empty, cargo will still succeed in building the top level crate, except
# it will need to rebuild all dependencies from scratch, which is wasteful.
# See https://github.com/nix-community/naersk/issues/202
depsTargetNotEmpty = pkgs.runCommand "depsTargetNotEmpty"
{ inherit (simple-dep) builtDependencies; }
''
for dep in $builtDependencies; do
# Make destination directory for unarchiving
mkdir dst
${pkgs.zstd}/bin/zstd -d "$dep/target.tar.zst" --stdout | tar -x -C ./dst
if [ -z "$(ls -A ./dst)" ]; then
echo target directory is empty: "$dep"
return 1
fi
rm -rf ./dst
done
# Success
touch $out
'';
# Same as the test above except checks when the builtDependencies
# derivation is not compressed.
depsUncompressedTargetNotEmpty = pkgs.runCommand "depsUncompressedTargetNotEmpty"
{ inherit (simple-dep-no-compress) builtDependencies; }
''
for dep in $builtDependencies; do
if [ -z "$(ls -A "$dep"/target)" ]; then
echo target directory is empty: "$dep"
return 1
fi
done
# Success
touch $out
'';
simple-dep = naersk.buildPackage {
src = ./test/simple-dep;
doCheck = true;
};
simple-dep-no-compress = naersk.buildPackage {
src = ./test/simple-dep;
doCheck = true;
compressTarget = false;
};
simple-dep-doc = naersk.buildPackage
{
src = ./test/simple-dep;
doDoc = true;
doCheck = true;
};
simple-dep-patched = naersk.buildPackage {
src = ./test/simple-dep-patched;
doCheck = true;
};
cargo-release = naersk.buildPackage {
src = ./test/cargo-release;
doCheck = true;
};
dummyfication = naersk.buildPackage {
src = ./test/dummyfication;
doCheck = true;
};
dummyfication_test = pkgs.runCommand
"dummyfication-test"
{ buildInputs = [ dummyfication ]; }
"my-bin > $out";
git-dep = naersk.buildPackage {
doCheck = true;
src = ./test/git-dep;
cargoOptions = (opts: opts ++ [ "--locked" ]);
};
git-dep-by-tag = naersk.buildPackage {
doCheck = true;
src = ./test/git-dep-by-tag;
cargoOptions = (opts: opts ++ [ "--locked" ]);
};
git-dep-dup = naersk.buildPackage {
doCheck = true;
src = ./test/git-dep-dup;
cargoOptions = (opts: opts ++ [ "--locked" ]);
};
cargo-wildcard = naersk.buildPackage {
src = ./test/cargo-wildcard;
doCheck = true;
};
workspace = naersk.buildPackage {
src = ./test/workspace;
doCheck = true;
};
workspace-patched = naersk.buildPackage {
src = ./test/workspace-patched;
doCheck = true;
};
workspace-doc = naersk.buildPackage
{
src = ./test/workspace;
doDoc = true;
doCheck = true;
};
workspace-build-rs = naersk.buildPackage {
src = ./test/workspace-build-rs;
doCheck = true;
};
default-run = naersk.buildPackage {
src = ./test/default-run;
doCheck = true;
};
};
# extra crates, that are kinda slow to build
heavyTests = rec {
ripgrep-all = naersk.buildPackage
{
src = sources.ripgrep-all;
doCheck = true;
};
ripgrep-all_test = pkgs.runCommand "ripgrep-all-test"
{ buildInputs = [ ripgrep-all ]; }
"rga --help && touch $out";
lorri = naersk.buildPackage {
src = sources.lorri;
BUILD_REV_COUNT = 1;
RUN_TIME_CLOSURE = "${sources.lorri}/nix/runtime.nix";
};
lorri_test = pkgs.runCommand "lorri-test" { buildInputs = [ lorri ]; }
"lorri --help && touch $out";
talent-plan-1 = naersk.buildPackage {
src = "${sources.talent-plan}/rust/projects/project-1";
doCheck = true;
};
talent-plan-2 = naersk.buildPackage {
doCheck = true;
src = "${sources.talent-plan}/rust/projects/project-2";
};
talent-plan-3 = naersk.buildPackage "${sources.talent-plan}/rust/projects/project-3";
rustlings = naersk.buildPackage sources.rustlings;
agent-rs = naersk.buildPackage {
doCheck = true;
src = sources.agent-rs;
buildInputs =
[
pkgs.openssl
pkgs.pkg-config
pkgs.perl
] ++ pkgs.lib.optional pkgs.stdenv.isDarwin pkgs.libiconv;
};
};
in
fastTests
// pkgs.lib.optionalAttrs (! fast) heavyTests
// pkgs.lib.optionalAttrs (nixpkgs == "nixpkgs-20.03" && pkgs.stdenv.isLinux) muslTests