From 0bf98c46997e48e5e8e9ad651e52a30bae362d7b Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Wed, 16 Nov 2022 14:22:19 -0800 Subject: [PATCH 1/4] cargo-llvm-cov: add myself as a maintainer --- pkgs/development/tools/rust/cargo-llvm-cov/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/tools/rust/cargo-llvm-cov/default.nix b/pkgs/development/tools/rust/cargo-llvm-cov/default.nix index 88b2f2e24406..1ca1784a3768 100644 --- a/pkgs/development/tools/rust/cargo-llvm-cov/default.nix +++ b/pkgs/development/tools/rust/cargo-llvm-cov/default.nix @@ -39,6 +39,6 @@ rustPlatform.buildRustPackage rec { library (e.g. fenix or rust-overlay) ''; license = with lib.licenses; [ asl20 /* or */ mit ]; - maintainers = with lib.maintainers; [ wucke13 matthiasbeyer ]; + maintainers = with lib.maintainers; [ wucke13 matthiasbeyer CobaltCause ]; }; } From 8ad7950576b691cf29b397c34c93767a64951cae Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Wed, 16 Nov 2022 14:25:54 -0800 Subject: [PATCH 2/4] cargo-llvm-cov: mark as broken on some platforms --- pkgs/development/tools/rust/cargo-llvm-cov/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/development/tools/rust/cargo-llvm-cov/default.nix b/pkgs/development/tools/rust/cargo-llvm-cov/default.nix index 1ca1784a3768..38db04413ce3 100644 --- a/pkgs/development/tools/rust/cargo-llvm-cov/default.nix +++ b/pkgs/development/tools/rust/cargo-llvm-cov/default.nix @@ -40,5 +40,8 @@ rustPlatform.buildRustPackage rec { ''; license = with lib.licenses; [ asl20 /* or */ mit ]; maintainers = with lib.maintainers; [ wucke13 matthiasbeyer CobaltCause ]; + + # The profiler runtime is (currently) disabled on non-Linux platforms + broken = !(stdenv.isLinux && !stdenv.targetPlatform.isRedox); }; } From eae65c5f85a3d23908f72adb653fa2e2fbc89a7d Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Wed, 16 Nov 2022 14:52:48 -0800 Subject: [PATCH 3/4] cargo-llvm-cov: refactor to fix tests --- .../tools/rust/cargo-llvm-cov/default.nix | 67 +++++++++++++------ 1 file changed, 45 insertions(+), 22 deletions(-) diff --git a/pkgs/development/tools/rust/cargo-llvm-cov/default.nix b/pkgs/development/tools/rust/cargo-llvm-cov/default.nix index 38db04413ce3..1b9449e0dfc5 100644 --- a/pkgs/development/tools/rust/cargo-llvm-cov/default.nix +++ b/pkgs/development/tools/rust/cargo-llvm-cov/default.nix @@ -1,36 +1,59 @@ { stdenv , lib -, fetchCrate +, fetchurl +, fetchFromGitHub , rustPlatform +, rustc }: -rustPlatform.buildRustPackage rec { +let pname = "cargo-llvm-cov"; version = "0.5.31"; - src = fetchCrate { - inherit pname version; - sha256 = "sha256-HjnP9H1t660PJ5eXzgAhrdDEgqdzzb+9Dbk5RGUPjaQ="; + owner = "taiki-e"; + homepage = "https://github.com/${owner}/${pname}"; + + llvm = rustc.llvmPackages.llvm; + + # Download `Cargo.lock` from crates.io so we don't clutter up Nixpkgs + cargoLock = fetchurl { + name = "Cargo.lock"; + url = "https://crates.io/api/v1/crates/${pname}/${version}/download"; + sha256 = "sha256-BbrdyJgZSIz6GaTdQv1GiFHufRBSbcoHcqqEmr/HvAM="; + downloadToTemp = true; + postFetch = '' + tar xzf $downloadedFile ${pname}-${version}/Cargo.lock + mv ${pname}-${version}/Cargo.lock $out + ''; }; - cargoSha256 = "sha256-p6zpRRNX4g+jESNSwouWMjZlFhTBFJhe7LirYtFrZ1g="; +in - # skip tests which require llvm-tools-preview - checkFlags = [ - "--skip bin_crate" - "--skip cargo_config" - "--skip clean_ws" - "--skip instantiations" - "--skip merge" - "--skip merge_failure_mode_all" - "--skip no_test" - "--skip open_report" - "--skip real1" - "--skip show_env" - "--skip virtual1" - ]; +rustPlatform.buildRustPackage { + inherit pname version; - meta = rec { - homepage = "https://github.com/taiki-e/${pname}"; + # Use `fetchFromGitHub` instead of `fetchCrate` because the latter does not + # pull in fixtures needed for the test suite + src = fetchFromGitHub { + inherit owner; + repo = pname; + rev = "v${version}"; + sha256 = "sha256-wRo94JVn4InkhrMHFSsEvm2FFIxUsltA57sMMOcL8b0="; + }; + + # Upstream doesn't include the lockfile so we need to add it back + postUnpack = '' + cp ${cargoLock} source/Cargo.lock + ''; + + cargoSha256 = "sha256-XcsognndhHenYnlJCNMbrNh+S8FX7qxXUjuV1j2qsmY="; + + # `cargo-llvm-cov` reads these environment variables to find these binaries, + # which are needed to run the tests + LLVM_COV = "${llvm}/bin/llvm-cov"; + LLVM_PROFDATA = "${llvm}/bin/llvm-profdata"; + + meta = { + inherit homepage; changelog = homepage + "/blob/v${version}/CHANGELOG.md"; description = "Cargo subcommand to easily use LLVM source-based code coverage"; longDescription = '' From cefb386e7813b26c67196b8966991a971b9e2dce Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Wed, 16 Aug 2023 14:27:19 -0700 Subject: [PATCH 4/4] cargo-llvm-cov: document test failure modes --- .../tools/rust/cargo-llvm-cov/default.nix | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkgs/development/tools/rust/cargo-llvm-cov/default.nix b/pkgs/development/tools/rust/cargo-llvm-cov/default.nix index 1b9449e0dfc5..24e8f458b60b 100644 --- a/pkgs/development/tools/rust/cargo-llvm-cov/default.nix +++ b/pkgs/development/tools/rust/cargo-llvm-cov/default.nix @@ -1,3 +1,20 @@ +# If the tests are broken, it's probably for one of two reasons: +# +# 1. The version of llvm used doesn't match the expectations of rustc and/or +# cargo-llvm-cov. This is relatively unlikely because we pull llvm out of +# rustc's attrset, so it *should* be the right version as long as this is the +# case. +# 2. Nixpkgs has changed its rust infrastructure in a way that causes +# cargo-llvm-cov to misbehave under test. It's likely that even though the +# tests are failing, cargo-llvm-cov will still function properly in actual +# use. This has happened before, and is described [here][0] (along with a +# feature request that would fix this instance of the problem). +# +# For previous test-troubleshooting discussion, see [here][1]. +# +# [0]: https://github.com/taiki-e/cargo-llvm-cov/issues/242 +# [1]: https://github.com/NixOS/nixpkgs/pull/197478 + { stdenv , lib , fetchurl