Subject: [bug#31040] [PATCH] gnu: rust: Add rust 1.25.0 release and enable cargo tests

From: Nikolai Merinov <[email-masked]>
Date: Sat, 31 Mar 2018 00:40:40 +0500

* gnu/packages/rust.scm (rust-1.23): Add "patch-cargo-tests" stage to disable
tests that incompatible with guix build environemnt; start tests for "cargo"
on "check" stage.
(rust-1.24): Rename "rust" to "rust-1.24".
(rust): Add "rust" package for "1.25.0" release. Disable new cargo test that
required network access
---
 gnu/packages/rust.scm | 43 +++++++++++++++++++++++++++++++++++++++----
 1 file changed, 39 insertions(+), 4 deletions(-)

diff --git a/gnu/packages/rust.scm b/gnu/packages/rust.scm
index 70140579b..cbca2dc7e 100644
--- a/gnu/packages/rust.scm
+++ b/gnu/packages/rust.scm
@@ -179,9 +179,12 @@ in turn be used to build the final Rust.")
        #:phases
        (modify-phases %standard-phases
          (add-after 'unpack 'set-env
-           (lambda _
+           (lambda* (#:key inputs #:allow-other-keys)
+             ;; Disable test for cross compilation support
+             (setenv "CFG_DISABLE_CROSS_TESTS" "1")
              (setenv "SHELL" (which "sh"))
              (setenv "CONFIG_SHELL" (which "sh"))
+             (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
              ;; guix llvm-3.9.1 package installs only shared libraries
              (setenv "LLVM_LINK_SHARED" "1")
              #t))
@@ -204,7 +207,16 @@ in turn be used to build the final Rust.")
                ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html>
                (delete-file-recursively "src/test/run-make/linker-output-non-utf8")
                #t)))
-         (add-after 'patch-tests 'fix-mtime-bug
+         (add-after 'patch-tests 'patch-cargo-tests
+           (lambda* _
+             (substitute* "src/tools/cargo/tests/build.rs"
+               (("/usr/bin/env") (which "env"))
+               ;; Guix llvm compiled without asmjs-unknown-emscripten at all
+               (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs"))
+             (substitute* "src/tools/cargo/tests/death.rs"
+               ;; Stuck when built in container
+               (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone"))))
+         (add-after 'patch-cargo-tests 'fix-mtime-bug
            (lambda* _
              (substitute* "src/build_helper/lib.rs"
                ;; Bug in Rust code.
@@ -289,7 +301,8 @@ jemalloc = \"" jemalloc "/lib/libjemalloc_pic.a" "\"
              (invoke "./x.py" "build" "src/tools/cargo")))
          (replace 'check
            (lambda* _
-             (invoke "./x.py" "test")))
+             (invoke "./x.py" "test")
+             (invoke "./x.py" "test" "src/tools/cargo")))
          (replace 'install
            (lambda* (#:key outputs #:allow-other-keys)
              (invoke "./x.py" "install")
@@ -318,7 +331,7 @@ safety and thread safety guarantees.")
     ;; Dual licensed.
     (license (list license:asl2.0 license:expat))))
 
-(define-public rust
+(define-public rust-1.24
   (let ((base-rust rust-1.23))
     (package
       (inherit base-rust)
@@ -334,3 +347,25 @@ safety and thread safety guarantees.")
        (substitute-keyword-arguments (package-arguments base-rust)
          ((#:phases phases) `(modify-phases ,phases
                                (delete 'fix-mtime-bug))))))))
+
+(define-public rust
+  (let ((base-rust rust-1.24))
+    (package
+      (inherit base-rust)
+      (version "1.25.0")
+      (source
+       (rust-source version
+                    "0baxjr99311lvwdq0s38bipbnj72pn6fgbk6lcq7j555xq53mxpf"))
+      (native-inputs
+       (alist-replace "cargo-bootstrap" (list base-rust "cargo")
+                      (alist-replace "rustc-bootstrap" (list base-rust)
+                                     (package-native-inputs base-rust))))
+      (arguments
+       (substitute-keyword-arguments (package-arguments base-rust)
+         ((#:phases phases)
+          `(modify-phases ,phases
+             (add-after 'patch-cargo-tests 'patch-cargo-index-update
+               (lambda* _
+                 (substitute* "src/tools/cargo/tests/generate-lockfile.rs"
+                   ;; This test want to update crate index
+                   (("fn no_index_update") "#[ignore]\nfn no_index_update")))))))))))
-- 
2.16.2