2017-08-05 07:38:48 -07:00
|
|
|
{ fetchurl, stdenv, path, cacert, git, rust }:
|
2017-06-15 14:12:31 -07:00
|
|
|
let
|
2017-08-05 07:38:48 -07:00
|
|
|
cargoVendor = import ./cargo-vendor.nix {
|
|
|
|
inherit fetchurl stdenv;
|
|
|
|
};
|
|
|
|
|
|
|
|
fetchcargo = import ./fetchcargo.nix {
|
|
|
|
inherit stdenv cacert git rust cargoVendor;
|
|
|
|
};
|
2017-06-15 14:12:31 -07:00
|
|
|
in
|
2017-08-05 07:38:48 -07:00
|
|
|
{ name, cargoSha256
|
2015-05-29 10:35:31 -07:00
|
|
|
, src ? null
|
|
|
|
, srcs ? null
|
|
|
|
, sourceRoot ? null
|
2016-05-28 06:03:59 -07:00
|
|
|
, logLevel ? ""
|
2015-05-29 10:35:31 -07:00
|
|
|
, buildInputs ? []
|
|
|
|
, cargoUpdateHook ? ""
|
2016-12-03 14:36:48 -08:00
|
|
|
, cargoDepsHook ? ""
|
2017-04-15 02:14:55 -07:00
|
|
|
, cargoBuildFlags ? []
|
2015-05-29 10:35:31 -07:00
|
|
|
, ... } @ args:
|
2014-10-10 07:59:37 -07:00
|
|
|
|
|
|
|
let
|
2017-06-14 14:36:27 -07:00
|
|
|
lib = stdenv.lib;
|
|
|
|
|
2017-08-05 07:38:48 -07:00
|
|
|
cargoDeps = fetchcargo {
|
2015-05-29 10:35:31 -07:00
|
|
|
inherit name src srcs sourceRoot cargoUpdateHook;
|
2017-08-05 07:38:48 -07:00
|
|
|
sha256 = cargoSha256;
|
2014-10-10 07:59:37 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
in stdenv.mkDerivation (args // {
|
2017-08-05 07:38:48 -07:00
|
|
|
inherit cargoDeps;
|
2014-10-10 07:59:37 -07:00
|
|
|
|
2015-04-23 07:37:52 -07:00
|
|
|
patchRegistryDeps = ./patch-registry-deps;
|
|
|
|
|
2016-06-14 03:49:48 -07:00
|
|
|
buildInputs = [ git rust.cargo rust.rustc ] ++ buildInputs;
|
2014-10-10 07:59:37 -07:00
|
|
|
|
2017-04-15 03:42:09 -07:00
|
|
|
configurePhase = args.configurePhase or ''
|
|
|
|
runHook preConfigure
|
|
|
|
# noop
|
|
|
|
runHook postConfigure
|
|
|
|
'';
|
2014-10-10 07:59:37 -07:00
|
|
|
|
|
|
|
postUnpack = ''
|
2016-12-03 14:36:48 -08:00
|
|
|
eval "$cargoDepsHook"
|
|
|
|
|
2017-10-23 09:13:08 -07:00
|
|
|
if [[ ! -f $cargoDeps/.config ]]; then
|
|
|
|
echo "ERROR: file not found: $cargoDeps/.config"
|
|
|
|
echo "try updating the cargoSha256"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p .cargo
|
|
|
|
# inherit cargo config from the deps, rewrite the target directory
|
|
|
|
cat $cargoDeps/.config | sed "s|REPLACEME|$cargoDeps|g" > .cargo/config
|
2017-11-20 09:02:01 -08:00
|
|
|
|
2016-05-28 03:46:16 -07:00
|
|
|
export RUST_LOG=${logLevel}
|
2016-05-31 11:30:19 -07:00
|
|
|
export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
|
2014-10-10 07:59:37 -07:00
|
|
|
'' + (args.postUnpack or "");
|
|
|
|
|
2017-04-15 02:14:55 -07:00
|
|
|
buildPhase = with builtins; args.buildPhase or ''
|
2017-04-15 03:42:09 -07:00
|
|
|
runHook preBuild
|
2017-04-15 02:14:55 -07:00
|
|
|
echo "Running cargo build --release ${concatStringsSep " " cargoBuildFlags}"
|
2017-08-05 07:38:48 -07:00
|
|
|
cargo build --release --frozen ${concatStringsSep " " cargoBuildFlags}
|
2017-04-15 03:42:09 -07:00
|
|
|
runHook postBuild
|
2014-10-10 07:59:37 -07:00
|
|
|
'';
|
|
|
|
|
2015-04-21 11:34:26 -07:00
|
|
|
checkPhase = args.checkPhase or ''
|
2017-04-15 03:42:09 -07:00
|
|
|
runHook preCheck
|
2015-04-21 11:34:26 -07:00
|
|
|
echo "Running cargo test"
|
|
|
|
cargo test
|
2017-04-15 03:42:09 -07:00
|
|
|
runHook postCheck
|
2015-04-21 11:34:26 -07:00
|
|
|
'';
|
|
|
|
|
|
|
|
doCheck = args.doCheck or true;
|
|
|
|
|
2014-10-10 07:59:37 -07:00
|
|
|
installPhase = args.installPhase or ''
|
2017-04-15 03:42:09 -07:00
|
|
|
runHook preInstall
|
2014-10-10 07:59:37 -07:00
|
|
|
mkdir -p $out/bin
|
2017-04-15 04:10:29 -07:00
|
|
|
find target/release -maxdepth 1 -executable -exec cp "{}" $out/bin \;
|
2017-04-15 03:42:09 -07:00
|
|
|
runHook postInstall
|
2014-10-10 07:59:37 -07:00
|
|
|
'';
|
2017-08-05 07:38:48 -07:00
|
|
|
|
2017-10-26 09:43:17 -07:00
|
|
|
passthru = { inherit cargoDeps; } // (args.passthru or {});
|
2014-10-10 07:59:37 -07:00
|
|
|
})
|