Merge pull request #197478 from CobaltCause/add-cargo-llvm-cov

cargo-llvm-cov: fix tests, mark broken as needed

authored by Matthias Beyer and committed by GitHub ac1367d4 6ef5ca47

+66 -23
+66 -23
pkgs/development/tools/rust/cargo-llvm-cov/default.nix
··· 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 + 1 18 { stdenv 2 19 , lib 3 - , fetchCrate 20 + , fetchurl 21 + , fetchFromGitHub 4 22 , rustPlatform 23 + , rustc 5 24 }: 6 25 7 - rustPlatform.buildRustPackage rec { 26 + let 8 27 pname = "cargo-llvm-cov"; 9 28 version = "0.5.31"; 10 29 11 - src = fetchCrate { 12 - inherit pname version; 13 - sha256 = "sha256-HjnP9H1t660PJ5eXzgAhrdDEgqdzzb+9Dbk5RGUPjaQ="; 30 + 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="; 14 58 }; 15 - cargoSha256 = "sha256-p6zpRRNX4g+jESNSwouWMjZlFhTBFJhe7LirYtFrZ1g="; 16 59 17 - # skip tests which require llvm-tools-preview 18 - checkFlags = [ 19 - "--skip bin_crate" 20 - "--skip cargo_config" 21 - "--skip clean_ws" 22 - "--skip instantiations" 23 - "--skip merge" 24 - "--skip merge_failure_mode_all" 25 - "--skip no_test" 26 - "--skip open_report" 27 - "--skip real1" 28 - "--skip show_env" 29 - "--skip virtual1" 30 - ]; 60 + # 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="; 31 66 32 - meta = rec { 33 - homepage = "https://github.com/taiki-e/${pname}"; 67 + # `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; 34 74 changelog = homepage + "/blob/v${version}/CHANGELOG.md"; 35 75 description = "Cargo subcommand to easily use LLVM source-based code coverage"; 36 76 longDescription = '' ··· 39 79 library (e.g. fenix or rust-overlay) 40 80 ''; 41 81 license = with lib.licenses; [ asl20 /* or */ mit ]; 42 - maintainers = with lib.maintainers; [ wucke13 matthiasbeyer ]; 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); 43 86 }; 44 87 }