Add support for cargo doc

This commit is contained in:
Bas van Dijk 2019-07-16 11:06:29 +02:00
parent 2d57092902
commit 4701ae2622
2 changed files with 22 additions and 0 deletions

View file

@ -3,7 +3,10 @@ src:
cargoBuild
, #| What command to run during the test phase
cargoTest ? "cargo test --$CARGO_BUILD_PROFILE"
, #| What command to run during the optional doc phase
cargoDoc ? "cargo doc --offline"
, doCheck ? true
, doDoc ? true
, name
, version
, rustc
@ -49,6 +52,9 @@ with rec
name
version;
outputs = [ "out" ] ++ lib.optional doDoc "doc";
preInstallPhases = lib.optional doDoc [ "docPhase" ];
CARGO_BUILD_PROFILE = if release then "release" else "debug";
# Otherwise specifying CMake as a dep breaks the build
@ -149,6 +155,17 @@ with rec
runHook postCheck
'';
docPhase = lib.optionalString doDoc ''
runHook preDoc
echo "Running doc command:"
echo " ${cargoDoc}"
${cargoDoc}
runHook postDoc
'';
installPhase =
''
runHook preInstall
@ -183,6 +200,10 @@ with rec
mkdir -p $out
cp -r target $out
${lib.optionalString doDoc ''
mv $out/target/doc $doc
''}
runHook postInstall
'';
};

View file

@ -162,6 +162,7 @@ with rec
(attrs //
{ cargoBuild = "source ${buildDepsScript}";
doCheck = false;
doDoc = false;
cargolockPath = builtinz.writeTOML cargolock;
cargotomlPath = builtinz.writeTOML
(