summary refs log tree commit diff
path: root/pkgs/development/compilers/rust/clippy.nix
blob: 018aba1f35682c01fd6cf0785fcad8fc96e10718 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
{ stdenv, lib, rustPlatform, Security, patchelf }:

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

  separateDebugInfo = true;

  # the rust source tarball already has all the dependencies vendored, no need to fetch them again
  cargoVendorDir = "vendor";
  buildAndTestSubdir = "src/tools/clippy";

  # changes hash of vendor directory otherwise
  dontUpdateAutotoolsGnuConfigScripts = true;

  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;

  # Without disabling the test the build fails with:
  # error: failed to run custom build command for `rustc_llvm v0.0.0
  #   (/private/tmp/nix-build-clippy-1.36.0.drv-0/rustc-1.36.0-src/src/librustc_llvm)
  doCheck = false;

  # Clippy uses the rustc_driver and std private libraries, and Rust's build process forces them to have
  # an install name of `@rpath/...` [0] [1] instead of the standard on macOS, which is an absolute path
  # to itself.
  #
  # [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 "${rustPlatform.rust.rustc}/lib" "$out/bin/clippy-driver"
    install_name_tool -add_rpath "${rustPlatform.rust.rustc}/lib" "$out/bin/cargo-clippy"
  '';

  meta = with lib; {
    homepage = "https://rust-lang.github.io/rust-clippy/";
    description = "A bunch of lints to catch common mistakes and improve your Rust code";
    maintainers = with maintainers; [ basvandijk ] ++ teams.rust.members;
    license = with licenses; [ mit asl20 ];
    platforms = platforms.unix;
  };
}