diff --git a/lib/cargoTarpaulin.nix b/lib/cargoTarpaulin.nix index 5ac007d9..1b094f82 100644 --- a/lib/cargoTarpaulin.nix +++ b/lib/cargoTarpaulin.nix @@ -3,7 +3,7 @@ }: { cargoExtraArgs ? "" -, cargoTarpaulinExtraArgs ? "--skip-clean --out Xml --output-dir $out" +, cargoTarpaulinExtraArgs ? "--out Xml --output-dir $out" , ... }@origArgs: let diff --git a/lib/mkCargoDerivation.nix b/lib/mkCargoDerivation.nix index 76e35cb6..929acb45 100644 --- a/lib/mkCargoDerivation.nix +++ b/lib/mkCargoDerivation.nix @@ -5,6 +5,7 @@ , crateNameFromCargoToml , inheritCargoArtifactsHook , installCargoArtifactsHook +, rsync , stdenv , vendorCargoDeps , zstd @@ -59,6 +60,7 @@ chosenStdenv.mkDerivation (cleanedArgs // { configureCargoVendoredDepsHook inheritCargoArtifactsHook installCargoArtifactsHook + rsync zstd ]; diff --git a/lib/setupHooks/inheritCargoArtifacts.nix b/lib/setupHooks/inheritCargoArtifacts.nix index afb3d67e..d4a8a8fe 100644 --- a/lib/setupHooks/inheritCargoArtifacts.nix +++ b/lib/setupHooks/inheritCargoArtifacts.nix @@ -1,4 +1,5 @@ { makeSetupHook +, rsync }: makeSetupHook diff --git a/lib/setupHooks/inheritCargoArtifactsHook.sh b/lib/setupHooks/inheritCargoArtifactsHook.sh index 2456ef1c..a55a3109 100644 --- a/lib/setupHooks/inheritCargoArtifactsHook.sh +++ b/lib/setupHooks/inheritCargoArtifactsHook.sh @@ -24,18 +24,15 @@ inheritCargoArtifacts() { elif [ -d "${preparedArtifacts}" ]; then echo "copying cargo artifacts from ${preparedArtifacts} to ${cargoTargetDir}" - # NB: rustc doesn't like it when artifacts are either symlinks or hardlinks to the store - # (it tries to truncate files instead of unlinking and recreating them) - # so we're forced to do a full copy here :( - # - # Notes: - # - --no-target-directory to avoid nesting (i.e. `./target/target`) - # - preserve timestamps to avoid rebuilding - # - no-preserve ownership (root) so we can make the files writable - cp -r "${preparedArtifacts}" \ - --no-target-directory "${cargoTargetDir}" \ - --preserve=timestamps \ - --no-preserve=ownership + # copy target dir but ignore content-addressed build artifacts + rsync -r --chmod=Du=rwx --exclude "*/build/*" --exclude "*/deps/*" --exclude "*/*/build/*" --exclude "*/*/deps/*" "${preparedArtifacts}/" "${cargoTargetDir}/" + + # symlink all remaining content-addressed artifacts + pushd "${cargoTargetDir}" + for d in $(ls -d */{deps,build} */*/{deps,build}); do + ls "${preparedArtifacts}/${d}" | xargs -P 100 -I '##{}##' ln -fs "${preparedArtifacts}/${d}/##{}##" "${d}/##{}##" + done + popd # Keep existing permissions (e.g. exectuable), but also make things writable # since the store is read-only and cargo would otherwise choke