···1+# If the tests are broken, it's probably for one of two reasons:
2+#
3+# 1. The version of llvm used doesn't match the expectations of rustc and/or
4+# cargo-llvm-cov. This is relatively unlikely because we pull llvm out of
5+# rustc's attrset, so it *should* be the right version as long as this is the
6+# case.
7+# 2. Nixpkgs has changed its rust infrastructure in a way that causes
8+# cargo-llvm-cov to misbehave under test. It's likely that even though the
9+# tests are failing, cargo-llvm-cov will still function properly in actual
10+# use. This has happened before, and is described [here][0] (along with a
11+# feature request that would fix this instance of the problem).
12+#
13+# For previous test-troubleshooting discussion, see [here][1].
14+#
15+# [0]: https://github.com/taiki-e/cargo-llvm-cov/issues/242
16+# [1]: https://github.com/NixOS/nixpkgs/pull/197478
17+18{ stdenv
19, lib
20+, fetchurl
21+, fetchFromGitHub
22, rustPlatform
23+, rustc
24}:
2526+let
27 pname = "cargo-llvm-cov";
28 version = "0.5.31";
2930+ owner = "taiki-e";
31+ homepage = "https://github.com/${owner}/${pname}";
32+33+ llvm = rustc.llvmPackages.llvm;
34+35+ # Download `Cargo.lock` from crates.io so we don't clutter up Nixpkgs
36+ cargoLock = fetchurl {
37+ name = "Cargo.lock";
38+ url = "https://crates.io/api/v1/crates/${pname}/${version}/download";
39+ sha256 = "sha256-BbrdyJgZSIz6GaTdQv1GiFHufRBSbcoHcqqEmr/HvAM=";
40+ downloadToTemp = true;
41+ postFetch = ''
42+ tar xzf $downloadedFile ${pname}-${version}/Cargo.lock
43+ mv ${pname}-${version}/Cargo.lock $out
44+ '';
45+ };
46+in
47+48+rustPlatform.buildRustPackage {
49+ inherit pname version;
50+51+ # Use `fetchFromGitHub` instead of `fetchCrate` because the latter does not
52+ # pull in fixtures needed for the test suite
53+ src = fetchFromGitHub {
54+ inherit owner;
55+ repo = pname;
56+ rev = "v${version}";
57+ sha256 = "sha256-wRo94JVn4InkhrMHFSsEvm2FFIxUsltA57sMMOcL8b0=";
58 };
05960+ # Upstream doesn't include the lockfile so we need to add it back
61+ postUnpack = ''
62+ cp ${cargoLock} source/Cargo.lock
63+ '';
64+65+ cargoSha256 = "sha256-XcsognndhHenYnlJCNMbrNh+S8FX7qxXUjuV1j2qsmY=";
000000006667+ # `cargo-llvm-cov` reads these environment variables to find these binaries,
68+ # which are needed to run the tests
69+ LLVM_COV = "${llvm}/bin/llvm-cov";
70+ LLVM_PROFDATA = "${llvm}/bin/llvm-profdata";
71+72+ meta = {
73+ inherit homepage;
74 changelog = homepage + "/blob/v${version}/CHANGELOG.md";
75 description = "Cargo subcommand to easily use LLVM source-based code coverage";
76 longDescription = ''
···79 library (e.g. fenix or rust-overlay)
80 '';
81 license = with lib.licenses; [ asl20 /* or */ mit ];
82+ maintainers = with lib.maintainers; [ wucke13 matthiasbeyer CobaltCause ];
83+84+ # The profiler runtime is (currently) disabled on non-Linux platforms
85+ broken = !(stdenv.isLinux && !stdenv.targetPlatform.isRedox);
86 };
87}