mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-13 21:50:33 +03:00
buildRustPackage: add cargoDepsName attribute
The directory in the tarball of vendored dependencies contains `name`, which is by default set to `${pname}-${version}`. This adds an additional attribute to permit setting the name to something of the user's choosing. Since `cargoSha256`/`cargoHash` depend on the name of the directory of vendored dependencies, `cargoDepsName` can be used to e.g. make the hash invariant to the package version by setting `cargoDepsName = pname`.
This commit is contained in:
parent
2b37fe7a77
commit
d92396039d
2 changed files with 32 additions and 1 deletions
|
@ -80,6 +80,33 @@ The fetcher will verify that the `Cargo.lock` file is in sync with the `src`
|
||||||
attribute, and fail the build if not. It will also will compress the vendor
|
attribute, and fail the build if not. It will also will compress the vendor
|
||||||
directory into a tar.gz archive.
|
directory into a tar.gz archive.
|
||||||
|
|
||||||
|
The tarball with vendored dependencies contains a directory with the
|
||||||
|
package's `name`, which is normally composed of `pname` and
|
||||||
|
`version`. This means that the vendored dependencies hash
|
||||||
|
(`cargoSha256`/`cargoHash`) is dependent on the package name and
|
||||||
|
version. The `cargoDepsName` attribute can be used to use another name
|
||||||
|
for the directory of vendored dependencies. For example, the hash can
|
||||||
|
be made invariant to the version by setting `cargoDepsName` to
|
||||||
|
`pname`:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
rustPlatform.buildRustPackage rec {
|
||||||
|
pname = "broot";
|
||||||
|
version = "1.2.0";
|
||||||
|
|
||||||
|
src = fetchCrate {
|
||||||
|
inherit pname version;
|
||||||
|
sha256 = "1mqaynrqaas82f5957lx31x80v74zwmwmjxxlbywajb61vh00d38";
|
||||||
|
};
|
||||||
|
|
||||||
|
cargoHash = "sha256-JmBZcDVYJaK1cK05cxx5BrnGWp4t8ca6FLUbvIot67s=";
|
||||||
|
cargoDepsName = pname;
|
||||||
|
|
||||||
|
# ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Cross compilation
|
### Cross compilation
|
||||||
|
|
||||||
By default, Rust packages are compiled for the host platform, just like any
|
By default, Rust packages are compiled for the host platform, just like any
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
# Legacy hash
|
# Legacy hash
|
||||||
, cargoSha256 ? ""
|
, cargoSha256 ? ""
|
||||||
|
|
||||||
|
# Name for the vendored dependencies tarball
|
||||||
|
, cargoDepsName ? name
|
||||||
|
|
||||||
, src ? null
|
, src ? null
|
||||||
, srcs ? null
|
, srcs ? null
|
||||||
, unpackPhase ? null
|
, unpackPhase ? null
|
||||||
|
@ -60,7 +63,8 @@ let
|
||||||
|
|
||||||
cargoDeps = if cargoVendorDir == null
|
cargoDeps = if cargoVendorDir == null
|
||||||
then fetchCargoTarball ({
|
then fetchCargoTarball ({
|
||||||
inherit name src srcs sourceRoot unpackPhase cargoUpdateHook;
|
inherit src srcs sourceRoot unpackPhase cargoUpdateHook;
|
||||||
|
name = cargoDepsName;
|
||||||
hash = cargoHash;
|
hash = cargoHash;
|
||||||
patches = cargoPatches;
|
patches = cargoPatches;
|
||||||
sha256 = cargoSha256;
|
sha256 = cargoSha256;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue