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

View file

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