2016-06-14 12:49:48 +02:00
|
|
|
{ stdenv, cacert, git, rust, rustRegistry }:
|
2015-05-29 19:35:31 +02:00
|
|
|
{ name, depsSha256
|
|
|
|
, src ? null
|
|
|
|
, srcs ? null
|
|
|
|
, sourceRoot ? null
|
2016-05-28 15:03:59 +02:00
|
|
|
, logLevel ? ""
|
2015-05-29 19:35:31 +02:00
|
|
|
, buildInputs ? []
|
|
|
|
, cargoUpdateHook ? ""
|
2016-12-03 23:36:48 +01:00
|
|
|
, cargoDepsHook ? ""
|
2017-04-15 11:14:55 +02:00
|
|
|
, cargoBuildFlags ? []
|
2015-05-29 19:35:31 +02:00
|
|
|
, ... } @ args:
|
2014-10-10 16:59:37 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
fetchDeps = import ./fetchcargo.nix {
|
2016-06-14 12:49:48 +02:00
|
|
|
inherit stdenv cacert git rust rustRegistry;
|
2014-10-10 16:59:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
cargoDeps = fetchDeps {
|
2015-05-29 19:35:31 +02:00
|
|
|
inherit name src srcs sourceRoot cargoUpdateHook;
|
2014-10-10 16:59:37 +02:00
|
|
|
sha256 = depsSha256;
|
|
|
|
};
|
|
|
|
|
|
|
|
in stdenv.mkDerivation (args // {
|
2015-04-23 20:15:47 +02:00
|
|
|
inherit cargoDeps rustRegistry;
|
2014-10-10 16:59:37 +02:00
|
|
|
|
2015-04-23 16:37:52 +02:00
|
|
|
patchRegistryDeps = ./patch-registry-deps;
|
|
|
|
|
2016-06-14 12:49:48 +02:00
|
|
|
buildInputs = [ git rust.cargo rust.rustc ] ++ buildInputs;
|
2014-10-10 16:59:37 +02:00
|
|
|
|
2017-04-15 12:42:09 +02:00
|
|
|
configurePhase = args.configurePhase or ''
|
|
|
|
runHook preConfigure
|
|
|
|
# noop
|
|
|
|
runHook postConfigure
|
|
|
|
'';
|
2014-10-10 16:59:37 +02:00
|
|
|
|
|
|
|
postUnpack = ''
|
2016-12-03 23:36:48 +01:00
|
|
|
eval "$cargoDepsHook"
|
|
|
|
|
2015-04-23 15:14:34 +02:00
|
|
|
echo "Using cargo deps from $cargoDeps"
|
2015-04-23 20:15:47 +02:00
|
|
|
|
2017-03-30 15:15:49 +02:00
|
|
|
cp -a "$cargoDeps" deps
|
2015-04-23 15:14:34 +02:00
|
|
|
chmod +w deps -R
|
|
|
|
|
2015-05-19 18:21:11 +02:00
|
|
|
# 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
|
|
|
|
|
2015-04-23 20:15:47 +02:00
|
|
|
cat <<EOF > deps/config
|
|
|
|
[registry]
|
|
|
|
index = "file:///dev/null"
|
|
|
|
EOF
|
2015-04-23 15:14:34 +02:00
|
|
|
|
2015-05-19 18:21:11 +02:00
|
|
|
export CARGO_HOME="$(realpath deps)"
|
2016-05-28 12:46:16 +02:00
|
|
|
export RUST_LOG=${logLevel}
|
2016-05-31 20:30:19 +02:00
|
|
|
export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
|
2015-04-23 02:43:11 +02:00
|
|
|
|
2015-05-19 18:21:11 +02:00
|
|
|
# Let's find out which $indexHash cargo uses for file:///dev/null
|
2015-07-24 20:46:14 +02:00
|
|
|
(cd $sourceRoot && cargo fetch &>/dev/null) || true
|
2015-05-19 18:21:11 +02:00
|
|
|
cd deps
|
|
|
|
indexHash="$(basename $(echo registry/index/*))"
|
2015-04-23 20:15:47 +02:00
|
|
|
|
2015-05-19 18:21:11 +02:00
|
|
|
echo "Using indexHash '$indexHash'"
|
|
|
|
|
|
|
|
rm -rf -- "registry/cache/$indexHash" \
|
|
|
|
"registry/index/$indexHash"
|
|
|
|
|
|
|
|
mv registry/cache/HASH "registry/cache/$indexHash"
|
|
|
|
|
|
|
|
echo "Using rust registry from $rustRegistry"
|
|
|
|
ln -s "$rustRegistry" "registry/index/$indexHash"
|
2015-04-23 20:15:47 +02:00
|
|
|
|
|
|
|
# Retrieved the Cargo.lock file which we saved during the fetch
|
2015-05-19 18:21:11 +02:00
|
|
|
cd ..
|
2015-04-23 20:15:47 +02:00
|
|
|
mv deps/Cargo.lock $sourceRoot/
|
2015-04-23 02:43:11 +02:00
|
|
|
|
2015-04-23 20:15:47 +02:00
|
|
|
(
|
|
|
|
cd $sourceRoot
|
2015-04-23 02:43:11 +02:00
|
|
|
|
2014-10-10 16:59:37 +02:00
|
|
|
cargo fetch
|
2015-04-23 02:43:11 +02:00
|
|
|
cargo clean
|
2014-10-10 16:59:37 +02:00
|
|
|
)
|
|
|
|
'' + (args.postUnpack or "");
|
|
|
|
|
|
|
|
prePatch = ''
|
2015-04-23 16:37:52 +02:00
|
|
|
# Patch registry dependencies, using the scripts in $patchRegistryDeps
|
|
|
|
(
|
|
|
|
set -euo pipefail
|
2014-10-10 16:59:37 +02:00
|
|
|
|
2016-02-16 11:55:25 +01:00
|
|
|
cd $NIX_BUILD_TOP/deps/registry/src/*
|
2015-04-23 20:15:47 +02:00
|
|
|
|
2015-04-23 16:37:52 +02: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 16:59:37 +02:00
|
|
|
'' + (args.prePatch or "");
|
|
|
|
|
2017-04-15 11:14:55 +02:00
|
|
|
buildPhase = with builtins; args.buildPhase or ''
|
2017-04-15 12:42:09 +02:00
|
|
|
runHook preBuild
|
2017-04-15 11:14:55 +02:00
|
|
|
echo "Running cargo build --release ${concatStringsSep " " cargoBuildFlags}"
|
|
|
|
cargo build --release ${concatStringsSep " " cargoBuildFlags}
|
2017-04-15 12:42:09 +02:00
|
|
|
runHook postBuild
|
2014-10-10 16:59:37 +02:00
|
|
|
'';
|
|
|
|
|
2015-04-21 20:34:26 +02:00
|
|
|
checkPhase = args.checkPhase or ''
|
2017-04-15 12:42:09 +02:00
|
|
|
runHook preCheck
|
2015-04-21 20:34:26 +02:00
|
|
|
echo "Running cargo test"
|
|
|
|
cargo test
|
2017-04-15 12:42:09 +02:00
|
|
|
runHook postCheck
|
2015-04-21 20:34:26 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
doCheck = args.doCheck or true;
|
|
|
|
|
2014-10-10 16:59:37 +02:00
|
|
|
installPhase = args.installPhase or ''
|
2017-04-15 12:42:09 +02:00
|
|
|
runHook preInstall
|
2014-10-10 16:59:37 +02:00
|
|
|
mkdir -p $out/bin
|
2017-04-15 13:10:29 +02:00
|
|
|
find target/release -maxdepth 1 -executable -exec cp "{}" $out/bin \;
|
2017-04-15 12:42:09 +02:00
|
|
|
runHook postInstall
|
2014-10-10 16:59:37 +02:00
|
|
|
'';
|
|
|
|
})
|