Skip to content

Commit

Permalink
buildRustPackage: add documentation on how to create cargo.lock patches
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic92 committed Jun 5, 2020
1 parent fb6c3ce commit f039657
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions doc/languages-frameworks/rust.section.md
Expand Up @@ -75,6 +75,24 @@ pkgs.rustPlatform.buildRustPackage {
}
```

### Building a crate with an absent or out-of-date Cargo.lock file

`buildRustPackage` needs a `Cargo.lock` file to get all dependencies in the
source code in a reproducible way. If it is missing or out-of-date one can use
the `cargoPatches` attribute to update or add it.

```
{ lib, rustPlatform, fetchFromGitHub }:
rustPlatform.buildRustPackage rec {
(...)
cargoPatches = [
# a patch file to add/update Cargo.lock in the source code
./add-Cargo.lock.patch
];
}
```

## Compiling Rust crates using Nix instead of Cargo

### Simple operation
Expand Down
1 change: 1 addition & 0 deletions pkgs/build-support/rust/default.nix
Expand Up @@ -130,6 +130,7 @@ stdenv.mkDerivation (args // {
# give a friendlier error msg.
if ! [ -e $srcLockfile ]; then
echo "ERROR: Missing Cargo.lock from src. Expected to find it at: $srcLockfile"
echo "Hint: You can use the cargoPatches attribute to add a Cargo.lock manually to the build."
exit 1
fi
Expand Down

0 comments on commit f039657

Please sign in to comment.