Commit 0944487c authored by Alyssa Ross's avatar Alyssa Ross
Browse files

clippy: use the right rustc when cross compiling

When cross compiling, buildPackages.cargo uses a rustc that can build
for both the build and host platforms.  This was not true of
buildPackages.clippy, so it was not possible to use clippy for a cross
target.  Now it is.

I've modified clippy.nix to use rustc from rustPlatform, so we only
have to add a single override in default.nix.
parent e4050a49
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
{ stdenv, lib, rustPlatform, rustc, Security, patchelf }:
{ stdenv, lib, rustPlatform, Security, patchelf }:

rustPlatform.buildRustPackage {
  pname = "clippy";
  inherit (rustc) version src;
  inherit (rustPlatform.rust.rustc) version src;

  # the rust source tarball already has all the dependencies vendored, no need to fetch them again
  cargoVendorDir = "vendor";
@@ -10,7 +11,8 @@ rustPlatform.buildRustPackage {
  # changes hash of vendor directory otherwise
  dontUpdateAutotoolsGnuConfigScripts = true;

  buildInputs = [ rustc.llvm ] ++ lib.optionals stdenv.isDarwin [ Security ];
  buildInputs = [ rustPlatform.rust.rustc.llvm ]
    ++ lib.optionals stdenv.isDarwin [ Security ];

  # fixes: error: the option `Z` is only accepted on the nightly compiler
  RUSTC_BOOTSTRAP = 1;
@@ -27,8 +29,8 @@ rustPlatform.buildRustPackage {
  # [0]: https://github.com/rust-lang/rust/blob/f77f4d55bdf9d8955d3292f709bd9830c2fdeca5/src/bootstrap/builder.rs#L1543
  # [1]: https://github.com/rust-lang/rust/blob/f77f4d55bdf9d8955d3292f709bd9830c2fdeca5/compiler/rustc_codegen_ssa/src/back/linker.rs#L323-L331
  preFixup = lib.optionalString stdenv.isDarwin ''
    install_name_tool -add_rpath "${rustc}/lib" "$out/bin/clippy-driver"
    install_name_tool -add_rpath "${rustc}/lib" "$out/bin/cargo-clippy"
    install_name_tool -add_rpath "${rustPlatform.rust.rustc}/lib" "$out/bin/clippy-driver"
    install_name_tool -add_rpath "${rustPlatform.rust.rustc}/lib" "$out/bin/cargo-clippy"
  '';

  meta = with lib; {
+7 −1
Original line number Diff line number Diff line
@@ -83,7 +83,13 @@ in
      };
      cargo-auditable = self.callPackage ./cargo-auditable.nix { };
      cargo-auditable-cargo-wrapper = self.callPackage ./cargo-auditable-cargo-wrapper.nix { };
      clippy = self.callPackage ./clippy.nix { inherit Security; };
      clippy = 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;
        inherit Security;
      };
    });
  };
}