From 5435e977ed85b2faef53cdc4b6c5d8a4eb0adb21 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Sun, 5 Mar 2023 17:24:18 +0000 Subject: [PATCH] get cargo-clippy working on rust-bitcoin Also comment on crate2nix issue explaining how to do it: https://github.com/kolloch/crate2nix/issues/195 --- andrew-utils.nix | 9 +++-- rust-bitcoin.rust-bech32.check-pr.nix | 4 +-- rust-bitcoin.rust-bitcoin.check-pr.nix | 47 +++++++++++++++++++++++--- 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/andrew-utils.nix b/andrew-utils.nix index 4549a88..de44ee0 100644 --- a/andrew-utils.nix +++ b/andrew-utils.nix @@ -196,9 +196,12 @@ rec { }; in { name = builtins.unsafeDiscardStringContext (builtins.toString generatedCargoNix); - value = nixpkgs.callPackage generatedCargoNix { - # We have some should_panic tests in rust-bitcoin that fail in release mode - release = false; + value = { + generated = generatedCargoNix; + called = nixpkgs.callPackage generatedCargoNix { + # We have some should_panic tests in rust-bitcoin that fail in release mode + release = false; + }; }; }; } diff --git a/rust-bitcoin.rust-bech32.check-pr.nix b/rust-bitcoin.rust-bech32.check-pr.nix index ef1f727..7d9f52b 100644 --- a/rust-bitcoin.rust-bech32.check-pr.nix +++ b/rust-bitcoin.rust-bech32.check-pr.nix @@ -78,13 +78,13 @@ let srcName, mtxName, }: - calledCargoNix: + nixes: with pkgs; let pkgs = import { overlays = [ (self: super: { inherit rustc; }) ]; }; - in calledCargoNix.rootCrate.build.override { + in nixes.called.rootCrate.build.override { inherit features; runTests = true; testPreRun = '' diff --git a/rust-bitcoin.rust-bitcoin.check-pr.nix b/rust-bitcoin.rust-bitcoin.check-pr.nix index 91b2e99..34e5403 100644 --- a/rust-bitcoin.rust-bitcoin.check-pr.nix +++ b/rust-bitcoin.rust-bitcoin.check-pr.nix @@ -35,6 +35,7 @@ let { projectName = jsonConfig.repoName; inherit prNum srcName mtxName; + isTip = false; workspace = "bitcoin"; features = [ @@ -53,6 +54,7 @@ let { projectName = jsonConfig.repoName; inherit prNum srcName mtxName; + isTip = false; workspace = "bitcoin"; features = [ @@ -78,6 +80,7 @@ let { projectName = jsonConfig.repoName; inherit prNum srcName mtxName; + isTip = false; workspace = "bitcoin_hashes"; features = [ @@ -94,12 +97,13 @@ let ]; rustc = allRustcs; lockFile = map (x: /. + x) jsonConfig.lockFiles; - src = gitCommits; + src = builtins.head gitCommits; } { projectName = jsonConfig.repoName; inherit prNum srcName mtxName; + isTip = false; workspace = "bitcoin-internals"; features = [ @@ -111,6 +115,22 @@ let lockFile = map (x: /. + x) jsonConfig.lockFiles; src = gitCommits; } + + # Only tip + { + projectName = jsonConfig.repoName; + inherit srcName prNum; + + isTip = true; + + workspace = [ "bitcoin" "bitcoin-internals" "bitcoin_hashes" ]; + features = [ [ "default" ] ]; + rustc = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default); + lockFile = /. + builtins.head jsonConfig.lockFiles; + src = builtins.head gitCommits; + + mtxName = self: (mtxName self) + "-tip"; + } ]; singleCheckMemo = utils.crate2nixSingleCheckMemo; @@ -118,6 +138,7 @@ let singleCheckDrv = { projectName, prNum, + isTip, workspace, features, rustc, @@ -126,19 +147,36 @@ let srcName, mtxName, }: - calledCargoNix: + nixes: let pkgs = import { overlays = [ (self: super: { inherit rustc; }) ]; }; - in calledCargoNix.workspaceMembers.${workspace}.build.override { + in nixes.called.workspaceMembers.${workspace}.build.override { inherit features; runTests = true; testPreRun = '' ${rustc}/bin/rustc -V ${rustc}/bin/cargo -V - echo "Features: ${builtins.toJSON features}" + echo "Tip: ${builtins.toString isTip}" + echo "PR: ${prNum}" + echo "Commit: ${src.commitId}" + echo "Workspace ${workspace} / Features: ${builtins.toJSON features}" ''; + # cargo clippy runs on all workspaces at once, so rather than doing it + # repeatedly for every workspace, just choose one ("bitcoin") and only + # run it there.. + testPostRun = if workspace == "bitcoin" && isTip + then '' + export PATH=$PATH:${pkgs.gcc}/bin:${rustc}/bin + + export CARGO_TARGET_DIR=$PWD/target + cd ${nixes.generated}/crate + CARGO_HOME=../cargo cargo clippy --locked -- -D warnings + echo "Bailing to make this drv obvious" + exit 1 + '' + else ""; }; }; in @@ -153,6 +191,7 @@ in }; name = builtins.toString prNum; shortId = builtins.toString prNum; + commitId = builtins.toString prNum; }; }) checkData.argsMatrices; });