2018-11-21 04:38:49 -08:00
|
|
|
{ stdenv, cacert, git, cargo, rustc, cargo-vendor, fetchcargo, python3 }:
|
|
|
|
|
2018-04-07 14:44:21 -07:00
|
|
|
{ name, cargoSha256 ? "unset"
|
2015-05-29 10:35:31 -07:00
|
|
|
, src ? null
|
|
|
|
, srcs ? null
|
2018-08-12 22:44:30 -07:00
|
|
|
, cargoPatches ? []
|
|
|
|
, patches ? []
|
2015-05-29 10:35:31 -07:00
|
|
|
, 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 ? []
|
2018-02-20 01:59:26 -08:00
|
|
|
|
|
|
|
, cargoVendorDir ? null
|
2015-05-29 10:35:31 -07:00
|
|
|
, ... } @ args:
|
2014-10-10 07:59:37 -07:00
|
|
|
|
2018-04-07 14:44:21 -07:00
|
|
|
assert cargoVendorDir == null -> cargoSha256 != "unset";
|
2018-02-20 01:59:26 -08:00
|
|
|
|
2014-10-10 07:59:37 -07:00
|
|
|
let
|
2018-02-20 01:59:26 -08:00
|
|
|
cargoDeps = if cargoVendorDir == null
|
|
|
|
then fetchcargo {
|
|
|
|
inherit name src srcs sourceRoot cargoUpdateHook;
|
2018-08-12 22:44:30 -07:00
|
|
|
patches = cargoPatches;
|
2018-02-20 01:59:26 -08:00
|
|
|
sha256 = cargoSha256;
|
|
|
|
}
|
|
|
|
else null;
|
|
|
|
|
|
|
|
setupVendorDir = if cargoVendorDir == null
|
|
|
|
then ''
|
|
|
|
unpackFile "$cargoDeps"
|
|
|
|
cargoDepsCopy=$(stripHash $(basename $cargoDeps))
|
|
|
|
chmod -R +w "$cargoDepsCopy"
|
|
|
|
''
|
|
|
|
else ''
|
|
|
|
cargoDepsCopy="$sourceRoot/${cargoVendorDir}"
|
|
|
|
'';
|
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;
|
|
|
|
|
2018-11-21 04:38:49 -08:00
|
|
|
buildInputs = [ cacert git cargo rustc ] ++ buildInputs;
|
2014-10-10 07:59:37 -07:00
|
|
|
|
2018-08-12 22:44:30 -07:00
|
|
|
patches = cargoPatches ++ patches;
|
|
|
|
|
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"
|
|
|
|
|
2018-02-20 01:59:26 -08:00
|
|
|
${setupVendorDir}
|
2017-11-20 09:02:01 -08:00
|
|
|
|
2017-08-05 07:38:48 -07:00
|
|
|
mkdir .cargo
|
2018-09-09 06:54:00 -07:00
|
|
|
config="$(pwd)/$cargoDepsCopy/.cargo/config";
|
|
|
|
if [[ ! -e $config ]]; then
|
|
|
|
config=${./fetchcargo-default-config.toml};
|
|
|
|
fi;
|
|
|
|
substitute $config .cargo/config \
|
|
|
|
--subst-var-by vendor "$(pwd)/$cargoDepsCopy"
|
2015-04-23 06:14:34 -07:00
|
|
|
|
2017-11-20 09:02:01 -08:00
|
|
|
unset cargoDepsCopy
|
|
|
|
|
2016-05-28 03:46:16 -07:00
|
|
|
export RUST_LOG=${logLevel}
|
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
|
2018-09-30 07:03:35 -07:00
|
|
|
mkdir -p $out/bin $out/lib
|
2018-10-07 13:14:19 -07:00
|
|
|
find target/release -maxdepth 1 -type f -executable ! \( -regex ".*\.\(so.[0-9.]+\|so\|a\|dylib\)" \) -print0 | xargs -r -0 cp -t $out/bin
|
|
|
|
find target/release -maxdepth 1 -regex ".*\.\(so.[0-9.]+\|so\|a\|dylib\)" -print0 | xargs -r -0 cp -t $out/lib
|
2018-09-30 07:03:35 -07:00
|
|
|
rmdir --ignore-fail-on-non-empty $out/lib $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
|
|
|
})
|