From 4701ae2622f164a64179ee21ed968bf3642522c9 Mon Sep 17 00:00:00 2001 From: Bas van Dijk Date: Tue, 16 Jul 2019 11:06:29 +0200 Subject: [PATCH] Add support for cargo doc --- build.nix | 21 +++++++++++++++++++++ default.nix | 1 + 2 files changed, 22 insertions(+) diff --git a/build.nix b/build.nix index 6fe3fda..3ddf8f9 100644 --- a/build.nix +++ b/build.nix @@ -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 ''; }; diff --git a/default.nix b/default.nix index 52356d3..588ab93 100644 --- a/default.nix +++ b/default.nix @@ -162,6 +162,7 @@ with rec (attrs // { cargoBuild = "source ${buildDepsScript}"; doCheck = false; + doDoc = false; cargolockPath = builtinz.writeTOML cargolock; cargotomlPath = builtinz.writeTOML (