Unverified Commit 29cca090 authored by Philip Taron's avatar Philip Taron Committed by GitHub
Browse files

rustPlatform.fetchCargoTarball: support pname+version (#332975)

parents 71f01ce1 e273bc80
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -567,8 +567,7 @@ buildPythonPackage rec {
  };

  cargoDeps = rustPlatform.fetchCargoTarball {
    inherit src sourceRoot;
    name = "${pname}-${version}";
    inherit pname version src sourceRoot;
    hash = "sha256-miW//pnOmww2i6SOGbkrAIdc/JMDT4FJLqdMFojZeoY=";
  };

@@ -611,9 +610,8 @@ buildPythonPackage rec {
  };

  cargoDeps = rustPlatform.fetchCargoTarball {
    inherit src;
    inherit pname version src;
    sourceRoot = "${pname}-${version}/${cargoRoot}";
    name = "${pname}-${version}";
    hash = "sha256-PS562W4L1NimqDV2H0jl5vYhL08H9est/pbIxSdYVfo=";
  };

@@ -652,8 +650,7 @@ buildPythonPackage rec {
  };

  cargoDeps = rustPlatform.fetchCargoTarball {
    inherit src;
    name = "${pname}-${version}";
    inherit pname version src;
    hash = "sha256-heOBK8qi2nuc/Ib+I/vLzZ1fUUD/G/KTw9d7M4Hz5O0=";
  };

@@ -697,8 +694,7 @@ stdenv.mkDerivation rec {
  };

  cargoDeps = rustPlatform.fetchCargoTarball {
    inherit src;
    name = "${pname}-${version}";
    inherit pname version src;
    hash = "sha256-8fa3fa+sFi5H+49B5sr2vYPkp9C9s6CcE0zv4xB8gww=";
  };

+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ stdenv.mkDerivation rec {
  };

  cargoDeps = rustPlatform.fetchCargoTarball {
    inherit pname version src;
    inherit src;
    hash = "sha256-XTfKqKs7874ak7Lzscxw8E2qcnJOWMZaaol8TpIB6Vw=";
  };

+155 −115
Original line number Diff line number Diff line
{ lib, stdenv, cacert, git, cargo, python3 }:
let cargo-vendor-normalise = stdenv.mkDerivation {
{
  lib,
  stdenv,
  cacert,
  git,
  cargo,
  python3,
}:
let
  cargo-vendor-normalise = stdenv.mkDerivation {
    name = "cargo-vendor-normalise";
    src = ./cargo-vendor-normalise.py;
    nativeBuildInputs = [ python3.pkgs.wrapPython ];
@@ -17,27 +25,59 @@ let cargo-vendor-normalise = stdenv.mkDerivation {
    preferLocalBuild = true;
  };
in
{ name ? "cargo-deps"
, src ? null
, srcs ? []
, patches ? []
, sourceRoot ? ""
, cargoUpdateHook ? ""
, nativeBuildInputs ? []
, ...
{
  pname ? null,
  version ? null,
  name ? if args ? pname && args ? version then "${pname}-${version}" else "cargo-deps",
  src ? null,
  srcs ? [ ],
  patches ? [ ],
  sourceRoot ? "",
  cargoUpdateHook ? "",
  nativeBuildInputs ? [ ],
  ...
}@args:

let hash_ =
assert lib.assertMsg (
  (args ? pname || args ? version) -> !(args ? name)
) "Either specify `pname` with `version`, or specify `name` only, not a mix of both.";
assert lib.assertMsg (
  args ? pname == args ? version
) "If `pname` is specified, `version` must be also, and vice versa.";
let
  # args to remove from the final call to stdenv.mkDerivation, as we've already handled them
  removedArgs = [
    "name"
    "pname"
    "version"
    "sha256"
    "cargoUpdateHook"
    "nativeBuildInputs"
  ];

  hash_ =
    if args ? hash then
      {
        outputHashAlgo = if args.hash == "" then "sha256" else null;
        outputHash = args.hash;
      }
  else if args ? sha256 then { outputHashAlgo = "sha256"; outputHash = args.sha256; }
  else throw "fetchCargoTarball requires a hash for ${name}";
in stdenv.mkDerivation ({
    else if args ? sha256 then
      {
        outputHashAlgo = "sha256";
        outputHash = args.sha256;
      }
    else
      throw "fetchCargoTarball requires a hash for ${name}";
in
stdenv.mkDerivation (
  {
    name = "${name}-vendor.tar.gz";
  nativeBuildInputs = [ cacert git cargo-vendor-normalise cargo ] ++ nativeBuildInputs;
    nativeBuildInputs = [
      cacert
      git
      cargo-vendor-normalise
      cargo
    ] ++ nativeBuildInputs;

    buildPhase = ''
      runHook preBuild
@@ -111,6 +151,6 @@ in stdenv.mkDerivation ({
    inherit (hash_) outputHashAlgo outputHash;

    impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [ "NIX_CRATES_INDEX" ];
} // (builtins.removeAttrs args [
  "name" "sha256" "cargoUpdateHook" "nativeBuildInputs"
]))
  }
  // (removeAttrs args removedArgs)
)
+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ stdenv.mkDerivation (finalAttrs: {
  };

  cargoDeps = rustPlatform.fetchCargoTarball {
    inherit (finalAttrs) pname version src;
    inherit (finalAttrs) src;
    hash = "sha256-Q4CfDQxlhspjg7Et+0zHwZ/iSnp0CnwwpW/gT7htlL8=";
  };

+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ stdenv.mkDerivation (finalAttrs: {
  };

  cargoDeps = rustPlatform.fetchCargoTarball {
    inherit (finalAttrs) pname version src;
    inherit (finalAttrs) src;
    hash = "sha256-YVbaXGGwQaqjUkA47ryW1VgJpZTx5ApRGdCcB5aA71M=";
  };

Loading