Skip to content

Commit

Permalink
get cargo-clippy working on rust-bitcoin
Browse files Browse the repository at this point in the history
Also comment on crate2nix issue explaining how to do it: nix-community/crate2nix#195
  • Loading branch information
apoelstra committed Mar 5, 2023
1 parent 88eab2e commit 5435e97
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
9 changes: 6 additions & 3 deletions andrew-utils.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
};
}
Expand Down
4 changes: 2 additions & 2 deletions rust-bitcoin.rust-bech32.check-pr.nix
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ let
srcName,
mtxName,
}:
calledCargoNix:
nixes:
with pkgs;
let
pkgs = import <nixpkgs> {
overlays = [ (self: super: { inherit rustc; }) ];
};
in calledCargoNix.rootCrate.build.override {
in nixes.called.rootCrate.build.override {
inherit features;
runTests = true;
testPreRun = ''
Expand Down
47 changes: 43 additions & 4 deletions rust-bitcoin.rust-bitcoin.check-pr.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ let
{
projectName = jsonConfig.repoName;
inherit prNum srcName mtxName;
isTip = false;

workspace = "bitcoin";
features = [
Expand All @@ -53,6 +54,7 @@ let
{
projectName = jsonConfig.repoName;
inherit prNum srcName mtxName;
isTip = false;

workspace = "bitcoin";
features = [
Expand All @@ -78,6 +80,7 @@ let
{
projectName = jsonConfig.repoName;
inherit prNum srcName mtxName;
isTip = false;

workspace = "bitcoin_hashes";
features = [
Expand All @@ -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 = [
Expand All @@ -111,13 +115,30 @@ 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;

singleCheckDrv = {
projectName,
prNum,
isTip,
workspace,
features,
rustc,
Expand All @@ -126,19 +147,36 @@ let
srcName,
mtxName,
}:
calledCargoNix:
nixes:
let
pkgs = import <nixpkgs> {
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
Expand All @@ -153,6 +191,7 @@ in
};
name = builtins.toString prNum;
shortId = builtins.toString prNum;
commitId = builtins.toString prNum;
};
}) checkData.argsMatrices;
});
Expand Down

0 comments on commit 5435e97

Please sign in to comment.