1{
2 lib,
3 stdenv,
4 pkgsHostHost,
5 file,
6 curl,
7 pkg-config,
8 python3,
9 openssl,
10 cmake,
11 zlib,
12 installShellFiles,
13 makeWrapper,
14 rustPlatform,
15 rustc,
16 auditable ? !cargo-auditable.meta.broken,
17 cargo-auditable,
18}:
19
20rustPlatform.buildRustPackage.override
21 {
22 cargo-auditable = cargo-auditable.bootstrap;
23 }
24 {
25 pname = "cargo";
26 inherit (rustc.unwrapped) version src;
27
28 # the rust source tarball already has all the dependencies vendored, no need to fetch them again
29 cargoVendorDir = "vendor";
30 buildAndTestSubdir = "src/tools/cargo";
31
32 inherit auditable;
33
34 passthru = {
35 rustc = rustc;
36 inherit (rustc.unwrapped) tests;
37 };
38
39 # changes hash of vendor directory otherwise
40 dontUpdateAutotoolsGnuConfigScripts = true;
41
42 nativeBuildInputs = [
43 pkg-config
44 cmake
45 installShellFiles
46 makeWrapper
47 (lib.getDev pkgsHostHost.curl)
48 zlib
49 ];
50 buildInputs = [
51 file
52 curl
53 python3
54 openssl
55 zlib
56 ];
57
58 # cargo uses git-rs which is made for a version of libgit2 from recent master that
59 # is not compatible with the current version in nixpkgs.
60 #LIBGIT2_SYS_USE_PKG_CONFIG = 1;
61
62 # fixes: the cargo feature `edition` requires a nightly version of Cargo, but this is the `stable` channel
63 RUSTC_BOOTSTRAP = 1;
64
65 postInstall = ''
66 wrapProgram "$out/bin/cargo" --suffix PATH : "${rustc}/bin"
67
68 installManPage src/tools/cargo/src/etc/man/*
69
70 installShellCompletion --bash --name cargo \
71 src/tools/cargo/src/etc/cargo.bashcomp.sh
72
73 installShellCompletion --zsh src/tools/cargo/src/etc/_cargo
74 '';
75
76 checkPhase = ''
77 # Disable cross compilation tests
78 export CFG_DISABLE_CROSS_TESTS=1
79 cargo test
80 '';
81
82 # Disable check phase as there are failures (4 tests fail)
83 doCheck = false;
84
85 doInstallCheck = !stdenv.hostPlatform.isStatic && stdenv.hostPlatform.isElf;
86 installCheckPhase = ''
87 runHook preInstallCheck
88 ${stdenv.cc.targetPrefix}readelf -a $out/bin/.cargo-wrapped | grep -F 'Shared library: [libcurl.so'
89 runHook postInstallCheck
90 '';
91
92 meta = with lib; {
93 homepage = "https://crates.io";
94 description = "Downloads your Rust project's dependencies and builds your project";
95 mainProgram = "cargo";
96 teams = [ teams.rust ];
97 license = [
98 licenses.mit
99 licenses.asl20
100 ];
101 platforms = platforms.unix;
102 # https://github.com/alexcrichton/nghttp2-rs/issues/2
103 broken = stdenv.hostPlatform.isx86 && stdenv.buildPlatform != stdenv.hostPlatform;
104 };
105 }