guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: gnu: rust-analyzer: Make it work out of the box.


From: guix-commits
Subject: branch master updated: gnu: rust-analyzer: Make it work out of the box.
Date: Sat, 22 Jan 2022 11:04:01 -0500

This is an automated email from the git hooks/post-receive script.

ngz pushed a commit to branch master
in repository guix.

The following commit(s) were added to refs/heads/master by this push:
     new d96f47f012 gnu: rust-analyzer: Make it work out of the box.
d96f47f012 is described below

commit d96f47f012571cdd6dd67c513e496042db303ca7
Author: Z572 via Guix-patches via <guix-patches@gnu.org>
AuthorDate: Sat Jan 22 12:37:10 2022 +0800

    gnu: rust-analyzer: Make it work out of the box.
    
    * gnu/packages/rust.scm (rust-src): New variable.
    * gnu/packages/rust-apps.scm (rust-analyzer): [native-inputs]: Add rust-src.
    [arguments]: <#:phases>: Add wrap-program phase.
    
    Signed-off-by: Nicolas Goaziou <mail@nicolasgoaziou.fr>
---
 gnu/packages/rust-apps.scm | 25 +++++++++++++++++++++++++
 gnu/packages/rust.scm      | 20 ++++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/gnu/packages/rust-apps.scm b/gnu/packages/rust-apps.scm
index bdfc5f7dfd..d2cc949667 100644
--- a/gnu/packages/rust-apps.scm
+++ b/gnu/packages/rust-apps.scm
@@ -1492,6 +1492,30 @@ background agent taking care of maintaining the 
necessary state.")
          (add-before 'install 'chdir
            (lambda _
              (chdir "crates/rust-analyzer")))
+         (add-after 'install 'wrap-program
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (bin (string-append out "/bin"))
+                    (rust-src-path (search-input-directory
+                                    inputs "/lib/rustlib/src/rust/library")))
+               ;; if environment variable RUST_SRC_PATH is not set, set it,
+               ;; make rust-analyzer work out of box.
+               (with-directory-excursion bin
+                 (let* ((prog "rust-analyzer")
+                        (wrapped-file (string-append (dirname prog)
+                                                     "/." (basename prog) 
"-real"))
+                        (prog-tmp (string-append wrapped-file "-tmp")))
+                   (link prog wrapped-file)
+                   (call-with-output-file prog-tmp
+                     (lambda (port)
+                       (format port "#!~a
+if test -z \"${RUST_SRC_PATH}\";then export RUST_SRC_PATH=~S;fi;
+exec -a \"$0\" \"~a\" \"$@\""
+                               (which "bash")
+                               rust-src-path
+                               (canonicalize-path wrapped-file))))
+                   (chmod prog-tmp #o755)
+                   (rename-file prog-tmp prog))))))
          (replace 'install-license-files
            (lambda* (#:key outputs #:allow-other-keys)
              (let* ((out (assoc-ref outputs "out"))
@@ -1500,6 +1524,7 @@ background agent taking care of maintaining the necessary 
state.")
                (chdir "../..")
                (install-file "LICENSE-MIT" doc)
                (install-file "LICENSE-APACHE" doc)))))))
+    (native-inputs (list rust-src))
     (home-page "https://rust-analyzer.github.io/";)
     (synopsis "Experimental Rust compiler front-end for IDEs")
     (description "Rust-analyzer is a modular compiler frontend for the Rust
diff --git a/gnu/packages/rust.scm b/gnu/packages/rust.scm
index 739ffb3192..5a6d4a5c30 100644
--- a/gnu/packages/rust.scm
+++ b/gnu/packages/rust.scm
@@ -13,6 +13,7 @@
 ;;; Copyright © 2020 Matthew James Kraai <kraai@ftbfs.org>
 ;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2021 (unmatched parenthesis <paren@disroot.org>
+;;; Copyright © 2022 Zheng Junjie <873216071@qq.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -49,6 +50,7 @@
   #:use-module (gnu packages tls)
   #:use-module (gnu packages)
   #:use-module (guix build-system cargo)
+  #:use-module (guix build-system copy)
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system trivial)
   #:use-module (guix download)
@@ -787,3 +789,21 @@ safety and thread safety guarantees.")
 ;;; be relied upon.  This is to ease maintenance and reduce the time
 ;;; required to build the full Rust bootstrap chain.
 (define-public rust rust-1.57)
+
+(define-public rust-src
+  (hidden-package
+   (package
+     (inherit rust)
+     (name "rust-src")
+     (build-system copy-build-system)
+     (native-inputs '())
+     (inputs '())
+     (native-search-paths '())
+     (outputs '("out"))
+     (arguments
+      `(#:install-plan
+        '(("library" "lib/rustlib/src/rust/library")
+          ("src" "lib/rustlib/src/rust/src"))))
+     (synopsis "Source code for the Rust standard library")
+     (description "This package provide source code for the Rust standard
+library, only use by rust-analyzer, make rust-analyzer out of the box."))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]