Skip to content

Commit

Permalink
cargoDoc: add a fallback search for non-cross-compiled docs (#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
ipetkov authored Sep 25, 2024
1 parent 6b40cc8 commit d3797a7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* `downloadCargoPackageFromGit` will now set `fetchLFS = true` when fetching git
repos with defined output hashes

### Fixed
* `cargoDoc` correctly honors `docInstallRoot` when specified
* `cargoDoc` falls back to installing from `./target/doc` even if
`$CARGO_BUILD_TARGET` is set but `./target/$CARGO_BUILD_TARGET/doc` does not
exist

### Removed
* The deprecated top-level (flake) attribute `lib` no longer exists. Please use
`mkLib` with an instance of `pkgs` instead.
Expand Down Expand Up @@ -68,7 +74,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [0.17.2] - 2024-05-26

### Fixed
* `removeReferencesToVendoredSources` has been optimzed to search for source
* `removeReferencesToVendoredSources` has been optimized to search for source
references only once. For derivations which install many files, this phase can
run up to 99% faster than before.
* `cleanCargoToml` now cleans underscored versions of the same attributes (e.g.
Expand Down
3 changes: 2 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ Except where noted below, all derivation attributes are delegated to
`$CARGO_TARGET_DIR` (or default to `./target` if not set) and
`$CARGO_BUILD_TARGET` (if set).
- Default value: `"${CARGO_TARGET_DIR:-target}/${CARGO_BUILD_TARGET:-}/doc"`
if such a directory exists, otherwise falls back to
`"${CARGO_TARGET_DIR:-target}/doc"`

#### Remove attributes
The following attributes will be removed before being lowered to
Expand All @@ -503,7 +505,6 @@ environment variables during the build, you can bring them back via
`.overrideAttrs`.
* `cargoDocExtraArgs`
* `cargoExtraArgs`
* `docInstallRoot`

### `craneLib.cargoFmt`

Expand Down
10 changes: 8 additions & 2 deletions lib/cargoDoc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ let
args = (builtins.removeAttrs origArgs [
"cargoDocExtraArgs"
"cargoExtraArgs"
"docInstallRoot"
]);
in
mkCargoDerivation (args // {
Expand All @@ -22,10 +21,17 @@ mkCargoDerivation (args // {
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
# even when building in release mode, except when cross-compiling targets.
# However, even if CARGO_BUILD_TARGET is set but does not result in cross-compilation
# cargo will still put the docs in the root of the target directory, so we need to take
# that into account
installPhaseCommand = ''
if [ -z "''${docInstallRoot:-}" ]; then
docInstallRoot="''${CARGO_TARGET_DIR:-target}/''${CARGO_BUILD_TARGET:-}/doc"
if ! [ -d "''${docInstallRoot}" ]; then
docInstallRoot="''${CARGO_TARGET_DIR:-target}/doc"
fi
fi
mkdir -p $out/share
Expand Down

0 comments on commit d3797a7

Please sign in to comment.