2014-10-10 16:59:37 +02:00
|
|
|
{ stdenv, cacert, git, rustc, cargo, rustRegistry }:
|
2015-04-23 02:43:11 +02:00
|
|
|
{ name, src, depsSha256, buildInputs ? [], cargoUpdateHook ? "", ... } @ args:
|
2014-10-10 16:59:37 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
fetchDeps = import ./fetchcargo.nix {
|
|
|
|
inherit stdenv cacert git rustc cargo rustRegistry;
|
|
|
|
};
|
|
|
|
|
|
|
|
cargoDeps = fetchDeps {
|
2015-04-23 02:43:11 +02:00
|
|
|
inherit name src cargoUpdateHook;
|
2014-10-10 16:59:37 +02:00
|
|
|
sha256 = depsSha256;
|
|
|
|
};
|
|
|
|
|
|
|
|
in stdenv.mkDerivation (args // {
|
2015-04-23 02:43:11 +02:00
|
|
|
inherit cargoDeps rustRegistry cargoUpdateHook;
|
2014-10-10 16:59:37 +02:00
|
|
|
|
|
|
|
buildInputs = [ git cargo rustc ] ++ buildInputs;
|
|
|
|
|
|
|
|
configurePhase = args.configurePhase or "true";
|
|
|
|
|
|
|
|
postUnpack = ''
|
2015-04-23 15:14:34 +02:00
|
|
|
echo "Using cargo deps from $cargoDeps"
|
|
|
|
cp -r $cargoDeps deps
|
|
|
|
chmod +w deps -R
|
|
|
|
|
|
|
|
export CARGO_HOME=$(realpath deps)
|
|
|
|
|
2014-10-10 16:59:37 +02:00
|
|
|
echo "Using rust registry from $rustRegistry"
|
|
|
|
(
|
|
|
|
cd $sourceRoot
|
|
|
|
ln -s $rustRegistry ./cargo-rust-registry
|
2015-04-23 02:43:11 +02:00
|
|
|
|
|
|
|
substituteInPlace Cargo.lock \
|
|
|
|
--replace "registry+https://github.com/rust-lang/crates.io-index" \
|
|
|
|
"registry+file:///proc/self/cwd/cargo-rust-registry"
|
|
|
|
|
|
|
|
eval "$cargoUpdateHook"
|
|
|
|
|
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 "");
|
|
|
|
|
|
|
|
# TODO: Probably not the best way to do this, but it should work for now
|
|
|
|
prePatch = ''
|
|
|
|
for dir in ../deps/registry/src/*/pkg-config-*; do
|
|
|
|
[ -d "$dir" ] || continue
|
|
|
|
|
|
|
|
substituteInPlace "$dir/src/lib.rs" \
|
|
|
|
--replace '"/usr"' '"/nix/store/"'
|
|
|
|
done
|
|
|
|
'' + (args.prePatch or "");
|
|
|
|
|
|
|
|
buildPhase = args.buildPhase or ''
|
2015-04-21 20:34:26 +02:00
|
|
|
echo "Running cargo build --release"
|
2014-10-10 16:59:37 +02:00
|
|
|
cargo build --release
|
|
|
|
'';
|
|
|
|
|
2015-04-21 20:34:26 +02:00
|
|
|
checkPhase = args.checkPhase or ''
|
|
|
|
echo "Running cargo test"
|
|
|
|
cargo test
|
|
|
|
'';
|
|
|
|
|
|
|
|
doCheck = args.doCheck or true;
|
|
|
|
|
2014-10-10 16:59:37 +02: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;
|
|
|
|
'';
|
|
|
|
})
|