2022-01-05 01:18:29 +03:00
|
|
|
{ cargoBuild
|
2022-01-04 01:22:08 +03:00
|
|
|
, installFromCargoBuildLogHook
|
2022-01-04 20:48:22 +03:00
|
|
|
, lib
|
2022-01-04 01:22:08 +03:00
|
|
|
}:
|
|
|
|
|
2022-07-23 21:10:45 +03:00
|
|
|
{ cargoBuildCommand ? "cargoWithProfile build"
|
2022-01-04 01:22:08 +03:00
|
|
|
, cargoExtraArgs ? ""
|
|
|
|
, ...
|
|
|
|
}@args:
|
2022-01-04 20:48:22 +03:00
|
|
|
let
|
|
|
|
buildPhaseCargoCommand = args.buildPhaseCargoCommand or ''
|
|
|
|
cargoBuildLog=$(mktemp cargoBuildLogXXXX.json)
|
|
|
|
${cargoBuildCommand} --message-format json-render-diagnostics ${cargoExtraArgs} >"$cargoBuildLog"
|
|
|
|
'';
|
|
|
|
|
2022-07-23 20:04:55 +03:00
|
|
|
installPhaseCommand = args.installPhaseCommand or ''
|
2022-01-04 20:48:22 +03:00
|
|
|
if [ -n "$cargoBuildLog" -a -f "$cargoBuildLog" ]; then
|
|
|
|
installFromCargoBuildLog "$out" "$cargoBuildLog"
|
|
|
|
else
|
|
|
|
echo ${lib.strings.escapeShellArg ''
|
|
|
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
$cargoBuildLog is either undefined or does not point to a valid file location!
|
|
|
|
By default `buildPackage` will capture cargo's output and use it to determine which binaries
|
|
|
|
should be installed (instead of just guessing based on what is present in cargo's target directory).
|
|
|
|
If you are overriding the derivation with a custom build step, you have two options:
|
|
|
|
1. override `installPhaseCommand` with the appropriate installation steps
|
|
|
|
2. ensure that cargo's build log is captured in a file and point $cargoBuildLog at it
|
|
|
|
At a minimum, the latter option can be achieved with running:
|
|
|
|
cargoBuildLog=$(mktemp cargoBuildLogXXXX.json)
|
2022-07-23 21:10:45 +03:00
|
|
|
cargo build --release --message-format json-render-diagnostics >"$cargoBuildLog"
|
2022-01-04 20:48:22 +03:00
|
|
|
''}
|
|
|
|
|
|
|
|
false
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
in
|
2022-01-05 01:18:29 +03:00
|
|
|
(cargoBuild args).overrideAttrs (old: {
|
2022-01-04 20:48:22 +03:00
|
|
|
# NB: we use overrideAttrs here so that our extra additions here do not end up
|
|
|
|
# invalidating any deps builds by being inherited. For example, we probably don't
|
|
|
|
# care about installing bins/libs from the deps only build, so there's no point to
|
|
|
|
# trying to build it with the install scripts in its build environment.
|
|
|
|
|
2022-01-04 01:22:08 +03:00
|
|
|
# Don't copy target dir by default since we are going to be installing bins/libs
|
2022-01-09 04:14:05 +03:00
|
|
|
doInstallCargoArtifacts = args.doInstallCargoArtifacts or false;
|
2022-01-04 01:22:08 +03:00
|
|
|
|
|
|
|
buildPhase = args.buildPhase or ''
|
|
|
|
runHook preBuild
|
2022-01-04 20:48:22 +03:00
|
|
|
${buildPhaseCargoCommand}
|
2022-01-04 01:22:08 +03:00
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = args.installPhase or ''
|
|
|
|
runHook preInstall
|
2022-01-04 20:48:22 +03:00
|
|
|
${installPhaseCommand}
|
2022-01-04 01:22:08 +03:00
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
|
|
|
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
|
|
|
|
installFromCargoBuildLogHook
|
|
|
|
];
|
|
|
|
})
|