forked from ipetkov/crane
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildDepsOnly.nix
66 lines (57 loc) · 1.82 KB
/
buildDepsOnly.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
{ crateNameFromCargoToml
, lib
, mkCargoDerivation
, mkDummySrc
, vendorCargoDeps
}:
{ cargoBuildCommand ? "cargoWithProfile build"
, cargoCheckCommand ? "cargoWithProfile check"
, cargoExtraArgs ? "--locked"
, cargoTestCommand ? "cargoWithProfile test"
, cargoTestExtraArgs ? ""
, ...
}@args:
let
crateName = crateNameFromCargoToml args;
cleanedArgs = builtins.removeAttrs args [
"cargoBuildCommand"
"cargoCheckCommand"
"cargoCheckExtraArgs"
"cargoExtraArgs"
"cargoTestCommand"
"cargoTestExtraArgs"
"outputHashes"
"dummySrc"
];
# Run tests by default to ensure we cache any dev-dependencies
doCheck = args.doCheck or true;
cargoCheckExtraArgs = args.cargoCheckExtraArgs or (if doCheck then "--all-targets" else "");
dummySrc =
if args ? dummySrc then
lib.warnIf
(args ? src && args.src != null)
"buildDepsOnly will ignore `src` when `dummySrc` is specified"
args.dummySrc
else
mkDummySrc args;
in
mkCargoDerivation (cleanedArgs // {
inherit doCheck;
src = dummySrc;
pnameSuffix = "-deps";
pname = args.pname or crateName.pname;
version = args.version or crateName.version;
cargoArtifacts = null;
cargoVendorDir = args.cargoVendorDir or (vendorCargoDeps args);
# First we run `cargo check` to cache cargo's internal artifacts, fingerprints, etc. for all deps.
# Then we run `cargo build` to actually compile the deps and cache the results
buildPhaseCargoCommand = args.buildPhaseCargoCommand or ''
${cargoCheckCommand} ${cargoExtraArgs} ${cargoCheckExtraArgs}
${cargoBuildCommand} ${cargoExtraArgs}
'';
checkPhaseCargoCommand = args.checkPhaseCargoCommand or ''
${cargoTestCommand} ${cargoExtraArgs} ${cargoTestExtraArgs}
'';
# No point in building this if not for the cargo artifacts
doInstallCargoArtifacts = true;
})