diff options
author | Daniël de Kok <me@danieldk.eu> | 2021-05-08 07:44:31 +0200 |
---|---|---|
committer | Daniël de Kok <me@danieldk.eu> | 2021-05-28 08:01:28 +0200 |
commit | b3969f3ad793ee98af14cf0c649f626520943a53 (patch) | |
tree | a2d96f9e34dd6ad96d4d77b1207e8ae038532edb /pkgs/build-support/rust/default.nix | |
parent | 2f46d77e2806dd22f4ec4ac6ea3f9981df81dd94 (diff) | |
download | nixpkgs-b3969f3ad793ee98af14cf0c649f626520943a53.tar nixpkgs-b3969f3ad793ee98af14cf0c649f626520943a53.tar.gz nixpkgs-b3969f3ad793ee98af14cf0c649f626520943a53.tar.bz2 nixpkgs-b3969f3ad793ee98af14cf0c649f626520943a53.tar.lz nixpkgs-b3969f3ad793ee98af14cf0c649f626520943a53.tar.xz nixpkgs-b3969f3ad793ee98af14cf0c649f626520943a53.tar.zst nixpkgs-b3969f3ad793ee98af14cf0c649f626520943a53.zip |
rustPlatform.buildRustPackage: support direct use of Cargo.lock
This change introduces the cargoLock argument to buildRustPackage, which can be used in place of cargo{Sha256,Hash} or cargoVendorDir. It uses the importCargoLock function to build the vendor directory. Differences compared to cargo{Sha256,Hash}: - Requires a Cargo.lock file. - Does not require a Cargo hash. - Retrieves all dependencies as fixed-output derivations. This makes buildRustPackage much easier to use as part of a Rust project, since it does not require updating cargo{Sha256,Hash} for every change to the lock file.
Diffstat (limited to 'pkgs/build-support/rust/default.nix')
-rw-r--r-- | pkgs/build-support/rust/default.nix | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index ff9ca642daa..711276116a6 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -7,6 +7,7 @@ , cargoInstallHook , cargoSetupHook , fetchCargoTarball +, importCargoLock , runCommandNoCC , rustPlatform , callPackage @@ -41,6 +42,7 @@ , cargoDepsHook ? "" , buildType ? "release" , meta ? {} +, cargoLock ? null , cargoVendorDir ? null , checkType ? buildType , depsExtraArgs ? {} @@ -55,19 +57,22 @@ , buildAndTestSubdir ? null , ... } @ args: -assert cargoVendorDir == null -> !(cargoSha256 == "" && cargoHash == ""); +assert cargoVendorDir == null && cargoLock == null -> cargoSha256 == "" && cargoHash == "" + -> throw "cargoSha256, cargoHash, cargoVendorDir, or cargoLock must be set"; assert buildType == "release" || buildType == "debug"; let - cargoDeps = if cargoVendorDir == null - then fetchCargoTarball ({ - inherit src srcs sourceRoot unpackPhase cargoUpdateHook; - name = cargoDepsName; - hash = cargoHash; - patches = cargoPatches; - sha256 = cargoSha256; - } // depsExtraArgs) + cargoDeps = + if cargoVendorDir == null + then if cargoLock != null then importCargoLock cargoLock + else fetchCargoTarball ({ + inherit src srcs sourceRoot unpackPhase cargoUpdateHook; + name = cargoDepsName; + hash = cargoHash; + patches = cargoPatches; + sha256 = cargoSha256; + } // depsExtraArgs) else null; # If we have a cargoSha256 fixed-output derivation, validate it at build time @@ -96,7 +101,7 @@ in # See https://os.phil-opp.com/testing/ for more information. assert useSysroot -> !(args.doCheck or true); -stdenv.mkDerivation ((removeAttrs args ["depsExtraArgs"]) // lib.optionalAttrs useSysroot { +stdenv.mkDerivation ((removeAttrs args [ "depsExtraArgs" "cargoLock" ]) // lib.optionalAttrs useSysroot { RUSTFLAGS = "--sysroot ${sysroot} " + (args.RUSTFLAGS or ""); } // { inherit buildAndTestSubdir cargoDeps; |