1 cargoSetupPostUnpackHook
() {
2 echo "Executing cargoSetupPostUnpackHook"
4 # Some cargo builds include build hooks that modify their own vendor
5 # dependencies. This copies the vendor directory into the build tree and makes
6 # it writable. If we're using a tarball, the unpackFile hook already handles
7 # this for us automatically.
8 if [ -z $cargoVendorDir ]; then
9 if [ -d "$cargoDeps" ]; then
10 local dest
=$
(stripHash
"$cargoDeps")
11 cp -Lr --reflink=auto
-- "$cargoDeps" "$dest"
12 chmod -R +644 -- "$dest"
14 unpackFile
"$cargoDeps"
16 export cargoDepsCopy
="$(realpath "$
(stripHash
$cargoDeps)")"
18 cargoDepsCopy
="$(realpath "$
(pwd)/$sourceRoot/${cargoRoot:+$cargoRoot/}${cargoVendorDir}")"
21 if [ ! -d .cargo
]; then
25 config
="$cargoDepsCopy/.cargo/config.toml"
26 if [[ ! -e $config ]]; then
27 config
=@defaultConfig@
31 substitute
$config $tmp_config \
32 --subst-var-by vendor
"$cargoDepsCopy"
33 cat ${tmp_config} >> .cargo
/config.toml
35 cat >> .cargo
/config.toml
<<'EOF'
39 echo "Finished cargoSetupPostUnpackHook"
42 # After unpacking and applying patches, check that the Cargo.lock matches our
43 # src package. Note that we do this after the patchPhase, because the
44 # patchPhase may create the Cargo.lock if upstream has not shipped one.
45 cargoSetupPostPatchHook
() {
46 echo "Executing cargoSetupPostPatchHook"
48 cargoDepsLockfile
="$cargoDepsCopy/Cargo.lock"
49 srcLockfile
="$(pwd)/${cargoRoot:+$cargoRoot/}Cargo.lock"
51 echo "Validating consistency between $srcLockfile and $cargoDepsLockfile"
52 if ! @
diff@
$srcLockfile $cargoDepsLockfile; then
54 # If the diff failed, first double-check that the file exists, so we can
55 # give a friendlier error msg.
56 if ! [ -e $srcLockfile ]; then
57 echo "ERROR: Missing Cargo.lock from src. Expected to find it at: $srcLockfile"
58 echo "Hint: You can use the cargoPatches attribute to add a Cargo.lock manually to the build."
62 if ! [ -e $cargoDepsLockfile ]; then
63 echo "ERROR: Missing lockfile from cargo vendor. Expected to find it at: $cargoDepsLockfile"
68 echo "ERROR: cargoHash or cargoSha256 is out of date"
70 echo "Cargo.lock is not the same in $cargoDepsCopy"
72 echo "To fix the issue:"
73 echo '1. Set cargoHash/cargoSha256 to an empty string: `cargoHash = "";`'
74 echo '2. Build the derivation and wait for it to fail with a hash mismatch'
75 echo '3. Copy the "got: sha256-..." value back into the cargoHash field'
76 echo ' You should have: cargoHash = "sha256-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=";'
84 echo "Finished cargoSetupPostPatchHook"
87 if [ -z "${dontCargoSetupPostUnpack-}" ]; then
88 postUnpackHooks
+=(cargoSetupPostUnpackHook
)
91 if [ -z ${cargoVendorDir-} ]; then
92 postPatchHooks
+=(cargoSetupPostPatchHook
)