···11+# If the tests are broken, it's probably for one of two reasons:
22+#
33+# 1. The version of llvm used doesn't match the expectations of rustc and/or
44+# cargo-llvm-cov. This is relatively unlikely because we pull llvm out of
55+# rustc's attrset, so it *should* be the right version as long as this is the
66+# case.
77+# 2. Nixpkgs has changed its rust infrastructure in a way that causes
88+# cargo-llvm-cov to misbehave under test. It's likely that even though the
99+# tests are failing, cargo-llvm-cov will still function properly in actual
1010+# use. This has happened before, and is described [here][0] (along with a
1111+# feature request that would fix this instance of the problem).
1212+#
1313+# For previous test-troubleshooting discussion, see [here][1].
1414+#
1515+# [0]: https://github.com/taiki-e/cargo-llvm-cov/issues/242
1616+# [1]: https://github.com/NixOS/nixpkgs/pull/197478
1717+118{ stdenv
219, lib
33-, fetchCrate
2020+, fetchurl
2121+, fetchFromGitHub
422, rustPlatform
2323+, rustc
524}:
62577-rustPlatform.buildRustPackage rec {
2626+let
827 pname = "cargo-llvm-cov";
928 version = "0.5.31";
10291111- src = fetchCrate {
1212- inherit pname version;
1313- sha256 = "sha256-HjnP9H1t660PJ5eXzgAhrdDEgqdzzb+9Dbk5RGUPjaQ=";
3030+ owner = "taiki-e";
3131+ homepage = "https://github.com/${owner}/${pname}";
3232+3333+ llvm = rustc.llvmPackages.llvm;
3434+3535+ # Download `Cargo.lock` from crates.io so we don't clutter up Nixpkgs
3636+ cargoLock = fetchurl {
3737+ name = "Cargo.lock";
3838+ url = "https://crates.io/api/v1/crates/${pname}/${version}/download";
3939+ sha256 = "sha256-BbrdyJgZSIz6GaTdQv1GiFHufRBSbcoHcqqEmr/HvAM=";
4040+ downloadToTemp = true;
4141+ postFetch = ''
4242+ tar xzf $downloadedFile ${pname}-${version}/Cargo.lock
4343+ mv ${pname}-${version}/Cargo.lock $out
4444+ '';
4545+ };
4646+in
4747+4848+rustPlatform.buildRustPackage {
4949+ inherit pname version;
5050+5151+ # Use `fetchFromGitHub` instead of `fetchCrate` because the latter does not
5252+ # pull in fixtures needed for the test suite
5353+ src = fetchFromGitHub {
5454+ inherit owner;
5555+ repo = pname;
5656+ rev = "v${version}";
5757+ sha256 = "sha256-wRo94JVn4InkhrMHFSsEvm2FFIxUsltA57sMMOcL8b0=";
1458 };
1515- cargoSha256 = "sha256-p6zpRRNX4g+jESNSwouWMjZlFhTBFJhe7LirYtFrZ1g=";
16591717- # skip tests which require llvm-tools-preview
1818- checkFlags = [
1919- "--skip bin_crate"
2020- "--skip cargo_config"
2121- "--skip clean_ws"
2222- "--skip instantiations"
2323- "--skip merge"
2424- "--skip merge_failure_mode_all"
2525- "--skip no_test"
2626- "--skip open_report"
2727- "--skip real1"
2828- "--skip show_env"
2929- "--skip virtual1"
3030- ];
6060+ # Upstream doesn't include the lockfile so we need to add it back
6161+ postUnpack = ''
6262+ cp ${cargoLock} source/Cargo.lock
6363+ '';
6464+6565+ cargoSha256 = "sha256-XcsognndhHenYnlJCNMbrNh+S8FX7qxXUjuV1j2qsmY=";
31663232- meta = rec {
3333- homepage = "https://github.com/taiki-e/${pname}";
6767+ # `cargo-llvm-cov` reads these environment variables to find these binaries,
6868+ # which are needed to run the tests
6969+ LLVM_COV = "${llvm}/bin/llvm-cov";
7070+ LLVM_PROFDATA = "${llvm}/bin/llvm-profdata";
7171+7272+ meta = {
7373+ inherit homepage;
3474 changelog = homepage + "/blob/v${version}/CHANGELOG.md";
3575 description = "Cargo subcommand to easily use LLVM source-based code coverage";
3676 longDescription = ''
···3979 library (e.g. fenix or rust-overlay)
4080 '';
4181 license = with lib.licenses; [ asl20 /* or */ mit ];
4242- maintainers = with lib.maintainers; [ wucke13 matthiasbeyer ];
8282+ maintainers = with lib.maintainers; [ wucke13 matthiasbeyer CobaltCause ];
8383+8484+ # The profiler runtime is (currently) disabled on non-Linux platforms
8585+ broken = !(stdenv.isLinux && !stdenv.targetPlatform.isRedox);
4386 };
4487}