nixpkgs/pkgs/development/tools/rust/rust-analyzer/generic.nix
Maximilian Bosch 6b23cfe689
rustPlatform: add buildAndTestSubdir-argument
There are several tarballs (such as the `rust-lang/rust`-source) with a
`Cargo.toml` at root and several sub-packages (with their own Cargo.toml)
without using workspaces[1].

In such a case it's needed to move into a subdir to only build the
specified sub-package (e.g. `rustfmt` or `rsl`), however the artifacts
are at `/target` in the root-dir of the build environment. This breaks
the build since `buildRustPackage` searches for executables in `target`
(which is at the build-env's root) at the end of the `buildPhase`.

With the optional `buildAndTestSubdir`-argument, the builder moves into
the specified subdir using `pushd`/`popd` during `buildPhase` and
`checkPhase`.

Also moved the logic to find executables and libs to the end of the `buildPhase`
from a custom `postBuild`-hook to fix packages with custom `build`/`install`-procedures
such as `uutils-coreutils`.

[1] https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html
2020-05-13 01:47:17 +02:00

44 lines
1.2 KiB
Nix

{ lib, stdenv, fetchFromGitHub, rustPlatform, darwin
, useJemalloc ? false
, doCheck ? true
# Version specific args
, rev, version, sha256, cargoSha256 }:
rustPlatform.buildRustPackage {
pname = "rust-analyzer-unwrapped";
inherit version cargoSha256;
src = fetchFromGitHub {
owner = "rust-analyzer";
repo = "rust-analyzer";
inherit rev sha256;
};
buildAndTestSubdir = "crates/rust-analyzer";
cargoBuildFlags = lib.optional useJemalloc "--features=jemalloc";
nativeBuildInputs = lib.optionals doCheck [ rustPlatform.rustcSrc ];
buildInputs = lib.optionals stdenv.hostPlatform.isDarwin
[ darwin.apple_sdk.frameworks.CoreServices ];
inherit doCheck;
# Skip tests running `rustup` for `cargo fmt`.
preCheck = ''
fakeRustup=$(mktemp -d)
ln -s $(command -v true) $fakeRustup/rustup
export PATH=$PATH''${PATH:+:}$fakeRustup
export RUST_SRC_PATH=${rustPlatform.rustcSrc}
'';
meta = with stdenv.lib; {
description = "An experimental modular compiler frontend for the Rust language";
homepage = "https://github.com/rust-analyzer/rust-analyzer";
license = with licenses; [ mit asl20 ];
maintainers = with maintainers; [ oxalica ];
platforms = platforms.all;
};
}