clippy: fix cross linting

Clippy uses `clippy-driver` for linting, which needs to be pointed to the
correct sysroot, just like our rustc.

Fixes: https://github.com/NixOS/nixpkgs/issues/278508
This commit is contained in:
Marie Ramlow
2025-08-15 15:35:41 +02:00
committed by Alyssa Ross
parent ab0f3607a6
commit f3423e9fdd
2 changed files with 36 additions and 6 deletions

View File

@@ -0,0 +1,34 @@
{
lib,
runCommand,
clippy-unwrapped,
rustc-unwrapped,
makeWrapper,
}:
runCommand "${clippy-unwrapped.pname}-wrapper-${clippy-unwrapped.version}"
{
preferLocalBuild = true;
strictDeps = true;
inherit (clippy-unwrapped) outputs;
nativeBuildInputs = [ makeWrapper ];
meta = clippy-unwrapped.meta // {
description = "${clippy-unwrapped.meta.description} (wrapper script)";
priority = 10;
};
}
''
mkdir -p $out/bin
makeWrapper ${clippy-unwrapped}/bin/cargo-clippy $out/bin/cargo-clippy \
--set-default SYSROOT ${rustc-unwrapped}
makeWrapper ${clippy-unwrapped}/bin/clippy-driver $out/bin/clippy-driver \
--set-default SYSROOT ${rustc-unwrapped}
${lib.concatMapStrings (output: "ln -s ${clippy-unwrapped.${output}} \$${output}\n") (
lib.remove "out" clippy-unwrapped.outputs
)}
''

View File

@@ -127,12 +127,8 @@ in
self.callPackage ./cargo_cross.nix { };
cargo-auditable = self.callPackage ./cargo-auditable.nix { };
cargo-auditable-cargo-wrapper = self.callPackage ./cargo-auditable-cargo-wrapper.nix { };
clippy = self.callPackage ./clippy.nix {
# We want to use self, not buildRustPackages, so that
# buildPackages.clippy uses the cross compiler and supports
# linting for the target platform.
rustPlatform = makeRustPlatform self;
};
clippy-unwrapped = self.callPackage ./clippy.nix { };
clippy = if !fastCross then self.clippy-unwrapped else self.callPackage ./clippy-wrapper.nix { };
}
);
};