crane/lib/cargoDoc.nix
x10an14 23c2d75556
cargoDoc: support docInstallRoot to influence installation behavior (#603)
---------

Co-authored-by: Ivan Petkov <ivanppetkov@gmail.com>
2024-05-04 17:49:24 +00:00

35 lines
867 B
Nix

{ mkCargoDerivation
}:
{ cargoDocExtraArgs ? "--no-deps"
, cargoExtraArgs ? "--locked"
, ...
}@origArgs:
let
args = (builtins.removeAttrs origArgs [
"cargoDocExtraArgs"
"cargoExtraArgs"
"docInstallRoot"
]);
in
mkCargoDerivation (args // {
pnameSuffix = "-doc";
buildPhaseCargoCommand = "cargoWithProfile doc ${cargoExtraArgs} ${cargoDocExtraArgs}";
doInstallCargoArtifacts = args.doInstallCargoArtifacts or false;
docInstallRoot = args.docInstallRoot or "";
# NB: cargo always places docs at the root of the target directory
# even when building in release mode, except when cross-compiling targets
installPhaseCommand = ''
if [ -z "''${docInstallRoot:-}" ]; then
docInstallRoot="''${CARGO_TARGET_DIR:-target}/''${CARGO_BUILD_TARGET:-}/doc"
fi
mkdir -p $out/share
mv "''${docInstallRoot}" $out/share
'';
})