diff mbox series

[bug#53208,39/39] gnu: rust-analyzer: Make it out of box.

Message ID tencent_E94BF92F5B47A5DCB144B2F6793325352305@qq.com
State Accepted
Headers show
Series None | expand

Commit Message

Z572 Jan. 22, 2022, 4:37 a.m. UTC
looks like failed to send email yesterday

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> Z572 via Guix-patches via <guix-patches@gnu.org> writes:
>
>> +(define-public rust-src
>> +  (hidden-package
>> +   (package
>> +     (inherit rust-1.57)
>> +     (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
>> box."))))
>
> This cannot work, because, AFAIK, you can only inherit packages from the
> same module. So rust-src should be moved to rust.scm and made visible.

It can work, for example: fdik-libetpan and libetpan.
  fdik-libetpan is in (gnu packages pep), libetpan is in (gnu packages
  mail), fdik-libetpan inherit from libetpan, them are in different module.
  
>
>> +         (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 not get environment variable RUST_SRC_PATH, set it,
>> +               ;; make rust-analyzer 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))))))
>
> I tried to move the rust-src in rust.scm, as explained above, but when
> I do, installation of rust-analyzer fails during the `wrap-program'
> phases.

new patch move rust-src to rust.scm, and build rust-analyzer success.

>
>>           (replace 'install-license-files
>>             (lambda* (#:key outputs #:allow-other-keys)
>>               (let* ((out (assoc-ref outputs "out"))
>> @@ -1298,6 +1341,7 @@ (define-public rust-analyzer
>>                 (chdir "../..")
>>                 (install-file "LICENSE-MIT" doc)
>>                 (install-file "LICENSE-APACHE" doc)))))))
>> +    (inputs (list rust-src))
>
> Shouldn't it be a native-input?

Fix in new patch.

>
> Could you have a look at those issues? Thanks!
>
> Regards,

Comments

Nicolas Goaziou Jan. 22, 2022, 4:04 p.m. UTC | #1
Hello,

Z572 via Guix-patches via <guix-patches@gnu.org> writes:

> Fix in new patch.

Applied. Thank you.

Regards,
diff mbox series

Patch

From a3ea65ba89f7f369fd6d2f8bd557dd59645ed456 Mon Sep 17 00:00:00 2001
Message-Id: <a3ea65ba89f7f369fd6d2f8bd557dd59645ed456.1642764287.git.873216071@qq.com>
From: Z572 <873216071@qq.com>
Date: Fri, 21 Jan 2022 19:06:10 +0800
Subject: [PATCH] gnu: rust-analyzer: Make it 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.
---
 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 a31fabac36..8ffa3a9817 100644
--- a/gnu/packages/rust-apps.scm
+++ b/gnu/packages/rust-apps.scm
@@ -1408,6 +1408,30 @@  (define-public rust-analyzer
          (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 not get environment variable RUST_SRC_PATH, set it,
+               ;; make rust-analyzer 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"))
@@ -1416,6 +1440,7 @@  (define-public rust-analyzer
                (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 @@  (define-module (gnu packages rust)
   #: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 @@  (define rust-1.57
 ;;; 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."))))
-- 
2.34.0