2014-10-10 15:59:37 +01:00
|
|
|
{ stdenv, cacert, git, rustc, cargo, rustRegistry }:
|
2015-04-23 01:43:11 +01:00
|
|
|
{ name, src, depsSha256, buildInputs ? [], cargoUpdateHook ? "", ... } @ args:
|
2014-10-10 15:59:37 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
fetchDeps = import ./fetchcargo.nix {
|
|
|
|
inherit stdenv cacert git rustc cargo rustRegistry;
|
|
|
|
};
|
|
|
|
|
|
|
|
cargoDeps = fetchDeps {
|
2015-04-23 01:43:11 +01:00
|
|
|
inherit name src cargoUpdateHook;
|
2014-10-10 15:59:37 +01:00
|
|
|
sha256 = depsSha256;
|
|
|
|
};
|
|
|
|
|
2015-04-23 19:15:47 +01:00
|
|
|
# The following is the directory name cargo creates when the registry index
|
|
|
|
# URL is file:///dev/null
|
|
|
|
#
|
|
|
|
# It's OK to use /dev/null as the URL because by the time we do this, cargo
|
|
|
|
# won't attempt to update the registry anymore, so the URL is more or less
|
|
|
|
# irrelevant
|
|
|
|
registryIndexDirName = "-ba82b75dd6681d6f";
|
|
|
|
|
2014-10-10 15:59:37 +01:00
|
|
|
in stdenv.mkDerivation (args // {
|
2015-04-23 19:15:47 +01:00
|
|
|
inherit cargoDeps rustRegistry;
|
2014-10-10 15:59:37 +01:00
|
|
|
|
2015-04-23 15:37:52 +01:00
|
|
|
patchRegistryDeps = ./patch-registry-deps;
|
|
|
|
|
2014-10-10 15:59:37 +01:00
|
|
|
buildInputs = [ git cargo rustc ] ++ buildInputs;
|
|
|
|
|
|
|
|
configurePhase = args.configurePhase or "true";
|
|
|
|
|
|
|
|
postUnpack = ''
|
2015-04-23 14:14:34 +01:00
|
|
|
echo "Using cargo deps from $cargoDeps"
|
2015-04-23 19:15:47 +01:00
|
|
|
|
|
|
|
cp -r "$cargoDeps" deps
|
2015-04-23 14:14:34 +01:00
|
|
|
chmod +w deps -R
|
|
|
|
|
2015-04-23 19:15:47 +01:00
|
|
|
cat <<EOF > deps/config
|
|
|
|
[registry]
|
|
|
|
index = "file:///dev/null"
|
|
|
|
EOF
|
2015-04-23 14:14:34 +01:00
|
|
|
|
2014-10-10 15:59:37 +01:00
|
|
|
echo "Using rust registry from $rustRegistry"
|
2015-04-23 01:43:11 +01:00
|
|
|
|
2015-04-23 19:15:47 +01:00
|
|
|
ln -s "$rustRegistry" "deps/registry/index/${registryIndexDirName}"
|
|
|
|
|
|
|
|
export CARGO_HOME="$(realpath deps)"
|
|
|
|
|
|
|
|
# Retrieved the Cargo.lock file which we saved during the fetch
|
|
|
|
mv deps/Cargo.lock $sourceRoot/
|
2015-04-23 01:43:11 +01:00
|
|
|
|
2015-04-23 19:15:47 +01:00
|
|
|
(
|
|
|
|
cd $sourceRoot
|
2015-04-23 01:43:11 +01:00
|
|
|
|
2014-10-10 15:59:37 +01:00
|
|
|
cargo fetch
|
2015-04-23 01:43:11 +01:00
|
|
|
cargo clean
|
2014-10-10 15:59:37 +01:00
|
|
|
)
|
|
|
|
'' + (args.postUnpack or "");
|
|
|
|
|
|
|
|
prePatch = ''
|
2015-04-23 15:37:52 +01:00
|
|
|
# Patch registry dependencies, using the scripts in $patchRegistryDeps
|
|
|
|
(
|
|
|
|
set -euo pipefail
|
2014-10-10 15:59:37 +01:00
|
|
|
|
2015-04-23 19:15:47 +01:00
|
|
|
cd ../deps/registry/src/*
|
|
|
|
|
2015-04-23 15:37:52 +01:00
|
|
|
for script in $patchRegistryDeps/*; do
|
|
|
|
# Run in a subshell so that directory changes and shell options don't
|
|
|
|
# affect any following commands
|
|
|
|
|
|
|
|
( . $script)
|
|
|
|
done
|
|
|
|
)
|
2014-10-10 15:59:37 +01:00
|
|
|
'' + (args.prePatch or "");
|
|
|
|
|
|
|
|
buildPhase = args.buildPhase or ''
|
2015-04-21 19:34:26 +01:00
|
|
|
echo "Running cargo build --release"
|
2014-10-10 15:59:37 +01:00
|
|
|
cargo build --release
|
|
|
|
'';
|
|
|
|
|
2015-04-21 19:34:26 +01:00
|
|
|
checkPhase = args.checkPhase or ''
|
|
|
|
echo "Running cargo test"
|
|
|
|
cargo test
|
|
|
|
'';
|
|
|
|
|
|
|
|
doCheck = args.doCheck or true;
|
|
|
|
|
2014-10-10 15:59:37 +01:00
|
|
|
installPhase = args.installPhase or ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
for f in $(find target/release -maxdepth 1 -type f); do
|
|
|
|
cp $f $out/bin
|
|
|
|
done;
|
|
|
|
'';
|
|
|
|
})
|