Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symlink cargo build artifacts instead of copying them #322

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cargoTarpaulin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
}:

{ cargoExtraArgs ? ""
, cargoTarpaulinExtraArgs ? "--skip-clean --out Xml --output-dir $out"
, cargoTarpaulinExtraArgs ? "--out Xml --output-dir $out"
, ...
}@origArgs:
let
Expand Down
2 changes: 2 additions & 0 deletions lib/mkCargoDerivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
, crateNameFromCargoToml
, inheritCargoArtifactsHook
, installCargoArtifactsHook
, rsync
, stdenv
, vendorCargoDeps
, zstd
Expand Down Expand Up @@ -59,6 +60,7 @@ chosenStdenv.mkDerivation (cleanedArgs // {
configureCargoVendoredDepsHook
inheritCargoArtifactsHook
installCargoArtifactsHook
rsync
zstd
];

Expand Down
1 change: 1 addition & 0 deletions lib/setupHooks/inheritCargoArtifacts.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{ makeSetupHook
, rsync
}:

makeSetupHook
Expand Down
21 changes: 9 additions & 12 deletions lib/setupHooks/inheritCargoArtifactsHook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down