about summary refs log tree commit diff
path: root/pkgs/development/tools/rust
diff options
context:
space:
mode:
authorJörg Thalheim <Mic92@users.noreply.github.com>2020-04-14 10:19:59 +0100
committerGitHub <noreply@github.com>2020-04-14 10:19:59 +0100
commit418b24b133769713e0b97e20898c46b8eb55b432 (patch)
tree857db47d7aa6bd77c9f680be6814ad618d4b959b /pkgs/development/tools/rust
parent46f06e083bd2d1098331ffb6ce36a667e3281d18 (diff)
parent3104237387bebf4c2662881f92c3278e0206e6c3 (diff)
downloadnixlib-418b24b133769713e0b97e20898c46b8eb55b432.tar
nixlib-418b24b133769713e0b97e20898c46b8eb55b432.tar.gz
nixlib-418b24b133769713e0b97e20898c46b8eb55b432.tar.bz2
nixlib-418b24b133769713e0b97e20898c46b8eb55b432.tar.lz
nixlib-418b24b133769713e0b97e20898c46b8eb55b432.tar.xz
nixlib-418b24b133769713e0b97e20898c46b8eb55b432.tar.zst
nixlib-418b24b133769713e0b97e20898c46b8eb55b432.zip
Merge pull request #77752 from oxalica/rust-analyzer
rust-analyzer: init at unstable-2020-03-09
Diffstat (limited to 'pkgs/development/tools/rust')
-rw-r--r--pkgs/development/tools/rust/rust-analyzer/default.nix14
-rw-r--r--pkgs/development/tools/rust/rust-analyzer/generic.nix45
-rwxr-xr-xpkgs/development/tools/rust/rust-analyzer/update.sh61
-rw-r--r--pkgs/development/tools/rust/rust-analyzer/wrapper.nix16
4 files changed, 136 insertions, 0 deletions
diff --git a/pkgs/development/tools/rust/rust-analyzer/default.nix b/pkgs/development/tools/rust/rust-analyzer/default.nix
new file mode 100644
index 000000000000..ec500db47d98
--- /dev/null
+++ b/pkgs/development/tools/rust/rust-analyzer/default.nix
@@ -0,0 +1,14 @@
+{ pkgs, callPackage }:
+
+{
+  rust-analyzer-unwrapped = callPackage ./generic.nix rec {
+    rev = "2020-04-06";
+    version = "unstable-${rev}";
+    sha256 = "0cm12707rq88w9yd4kkh26pnaqfvif6yyshk42pfi9vyv4ljfpcv";
+    cargoSha256 = "0q1qwji407pmklwb27z2jwyrvwyn8zkmrwm4nbcgk53ci4p6a17k";
+  };
+
+  rust-analyzer = callPackage ./wrapper.nix {} {
+    unwrapped = pkgs.rust-analyzer-unwrapped;
+  };
+}
diff --git a/pkgs/development/tools/rust/rust-analyzer/generic.nix b/pkgs/development/tools/rust/rust-analyzer/generic.nix
new file mode 100644
index 000000000000..de755ec17ff5
--- /dev/null
+++ b/pkgs/development/tools/rust/rust-analyzer/generic.nix
@@ -0,0 +1,45 @@
+{ 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;
+  };
+
+  preBuild = "pushd crates/rust-analyzer";
+  # Do not checking other crates in checkPhase.
+  preInstall = "popd";
+
+  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;
+  };
+}
diff --git a/pkgs/development/tools/rust/rust-analyzer/update.sh b/pkgs/development/tools/rust/rust-analyzer/update.sh
new file mode 100755
index 000000000000..929112542596
--- /dev/null
+++ b/pkgs/development/tools/rust/rust-analyzer/update.sh
@@ -0,0 +1,61 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i bash -p curl jq nix-prefetch
+set -euo pipefail
+cd "$(dirname "$0")"
+owner=rust-analyzer
+repo=rust-analyzer
+nixpkgs=../../../../..
+
+# Update lsp
+
+rev=$(
+    curl -s "https://api.github.com/repos/$owner/$repo/releases" |
+    jq 'map(select(.prerelease | not)) | .[0].tag_name' --raw-output
+)
+old_rev=$(sed -nE 's/.*\brev = "(.*)".*/\1/p' ./default.nix)
+if grep -q 'cargoSha256 = ""' ./default.nix; then
+    old_rev='broken'
+fi
+if [[ "$rev" == "$old_rev" ]]; then
+    echo "Up to date: $rev"
+    exit
+fi
+echo "$old_rev -> $rev"
+
+sha256=$(nix-prefetch -f "$nixpkgs" rust-analyzer-unwrapped.src --rev "$rev")
+# Clear cargoSha256 to avoid inconsistency.
+sed -e "s/rev = \".*\"/rev = \"$rev\"/" \
+    -e "s/sha256 = \".*\"/sha256 = \"$sha256\"/" \
+    -e "s/cargoSha256 = \".*\"/cargoSha256 = \"\"/" \
+    --in-place ./default.nix
+node_src="$(nix-build "$nixpkgs" -A rust-analyzer.src --no-out-link)/editors/code"
+
+# Check vscode compatibility
+req_vscode_ver="$(jq '.engines.vscode' "$node_src/package.json" --raw-output)"
+req_vscode_ver="${req_vscode_ver#^}"
+cur_vscode_ver="$(nix eval --raw -f "$nixpkgs" vscode.version)"
+if [[ "$(nix eval "(builtins.compareVersions \"$req_vscode_ver\" \"$cur_vscode_ver\")")" -gt 0 ]]; then
+    echo "vscode $cur_vscode_ver is incompatible with the extension requiring ^$req_vscode_ver"
+    exit 1
+fi
+
+echo "Prebuilding for cargoSha256"
+cargo_sha256=$(nix-prefetch "{ sha256 }: (import $nixpkgs {}).rust-analyzer-unwrapped.cargoDeps.overrideAttrs (_: { outputHash = sha256; })")
+sed "s/cargoSha256 = \".*\"/cargoSha256 = \"$cargo_sha256\"/" \
+    --in-place ./default.nix
+
+# Update vscode extension
+
+build_deps="../../../../misc/vscode-extensions/rust-analyzer/build-deps"
+# We need devDependencies to build vsix.
+jq '{ name, version, dependencies: (.dependencies + .devDependencies) }' "$node_src/package.json" \
+    >"$build_deps/package.json"
+
+# FIXME: Lock the version of @type/vscode, the latest one (1.43.0) will cause build failure.
+vscode_lock_ver="$(jq '.dependencies."@types/vscode".version' --raw-output "$node_src/package-lock.json")"
+jq '.dependencies."@types/vscode" = "'$vscode_lock_ver'"' "$build_deps/package.json" >"$build_deps/package.json.new"
+mv "$build_deps"/package.json{.new,}
+
+pushd "../../../node-packages"
+./generate.sh
+popd
diff --git a/pkgs/development/tools/rust/rust-analyzer/wrapper.nix b/pkgs/development/tools/rust/rust-analyzer/wrapper.nix
new file mode 100644
index 000000000000..8ca3ff1a6d20
--- /dev/null
+++ b/pkgs/development/tools/rust/rust-analyzer/wrapper.nix
@@ -0,0 +1,16 @@
+{ lib, rustPlatform, runCommandNoCC, makeWrapper }:
+
+lib.makeOverridable ({
+  unwrapped,
+  pname ? "rust-analyzer",
+  version ? unwrapped.version,
+  rustcSrc ? rustPlatform.rustcSrc,
+}: runCommandNoCC "${pname}-${version}" {
+  inherit pname version;
+  inherit (unwrapped) src meta;
+  nativeBuildInputs = [ makeWrapper ];
+} ''
+  mkdir -p $out/bin
+  makeWrapper ${unwrapped}/bin/rust-analyzer $out/bin/rust-analyzer \
+    --set-default RUST_SRC_PATH "${rustcSrc}"
+'')