From cd849893e7f9b6ad8c380b3ebc74ea92530f8c48 Mon Sep 17 00:00:00 2001
The goal is to provide standard rust tools as outputs of rustc. The tools we
were missing were rls, clippy, src, and rust-analyzer. as a separate output of
* gnu/packages/rust.scm (rust-1.46): [outputs] add rls, clippy, src, and
rust-analyzer, [arguments] alter phases to build, test, and install each new
output, [arguments] patch RUNPATHS of outputs that require it, [arguments]
delete all uninstall scripts from outputs, [arguments] delete all the install
gnu/packages/rust.scm | 145 +++++++++++++++++++++++++++++++-----------
1 file changed, 109 insertions(+), 36 deletions(-)
Toggle diff (210 lines)
diff --git a/gnu/packages/rust.scm b/gnu/packages/rust.scm
index f72f310169..8a09e1077e 100644
--- a/gnu/packages/rust.scm
+++ b/gnu/packages/rust.scm
;;; Copyright © 2020, 2021 Jakub Kądziołka <kuba@kadziolka.net>
;;; Copyright © 2020 Pierre Langlois <pierre.langlois@gmx.com>
;;; Copyright © 2020 Matthew Kraai <kraai@ftbfs.org>
+;;; Copyright © 2021 John Soo <jsoo1@asu.edu>
;;; This file is part of GNU Guix.
#:use-module (gnu packages jemalloc)
#:use-module (gnu packages linux)
#:use-module (gnu packages llvm)
+ #:use-module (gnu packages node)
#:use-module (gnu packages pkg-config)
#:use-module (gnu packages python)
#:use-module (gnu packages ssh)
@@ -1322,19 +1324,41 @@ move around."
"0a17jby2pd050s24cy4dfc0gzvgcl585v3vvyfilniyvjrqknsid")))
- (outputs (cons "rustfmt" (package-outputs base-rust)))
+ (outputs (append '("rustfmt" "rls" "src" "clippy" "rust-analyzer")
+ (package-outputs base-rust)))
+ `(("gcc-lib" ,gcc "lib")
+ ,@(package-inputs base-rust)))
+ ,@(package-native-inputs base-rust)))
(substitute-keyword-arguments (package-arguments base-rust)
+ (replace 'patch-cargo-checksums
+ ;; Generate checksums after patching generated files (in
+ ;; particular, vendor/jemalloc/rep/Makefile).
+ (use-modules (guix build cargo-utils))
+ (substitute* '("Cargo.lock"
+ "src/tools/rust-analyzer/Cargo.lock")
+ (("(checksum = )\".*\"" all name)
+ (string-append name "\"" ,%cargo-reference-hash "\"")))
+ (generate-all-checksums "vendor")
(invoke "./x.py" "build")
(invoke "./x.py" "build" "src/tools/cargo")
- (invoke "./x.py" "build" "src/tools/rustfmt")))
+ (invoke "./x.py" "build" "src/tools/rustfmt")
+ (invoke "./x.py" "build" "src/tools/clippy")
+ (invoke "./x.py" "build" "src/tools/rls")
+ (invoke "./x.py" "build"
+ "src/tools/rust-analyzer/crates/rust-analyzer")))
(string-append "-j" (number->string
@@ -1343,44 +1367,84 @@ move around."
(invoke "./x.py" parallel-job-spec "test"
(invoke "./x.py" parallel-job-spec "test"
- "src/tools/rustfmt"))))
+ ;; Clippy tests do not work. See
+ ;; https://github.com/rust-lang/rust/issues/78717
+ ;; Even with --stage 1, they fail to compile
+ ;; (invoke "./x.py" parallel-job-spec "test" "--stage" "1"
+ (substitute* "src/tools/rls/tests/client.rs"
+ (("fn client_dependency_typo_and_fix" all)
+ (string-append "#[ignore]\n" all)))
+ (invoke "./x.py" parallel-job-spec "test"
(lambda* (#:key outputs #:allow-other-keys)
(invoke "./x.py" "install")
+ (for-each delete-file-recursively
+ (find-files (assoc-ref outputs "out")
(substitute* "config.toml"
;; replace prefix to specific output
- (("prefix = \"[^\"]*\"")
- (string-append "prefix = \"" (assoc-ref outputs "cargo") "\"")))
- (invoke "./x.py" "install" "cargo")
- (substitute* "config.toml"
- ;; replace prefix to specific output
- (("prefix = \"[^\"]*\"")
- (string-append "prefix = \"" (assoc-ref outputs "rustfmt") "\"")))
- (invoke "./x.py" "install" "rustfmt")))
+ (define (install-component component)
+ (substitute* "config.toml"
+ ;; replace prefix to specific output
+ (("(tools =).*" all tools)
+ (string-append tools " [\"" component "\"]\n"))
+ (("prefix = \"[^\"]*\"")
+ "prefix = \"" (assoc-ref outputs component) "\"")))
+ (mkdir-p (assoc-ref outputs component))
+ (invoke "./x.py" "install" component)
+ (for-each delete-file-recursively
+ (find-files (assoc-ref outputs component)
+ (for-each install-component
+ (add-after 'install 'patch-tools-runpaths
+ (lambda* (#:key outputs inputs #:allow-other-keys)
+ (use-modules (ice-9 popen)
+ (define (patch-path path)
+ "patchelf --print-rpath " path))
+ (pipe (open-input-pipe read-rpath))
+ (current-rpath (get-string-all pipe))
+ (out (assoc-ref outputs "out"))
+ (libc (assoc-ref inputs "libc"))
+ (gcc-lib (assoc-ref inputs "gcc-lib")))
+ (invoke "patchelf" "--set-rpath"
+ (string-append current-rpath
+ (define (patch-component component)
+ (find-files (assoc-ref outputs component)
+ (lambda (p s) (executable-file? p)))))
+ (for-each patch-component '("clippy" "rls"))))
(replace 'delete-install-logs
(lambda* (#:key outputs #:allow-other-keys)
- (define (delete-manifest-file out-path file)
- (delete-file (string-append out-path "/lib/rustlib/" file)))
- (let ((out (assoc-ref outputs "out"))
- (cargo-out (assoc-ref outputs "cargo"))
- (rustfmt-out (assoc-ref outputs "rustfmt")))
- (lambda (file) (delete-manifest-file out file))
- ,(string-append "manifest-rust-std-"
- (nix-system->gnu-triplet-for-rust))
- (lambda (file) (delete-manifest-file cargo-out file))
- (lambda (file) (delete-manifest-file rustfmt-out file))
- "manifest-rustfmt-preview"))
+ (define log-manifest-re
+ "^install\\.log$|^manifest-([a-z]|[0-9]|_|-)+(-preview)?$")
+ (define (delete-install-log output)
+ (for-each delete-file-recursively
+ (find-files output log-manifest-re)))
+ (for-each delete-install-log (map cdr outputs)))))))))))
@@ -1413,7 +1477,8 @@ move around."
;; particular, vendor/jemalloc/rep/Makefile).
(use-modules (guix build cargo-utils))
- (substitute* "Cargo.lock"
+ (substitute* '("Cargo.lock"
+ "src/tools/rust-analyzer/Cargo.lock")
(("(checksum = )\".*\"" all name)
(string-append name "\"" ,%cargo-reference-hash "\"")))
(generate-all-checksums "vendor")
@@ -1445,7 +1510,15 @@ move around."
(("fn test_process_mask") "#[allow(unused_attributes)]
+ ;; FIXME: This fixes the "src" output which is not critical. We
+ ;; should probably copy the source of the de-vendored libunwind
+ ;; for completeness' sake.
+ (add-before 'install 'remove-vendored-llvm-reference-in-src
+ (substitute* "src/bootstrap/dist.rs"
+ ((", \"src/llvm-project/libunwind\"") ""))
(rust-bootstrapped-package rust-1.48 "1.49.0"