1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016 David Craven <david@craven.ch>
3 ;;; Copyright © 2016 Eric Le Bihan <eric.le.bihan.dev@free.fr>
4 ;;; Copyright © 2016 ng0 <ng0@n0.is>
5 ;;; Copyright © 2017 Ben Woodcroft <donttrustben@gmail.com>
6 ;;; Copyright © 2017, 2018 Nikolai Merinov <nikolai.merinov@member.fsf.org>
7 ;;; Copyright © 2017, 2019 Efraim Flashner <efraim@flashner.co.il>
8 ;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
9 ;;; Copyright © 2018 Danny Milosavljevic <dannym+a@scratchpost.org>
10 ;;; Copyright © 2019 Ivan Petkov <ivanppetkov@gmail.com>
12 ;;; This file is part of GNU Guix.
14 ;;; GNU Guix is free software; you can redistribute it and/or modify it
15 ;;; under the terms of the GNU General Public License as published by
16 ;;; the Free Software Foundation; either version 3 of the License, or (at
17 ;;; your option) any later version.
19 ;;; GNU Guix is distributed in the hope that it will be useful, but
20 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;;; GNU General Public License for more details.
24 ;;; You should have received a copy of the GNU General Public License
25 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
27 (define-module (gnu packages rust)
28 #:use-module (gnu packages base)
29 #:use-module (gnu packages bison)
30 #:use-module (gnu packages bootstrap)
31 #:use-module (gnu packages cmake)
32 #:use-module (gnu packages compression)
33 #:use-module (gnu packages curl)
34 #:use-module (gnu packages elf)
35 #:use-module (gnu packages flex)
36 #:use-module (gnu packages gcc)
37 #:use-module (gnu packages gdb)
38 #:use-module (gnu packages jemalloc)
39 #:use-module (gnu packages linux)
40 #:use-module (gnu packages llvm)
41 #:use-module (gnu packages pkg-config)
42 #:use-module (gnu packages python)
43 #:use-module (gnu packages ssh)
44 #:use-module (gnu packages tls)
45 #:use-module (gnu packages)
46 #:use-module (guix build-system cargo)
47 #:use-module (guix build-system gnu)
48 #:use-module (guix build-system trivial)
49 #:use-module (guix download)
50 #:use-module (guix git-download)
51 #:use-module ((guix licenses) #:prefix license:)
52 #:use-module (guix packages)
53 #:use-module ((guix build utils) #:select (alist-replace))
54 #:use-module (guix utils)
55 #:use-module (ice-9 match)
56 #:use-module (srfi srfi-26))
58 (define %cargo-reference-hash
59 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
61 (define* (nix-system->gnu-triplet-for-rust
62 #:optional (system (%current-system)))
64 ("x86_64-linux" "x86_64-unknown-linux-gnu")
65 ("i686-linux" "i686-unknown-linux-gnu")
66 ("armhf-linux" "armv7-unknown-linux-gnueabihf")
67 ("aarch64-linux" "aarch64-unknown-linux-gnu")
68 ("mips64el-linux" "mips64el-unknown-linux-gnuabi64")
69 (_ (nix-system->gnu-triplet system))))
71 (define* (rust-uri version #:key (dist "static"))
72 (string-append "https://" dist ".rust-lang.org/dist/"
73 "rustc-" version "-src.tar.gz"))
75 (define* (rust-bootstrapped-package base-rust version checksum)
76 "Bootstrap rust VERSION with source checksum CHECKSUM using BASE-RUST."
82 (inherit (package-source base-rust))
83 (uri (rust-uri version))
84 (sha256 (base32 checksum))))
86 (alist-replace "cargo-bootstrap" (list base-rust "cargo")
87 (alist-replace "rustc-bootstrap" (list base-rust)
88 (package-native-inputs base-rust))))))
91 (let ((rustc-version "1.19.0"))
98 (url "https://github.com/thepowersgang/mrustc.git")
99 (commit (string-append "v" version))))
100 (file-name (git-file-name name version))
103 "194ny7vsks5ygiw7d8yxjmp1qwigd71ilchis6xjl6bb2sj97rd2"))))
104 (outputs '("out" "cargo"))
105 (build-system gnu-build-system)
111 ;; Required for the libstd sources.
112 ("rustc" ,(package-source rust-1.19))))
114 `(#:test-target "test"
116 (list ,(string-append "RUSTC_TARGET="
117 (or (%current-target-system)
118 (nix-system->gnu-triplet-for-rust))))
120 (modify-phases %standard-phases
121 (add-after 'unpack 'patch-date
123 (substitute* "Makefile"
124 (("shell date") "shell date -d @1"))
125 (substitute* "run_rustc/Makefile"
126 (("[$]Vtime ") "$V "))
128 (add-after 'patch-date 'unpack-target-compiler
129 (lambda* (#:key inputs outputs #:allow-other-keys)
130 (invoke "tar" "xf" (assoc-ref inputs "rustc"))
131 (chdir ,(string-append "rustc-" rustc-version "-src"))
132 (invoke "patch" "-p0" ,(string-append "../rustc-" rustc-version
135 (setenv "RUSTC_VERSION" ,rustc-version)
136 (setenv "MRUSTC_TARGET_VER"
137 ,(version-major+minor rustc-version))
138 (setenv "OUTDIR_SUF" "")
141 (lambda* (#:key inputs #:allow-other-keys)
142 (setenv "CC" (string-append (assoc-ref inputs "gcc")
144 (setenv "CXX" (string-append (assoc-ref inputs "gcc")
147 (add-after 'build 'build-minicargo
148 (lambda* (#:key make-flags #:allow-other-keys)
149 ;; TODO: minicargo.mk: RUSTC_VERSION=$(RUSTC_VERSION) RUSTC_CHANNEL=$(RUSTC_SRC_TY) OUTDIR_SUF=$(OUTDIR_SUF)
150 (apply invoke "make" "-f" "minicargo.mk" "LIBS" make-flags)
151 (apply invoke "make" "-C" "tools/minicargo" make-flags)))
152 ;(add-after 'check 'check-locally
153 ; (lambda* (#:key make-flags #:allow-other-keys)
154 ; ;; The enum test wouldn't work otherwise.
155 ; ;; See <https://github.com/thepowersgang/mrustc/issues/137>.
156 ; (setenv "MRUSTC_TARGET_VER" ,(version-major+minor rustc-version))
157 ; (apply invoke "make" "local_tests" make-flags)))
159 (lambda* (#:key inputs outputs #:allow-other-keys)
160 (let* ((out (assoc-ref outputs "out"))
161 (bin (string-append out "/bin"))
162 (tools-bin (string-append out "/tools/bin"))
163 (cargo-out (assoc-ref outputs "cargo"))
164 (cargo-bin (string-append cargo-out "/bin"))
165 (lib (string-append out "/lib"))
166 (lib/rust (string-append lib "/mrust"))
167 (gcc (assoc-ref inputs "gcc"))
168 (run_rustc (string-append out
169 "/share/mrustc/run_rustc")))
170 ;; These files are not reproducible.
171 (for-each delete-file (find-files "output" "\\.txt$"))
172 ;(delete-file-recursively "output/local_tests")
173 (mkdir-p (dirname lib/rust))
174 (copy-recursively "output" lib/rust)
177 (install-file "bin/mrustc" bin)
178 ;; minicargo uses relative paths to resolve mrustc.
179 (install-file "tools/bin/minicargo" tools-bin)
180 (install-file "tools/bin/minicargo" cargo-bin)
182 (copy-file "run_rustc/Makefile"
183 (string-append run_rustc "/Makefile"))
185 (synopsis "Compiler for the Rust progamming language")
186 (description "Rust is a systems programming language that provides memory
187 safety and thread safety guarantees.")
188 (home-page "https://github.com/thepowersgang/mrustc")
190 (license (list license:asl2.0 license:expat)))))
199 (uri (rust-uri "1.19.0"))
200 (sha256 (base32 "0l8c14qsf42rmkqy92ahij4vf356dbyspxcips1aswpvad81y8qm"))
201 (modules '((guix build utils)))
202 (snippet '(begin (delete-file-recursively "src/llvm") #t))
203 (patches (map search-patch '("rust-1.19-mrustc.patch")))))
204 (outputs '("out" "cargo"))
205 (properties '((timeout . 72000) ;20 hours
206 (max-silent-time . 18000))) ;5 hours (for armel)
208 `(#:imported-modules ,%cargo-utils-modules ;for `generate-all-checksums'
209 #:modules ((guix build utils) (ice-9 match) (guix build gnu-build-system))
211 (modify-phases %standard-phases
212 (add-after 'unpack 'set-env
213 (lambda* (#:key inputs #:allow-other-keys)
214 ;; Disable test for cross compilation support.
215 (setenv "CFG_DISABLE_CROSS_TESTS" "1")
216 (setenv "SHELL" (which "sh"))
217 (setenv "CONFIG_SHELL" (which "sh"))
218 (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
219 ;; guix llvm-3.9.1 package installs only shared libraries
220 (setenv "LLVM_LINK_SHARED" "1")
222 (add-after 'unpack 'patch-cargo-tomls
223 (lambda* (#:key inputs outputs #:allow-other-keys)
224 (substitute* "src/librustc_errors/Cargo.toml"
225 (("[[]dependencies[]]") "
229 (substitute* "src/librustc/Cargo.toml"
230 (("[[]dependencies[]]") "
232 getopts = { path = \"../libgetopts\" }
234 (substitute* "src/librustdoc/Cargo.toml"
235 (("[[]dependencies[]]") "
237 test = { path = \"../libtest\" }
240 (add-after 'unpack 'patch-tests
241 (lambda* (#:key inputs #:allow-other-keys)
242 (let ((bash (assoc-ref inputs "bash")))
243 (substitute* "src/libstd/process.rs"
244 ;; The newline is intentional.
245 ;; There's a line length "tidy" check in Rust which would
247 (("\"/bin/sh\"") (string-append "\n\"" bash "/bin/sh\"")))
248 (substitute* "src/libstd/net/tcp.rs"
249 ;; There is no network in build environment
250 (("fn connect_timeout_unroutable")
251 "#[ignore]\nfn connect_timeout_unroutable"))
252 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00222.html>
253 (substitute* "src/libstd/sys/unix/process/process_common.rs"
254 (("fn test_process_mask") "#[allow(unused_attributes)]
256 fn test_process_mask"))
258 (add-after 'patch-tests 'patch-aarch64-test
260 (substitute* "src/librustc_back/dynamic_lib.rs"
261 ;; This test is known to fail on aarch64 and powerpc64le:
262 ;; https://github.com/rust-lang/rust/issues/45410
263 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
265 (add-after 'patch-tests 'use-readelf-for-tests
267 ;; nm doesn't recognize the file format because of the
268 ;; nonstandard sections used by the Rust compiler, but readelf
270 (substitute* "src/test/run-make/atomic-lock-free/Makefile"
274 (add-after 'patch-tests 'remove-unsupported-tests
276 ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH.
277 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html>
278 (delete-file-recursively "src/test/run-make/linker-output-non-utf8")
280 (add-after 'patch-source-shebangs 'patch-cargo-checksums
282 (use-modules (guix build cargo-utils))
283 (substitute* "src/Cargo.lock"
284 (("(\"checksum .* = )\".*\"" all name)
285 (string-append name "\"" ,%cargo-reference-hash "\"")))
286 (generate-all-checksums "src/vendor")
288 ;; This phase is overridden by newer versions.
291 ;; This phase is overridden by newer versions.
293 (lambda* (#:key inputs outputs #:allow-other-keys)
294 (let ((rustc-bootstrap (assoc-ref inputs "rustc-bootstrap")))
295 (setenv "CFG_COMPILER_HOST_TRIPLE"
296 ,(nix-system->gnu-triplet (%current-system)))
297 (setenv "CFG_RELEASE" "")
298 (setenv "CFG_RELEASE_CHANNEL" "stable")
299 (setenv "CFG_LIBDIR_RELATIVE" "lib")
300 (setenv "CFG_VERSION" "1.19.0-stable-mrustc")
301 (setenv "MRUSTC_TARGET_VER" ,(version-major+minor version))
302 ; bad: (setenv "CFG_PREFIX" "mrustc") ; FIXME output path.
304 ;; mrustc 0.9 doesn't check the search paths for crates anymore.
305 (copy-recursively (string-append rustc-bootstrap "/lib/mrust")
307 (invoke (string-append rustc-bootstrap "/tools/bin/minicargo")
308 "src/rustc" "--vendor-dir" "src/vendor"
309 "--output-dir" "output/rustc-build"
310 "-L" (string-append rustc-bootstrap "/lib/mrust")
312 (setenv "CFG_COMPILER_HOST_TRIPLE" #f)
313 (setenv "CFG_RELEASE" #f)
314 (setenv "CFG_RELEASE_CHANNEL" #f)
315 (setenv "CFG_VERSION" #f)
316 (setenv "CFG_PREFIX" #f)
317 (setenv "CFG_LIBDIR_RELATIVE" #f)
318 (invoke (string-append rustc-bootstrap "/tools/bin/minicargo")
319 "src/tools/cargo" "--vendor-dir" "src/vendor"
320 "--output-dir" "output/cargo-build"
322 "-L" (string-append rustc-bootstrap "/lib/mrust")
324 ;; Now use the newly-built rustc to build the libraries.
325 ;; One day that could be replaced by:
326 ;; (invoke "output/cargo-build/cargo" "build"
327 ;; "--manifest-path" "src/bootstrap/Cargo.toml"
328 ;; "--verbose") ; "--locked" "--frozen"
329 ;; but right now, Cargo has problems with libstd's circular
331 (mkdir-p "output/target-libs")
332 (for-each (match-lambda
337 "output/rustc-build/rustc"
338 "-C" (string-append "linker="
340 ;; Required for libterm.
341 "-Z" "force-unstable-if-unmarked"
342 "-L" "output/target-libs"
343 (string-append "src/" name "/lib.rs")
345 (string-append "output/target-libs/"
346 (car (string-split name #\/))
354 ("liblibc/src" "--cfg" "stdbuild")
355 ("libunwind" "-l" "gcc_s")
356 ("libcompiler_builtins")
359 ;; Uses "cc" to link.
360 ("libstd" "-l" "dl" "-l" "rt" "-l" "pthread")
363 ;; Test dependencies:
369 ;; This phase is overridden by newer versions.
372 ;; This phase is overridden by newer versions.
374 (lambda* (#:key inputs outputs #:allow-other-keys)
375 (let* ((out (assoc-ref outputs "out"))
376 (target-system ,(or (%current-target-system)
377 (nix-system->gnu-triplet
379 (out-libs (string-append out "/lib/rustlib/"
380 target-system "/lib")))
381 ;(setenv "CFG_PREFIX" out)
383 (copy-recursively "output/target-libs" out-libs)
384 (install-file "output/rustc-build/rustc"
385 (string-append out "/bin"))
386 (install-file "output/rustc-build/rustdoc"
387 (string-append out "/bin"))
388 (install-file "output/cargo-build/cargo"
389 (string-append (assoc-ref outputs "cargo")
392 (build-system gnu-build-system)
394 `(("bison" ,bison) ; For the tests
395 ("cmake" ,cmake-minimal)
396 ("flex" ,flex) ; For the tests
397 ("gdb" ,gdb) ; For the tests
398 ("procps" ,procps) ; For the tests
399 ("python-2" ,python-2)
400 ("rustc-bootstrap" ,mrustc)
401 ("cargo-bootstrap" ,mrustc "cargo")
402 ("pkg-config" ,pkg-config) ; For "cargo"
405 `(("jemalloc" ,jemalloc-4.5.0)
407 ("openssl" ,openssl-1.0)
408 ("libssh2" ,libssh2) ; For "cargo"
409 ("libcurl" ,curl))) ; For "cargo"
411 ;; rustc invokes gcc, so we need to set its search paths accordingly.
412 ;; Note: duplicate its value here to cope with circular dependencies among
413 ;; modules (see <https://bugs.gnu.org/31392>).
415 (list (search-path-specification
416 (variable "C_INCLUDE_PATH")
417 (files '("include")))
418 (search-path-specification
419 (variable "CPLUS_INCLUDE_PATH")
420 (files '("include/c++" "include")))
421 (search-path-specification
422 (variable "LIBRARY_PATH")
423 (files '("lib" "lib64")))))
425 (synopsis "Compiler for the Rust progamming language")
426 (description "Rust is a systems programming language that provides memory
427 safety and thread safety guarantees.")
428 (home-page "https://www.rust-lang.org")
430 (license (list license:asl2.0 license:expat))))
432 (define-public rust-1.20
434 (rust-bootstrapped-package rust-1.19 "1.20.0"
435 "0542y4rnzlsrricai130mqyxl8r6rd991frb4qsnwb27yigqg91a")))
440 (inherit (package-source base-rust))
442 (delete-file-recursively "src/jemalloc")
443 (delete-file-recursively "src/llvm")
446 (outputs '("out" "doc" "cargo"))
447 ;; Since rust-1.19 is local, it's quite probable that Hydra
448 ;; will build rust-1.19 only as a dependency of rust-1.20.
449 ;; But then Hydra will use the wrong properties, the ones here,
450 ;; for rust-1.19. Therefore, we copied the properties of
452 (properties '((timeout . 72000) ;20 hours
453 (max-silent-time . 18000))) ;5 hours (for armel)
455 (substitute-keyword-arguments (package-arguments rust-1.19)
457 `(modify-phases ,phases
458 (add-after 'patch-tests 'patch-cargo-tests
460 (substitute* "src/tools/cargo/tests/build.rs"
461 (("/usr/bin/env") (which "env"))
462 ;; Guix llvm is compiled without asmjs-unknown-emscripten.
463 (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs"))
464 (substitute* "src/tools/cargo/tests/death.rs"
465 ;; This is stuck when built in container.
466 (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone"))
467 ;; Prints test output in the wrong order when built on
469 (substitute* "src/tools/cargo/tests/test.rs"
470 (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env"))
472 ;; These tests pull in a dependency on "git", which changes
473 ;; too frequently take part in the Rust toolchain.
474 (substitute* "src/tools/cargo/tests/new.rs"
475 (("fn author_prefers_cargo") "#[ignore]\nfn author_prefers_cargo")
476 (("fn finds_author_git") "#[ignore]\nfn finds_author_git")
477 (("fn finds_local_author_git") "#[ignore]\nfn finds_local_author_git"))
479 (add-after 'patch-cargo-tests 'ignore-glibc-2.27-incompatible-test
480 ;; https://github.com/rust-lang/rust/issues/47863
482 (substitute* "src/test/run-pass/out-of-stack.rs"
483 (("// ignore-android") "// ignore-test\n// ignore-android"))
486 (lambda* (#:key inputs outputs #:allow-other-keys)
487 (let* ((out (assoc-ref outputs "out"))
488 (doc (assoc-ref outputs "doc"))
489 (gcc (assoc-ref inputs "gcc"))
490 (gdb (assoc-ref inputs "gdb"))
491 (binutils (assoc-ref inputs "binutils"))
492 (python (assoc-ref inputs "python-2"))
493 (rustc (assoc-ref inputs "rustc-bootstrap"))
494 (cargo (assoc-ref inputs "cargo-bootstrap"))
495 (llvm (assoc-ref inputs "llvm"))
496 (jemalloc (assoc-ref inputs "jemalloc")))
497 (call-with-output-file "config.toml"
499 (display (string-append "
502 cargo = \"" cargo "/bin/cargo" "\"
503 rustc = \"" rustc "/bin/rustc" "\"
505 python = \"" python "/bin/python2" "\"
506 gdb = \"" gdb "/bin/gdb" "\"
511 docdir = \"" doc "/share/doc/rust" "\"
514 default-linker = \"" gcc "/bin/gcc" "\"
517 " ;; There are 2 failed codegen tests:
518 ;; codegen/mainsubprogram.rs and codegen/mainsubprogramstart.rs
519 ;; These tests require a patched LLVM
520 "codegen-tests = false
521 [target." ,(nix-system->gnu-triplet-for-rust) "]
522 llvm-config = \"" llvm "/bin/llvm-config" "\"
523 cc = \"" gcc "/bin/gcc" "\"
524 cxx = \"" gcc "/bin/g++" "\"
525 ar = \"" binutils "/bin/ar" "\"
526 jemalloc = \"" jemalloc "/lib/libjemalloc_pic.a" "\"
530 (add-after 'configure 'provide-cc
531 (lambda* (#:key inputs #:allow-other-keys)
532 (symlink (string-append (assoc-ref inputs "gcc") "/bin/gcc")
534 (setenv "PATH" (string-append "/tmp:" (getenv "PATH")))
536 (add-after 'provide-cc 'configure-archiver
537 (lambda* (#:key inputs #:allow-other-keys)
538 (substitute* "src/build_helper/lib.rs"
539 ;; Make sure "ar" is always used as the archiver.
540 (("\"musl\"") "\"\"")
541 ;; Then substitute "ar" by our name.
542 (("\"ar\"") (string-append "\""
543 (assoc-ref inputs "binutils")
546 (delete 'patch-cargo-tomls)
547 (add-before 'build 'reset-timestamps-after-changes
551 ;; Rust 1.20.0 treats timestamp 0 as "file doesn't exist".
552 ;; Therefore, use timestamp 1.
553 (utime filename 1 1 1 1))
554 (find-files "." #:directories? #t))
558 (invoke "./x.py" "build")
559 (invoke "./x.py" "build" "src/tools/cargo")))
562 ;; Disable parallel execution to prevent EAGAIN errors when
564 (invoke "./x.py" "-j1" "test" "-vv")
565 (invoke "./x.py" "-j1" "test" "src/tools/cargo")
568 (lambda* (#:key outputs #:allow-other-keys)
569 (invoke "./x.py" "install")
570 (substitute* "config.toml"
571 ;; replace prefix to specific output
572 (("prefix = \"[^\"]*\"")
573 (string-append "prefix = \"" (assoc-ref outputs "cargo") "\"")))
574 (invoke "./x.py" "install" "cargo")))
575 (add-after 'install 'delete-install-logs
576 (lambda* (#:key outputs #:allow-other-keys)
577 (define (delete-manifest-file out-path file)
578 (delete-file (string-append out-path "/lib/rustlib/" file)))
580 (let ((out (assoc-ref outputs "out"))
581 (cargo-out (assoc-ref outputs "cargo")))
583 (lambda (file) (delete-manifest-file out file))
586 "manifest-rust-std-x86_64-unknown-linux-gnu"
589 (lambda (file) (delete-manifest-file cargo-out file))
593 (add-after 'install 'wrap-rustc
594 (lambda* (#:key inputs outputs #:allow-other-keys)
595 (let ((out (assoc-ref outputs "out"))
596 (libc (assoc-ref inputs "libc"))
597 (ld-wrapper (assoc-ref inputs "ld-wrapper")))
598 ;; Let gcc find ld and libc startup files.
599 (wrap-program (string-append out "/bin/rustc")
600 `("PATH" ":" prefix (,(string-append ld-wrapper "/bin")))
601 `("LIBRARY_PATH" ":" suffix (,(string-append libc "/lib"))))
604 (define-public rust-1.21
605 (let ((base-rust (rust-bootstrapped-package rust-1.20 "1.21.0"
606 "1yj8lnxybjrybp00fqhxw8fpr641dh8wcn9mk44xjnsb4i1c21qp")))
610 (substitute-keyword-arguments (package-arguments base-rust)
612 `(modify-phases ,phases
613 (add-after 'configure 'remove-ar
614 (lambda* (#:key inputs #:allow-other-keys)
615 ;; Remove because toml complains about "unknown field".
616 (substitute* "config.toml"
620 (define-public rust-1.22
621 (let ((base-rust (rust-bootstrapped-package rust-1.21 "1.22.1"
622 "1lrzzp0nh7s61wgfs2h6ilaqi6iq89f1pd1yaf65l87bssyl4ylb")))
626 (substitute-keyword-arguments (package-arguments base-rust)
628 `(modify-phases ,phases
629 (add-after 'unpack 'remove-flaky-test
631 ;; See <https://github.com/rust-lang/rust/issues/43402>.
632 (when (file-exists? "src/test/run-make/issue-26092")
633 (delete-file-recursively "src/test/run-make/issue-26092"))
636 (define-public rust-1.23
637 (let ((base-rust (rust-bootstrapped-package rust-1.22 "1.23.0"
638 "14fb8vhjzsxlbi6yrn1r6fl5dlbdd1m92dn5zj5gmzfwf4w9ar3l")))
642 (substitute-keyword-arguments (package-arguments base-rust)
644 `(modify-phases ,phases
645 (delete 'configure-archiver)
647 (add-after 'unpack 'dont-build-native
649 ;; XXX: Revisit this when we use gcc 6.
650 (substitute* "src/binaryen/CMakeLists.txt"
651 (("ADD_COMPILE_FLAG\\(\\\"-march=native\\\"\\)") ""))
654 (define-public rust-1.24
656 (rust-bootstrapped-package rust-1.23 "1.24.1"
657 "1vv10x2h9kq7fxh2v01damdq8pvlp5acyh1kzcda9sfjx12kv99y")))
661 (substitute-keyword-arguments (package-arguments base-rust)
663 `(modify-phases ,phases
664 (delete 'use-readelf-for-tests)
665 (replace 'patch-aarch64-test
667 (substitute* "src/librustc_metadata/dynamic_lib.rs"
668 ;; This test is known to fail on aarch64 and powerpc64le:
669 ;; https://github.com/rust-lang/rust/issues/45410
670 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
673 ;;; Rust 1.25 release support work with llvm 6--but build with llvm 6 is
674 ;;; not determenistic due to <https://github.com/rust-lang/rust/issues/50556>.
675 ;;; Keep using llvm 3.9.1 until builds become determenistic
676 (define-public rust-1.25
678 (rust-bootstrapped-package rust-1.24 "1.25.0"
679 "0baxjr99311lvwdq0s38bipbnj72pn6fgbk6lcq7j555xq53mxpf")))
684 (inherit (package-source base-rust))
686 (delete-file-recursively "src/jemalloc")
687 (delete-file-recursively "src/llvm")
688 (delete-file-recursively "src/llvm-emscripten")
690 (patches (map search-patch
691 '("rust-1.25-accept-more-detailed-gdb-lines.patch")))))
693 (substitute-keyword-arguments (package-arguments base-rust)
695 `(modify-phases ,phases
696 (add-after 'patch-cargo-tests 'patch-cargo-index-update
698 (substitute* "src/tools/cargo/tests/generate-lockfile.rs"
699 ;; This test wants to update the crate index.
700 (("fn no_index_update") "#[ignore]\nfn no_index_update"))
702 (replace 'patch-aarch64-test
704 (substitute* "src/librustc_metadata/dynamic_lib.rs"
705 ;; This test is known to fail on aarch64 and powerpc64le:
706 ;; https://github.com/rust-lang/rust/issues/45410
707 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
708 ;; This test fails on aarch64 with llvm@6.0:
709 ;; https://github.com/rust-lang/rust/issues/49807
710 ;; other possible solution:
711 ;; https://github.com/rust-lang/rust/pull/47688
712 (delete-file "src/test/debuginfo/by-value-self-argument-in-trait-impl.rs")
714 (delete 'ignore-glibc-2.27-incompatible-test))))))))
716 (define-public rust-1.26
718 (rust-bootstrapped-package rust-1.25 "1.26.2"
719 "0047ais0fvmqvngqkdsxgrzhb0kljg8wy85b01kbbjc88hqcz7pv")))
724 (inherit (package-source base-rust))
725 (patches (map search-patch
726 '("rust-coresimd-doctest.patch"
727 "rust-1.25-accept-more-detailed-gdb-lines.patch")))))
729 (substitute-keyword-arguments (package-arguments base-rust)
731 `(modify-phases ,phases
732 ;; binaryen was replaced with LLD project from LLVM
733 (delete 'dont-build-native)
736 ;; Enable parallel execution.
737 (let ((parallel-job-spec
738 (string-append "-j" (number->string
740 (parallel-job-count))))))
741 (invoke "./x.py" parallel-job-spec "test" "-vv")
742 (invoke "./x.py" parallel-job-spec "test"
743 "src/tools/cargo"))))
744 (replace 'remove-unsupported-tests
746 ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH.
747 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html>
748 (delete-file-recursively "src/test/run-make-fulldeps/linker-output-non-utf8")
750 (replace 'patch-cargo-tests
752 (substitute* "src/tools/cargo/tests/testsuite/build.rs"
753 (("/usr/bin/env") (which "env"))
754 ;; Guix llvm is compiled without asmjs-unknown-emscripten.
755 (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs"))
756 (substitute* "src/tools/cargo/tests/testsuite/death.rs"
757 ;; This is stuck when built in container.
758 (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone"))
759 ;; Prints test output in the wrong order when built on
761 (substitute* "src/tools/cargo/tests/testsuite/test.rs"
762 (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env"))
764 ;; Avoid dependency on "git".
765 (substitute* "src/tools/cargo/tests/testsuite/new.rs"
766 (("fn author_prefers_cargo") "#[ignore]\nfn author_prefers_cargo")
767 (("fn finds_author_git") "#[ignore]\nfn finds_author_git")
768 (("fn finds_local_author_git") "#[ignore]\nfn finds_local_author_git"))
770 (add-after 'patch-cargo-tests 'disable-cargo-test-for-nightly-channel
772 ;; This test failed to work on "nightly" channel builds
773 ;; https://github.com/rust-lang/cargo/issues/5648
774 (substitute* "src/tools/cargo/tests/testsuite/resolve.rs"
775 (("fn test_resolving_minimum_version_with_transitive_deps")
776 "#[ignore]\nfn test_resolving_minimum_version_with_transitive_deps"))
778 (replace 'patch-cargo-index-update
780 (substitute* "src/tools/cargo/tests/testsuite/generate_lockfile.rs"
781 ;; This test wants to update the crate index.
782 (("fn no_index_update") "#[ignore]\nfn no_index_update"))
785 (define-public rust-1.27
787 (rust-bootstrapped-package rust-1.26 "1.27.2"
788 "0pg1s37bhx9zqbynxyydq5j6q7kij9vxkcv8maz0m25prm88r0cs")))
793 (inherit (package-source base-rust))
794 (patches (map search-patch '("rust-coresimd-doctest.patch"
795 "rust-bootstrap-stage0-test.patch"
796 "rust-1.25-accept-more-detailed-gdb-lines.patch"
797 "rust-reproducible-builds.patch")))))
799 ;; FIXME: Rust 1.27 and some later versions require GDB 8.2 specifically.
800 ;; See <https://bugs.gnu.org/37810>.
801 (alist-replace "gdb" (list gdb-8.2)
802 (package-native-inputs base-rust)))
804 (substitute-keyword-arguments (package-arguments base-rust)
806 `(modify-phases ,phases
807 (add-before 'install 'mkdir-prefix-paths
808 (lambda* (#:key outputs #:allow-other-keys)
809 ;; As result of https://github.com/rust-lang/rust/issues/36989
810 ;; `prefix' directory should exist before `install' call
811 (mkdir-p (assoc-ref outputs "out"))
812 (mkdir-p (assoc-ref outputs "cargo"))
814 (add-after 'patch-cargo-tests 'disable-thinlto-test
816 ;; thinlto required llvm 6.0 for work
817 (substitute* "src/tools/cargo/tests/testsuite/path.rs"
818 (("fn thin_lto_works") "#[ignore]\nfn thin_lto_works"))
821 (define-public rust-1.28
823 (rust-bootstrapped-package rust-1.27 "1.28.0"
824 "11k4rn77bca2rikykkk9fmprrgjswd4x4kaq7fia08vgkir82nhx")))
829 (inherit (package-source base-rust))
830 (patches (map search-patch '("rust-coresimd-doctest.patch"
831 "rust-bootstrap-stage0-test.patch"
832 "rust-1.25-accept-more-detailed-gdb-lines.patch"
833 "rust-reproducible-builds.patch")))))
836 (alist-replace "llvm" (list llvm-6)
837 (package-inputs base-rust)))
839 (substitute-keyword-arguments (package-arguments base-rust)
841 `(modify-phases ,phases
842 (add-after 'configure 'enable-codegen-tests
843 ;; Codegen tests should pass with llvm 6, so enable them.
845 (substitute* "config.toml"
846 (("codegen-tests = false") ""))
848 (add-after 'patch-tests 'disable-amd64-avx-test
849 ;; That test would fail on x86_64 machines without avx.
851 (substitute* "src/test/run-pass/issue-44056.rs"
852 (("only-x86_64") "ignore-test"))
854 ;; The thinlto test should pass with llvm 6.
855 (delete 'disable-thinlto-test))))))))
857 (define-public rust-1.29
859 (rust-bootstrapped-package rust-1.28 "1.29.2"
860 "1jb787080z754caa2w3w1amsygs4qlzj9rs1vy64firfmabfg22h")))
865 (inherit (package-source base-rust))
866 (patches (map search-patch '("rust-1.25-accept-more-detailed-gdb-lines.patch"
867 "rust-reproducible-builds.patch"))))))))
869 (define-public rust-1.30
871 (rust-bootstrapped-package rust-1.29 "1.30.1"
872 "0aavdc1lqv0cjzbqwl5n59yd0bqdlhn0zas61ljf38yrvc18k8rn")))
877 (inherit (package-source base-rust))
879 (delete-file-recursively "src/jemalloc")
880 (delete-file-recursively "src/llvm")
881 (delete-file-recursively "src/llvm-emscripten")
882 (delete-file-recursively "src/tools/clang")
883 (delete-file-recursively "src/tools/lldb")
886 (substitute-keyword-arguments (package-arguments base-rust)
888 `(modify-phases ,phases
889 (add-after 'patch-cargo-tests 'patch-cargo-env-shebang
890 (lambda* (#:key inputs #:allow-other-keys)
891 (let ((coreutils (assoc-ref inputs "coreutils")))
892 (substitute* "src/tools/cargo/tests/testsuite/fix.rs"
893 ;; Cargo has a test which explicitly sets a
894 ;; RUSTC_WRAPPER environment variable which points
895 ;; to /usr/bin/env. Since it's not a shebang, it
896 ;; needs to be manually patched
897 (("\"/usr/bin/env\"")
898 (string-append "\"" coreutils "/bin/env\"")))
900 (add-after 'patch-cargo-env-shebang 'ignore-cargo-package-tests
902 (substitute* "src/tools/cargo/tests/testsuite/package.rs"
903 ;; These tests largely check that cargo outputs warning/error
904 ;; messages as expected. It seems that cargo outputs an
905 ;; absolute path to something in the store instead of the
906 ;; expected relative path (e.g. `[..]`) so we'll ignore
908 (("fn include") "#[ignore]\nfn include")
909 (("fn exclude") "#[ignore]\nfn exclude"))
911 ;; The test has been moved elsewhere.
912 (replace 'disable-amd64-avx-test
914 (substitute* "src/test/ui/run-pass/issues/issue-44056.rs"
915 (("only-x86_64") "ignore-test"))
918 (define-public rust-1.31
920 (rust-bootstrapped-package rust-1.30 "1.31.1"
921 "0sk84ff0cklybcp0jbbxcw7lk7mrm6kb6km5nzd6m64dy0igrlli")))
925 (substitute-keyword-arguments (package-arguments base-rust)
927 `(modify-phases ,phases
928 (add-after 'patch-tests 'patch-command-exec-tests
929 (lambda* (#:key inputs #:allow-other-keys)
930 (let ((coreutils (assoc-ref inputs "coreutils")))
931 (substitute* "src/test/run-pass/command-exec.rs"
932 ;; This test suite includes some tests that the stdlib's
933 ;; `Command` execution properly handles situations where
934 ;; the environment or PATH variable are empty, but this
935 ;; fails since we don't have `echo` available in the usual
936 ;; Linux directories.
937 ;; NB: the leading space is so we don't fail a tidy check
938 ;; for trailing whitespace, and the newlines are to ensure
939 ;; we don't exceed the 100 chars tidy check as well
940 ((" Command::new\\(\"echo\"\\)")
941 (string-append "\nCommand::new(\"" coreutils "/bin/echo\")\n")))
943 ;; The test has been moved elsewhere.
944 (replace 'disable-amd64-avx-test
946 (substitute* "src/test/ui/issues/issue-44056.rs"
947 (("only-x86_64") "ignore-test"))
949 (add-after 'patch-tests 'patch-process-docs-rev-cmd
951 ;; Disable some doc tests which depend on the "rev" command
952 ;; https://github.com/rust-lang/rust/pull/58746
953 (substitute* "src/libstd/process.rs"
954 (("```rust") "```rust,no_run"))
957 (define-public rust-1.32
959 (rust-bootstrapped-package rust-1.31 "1.32.0"
960 "0ji2l9xv53y27xy72qagggvq47gayr5lcv2jwvmfirx029vlqnac")))
965 (inherit (package-source base-rust))
966 (snippet '(begin (delete-file-recursively "src/llvm")
967 (delete-file-recursively "src/llvm-emscripten")
968 (delete-file-recursively "src/tools/clang")
969 (delete-file-recursively "src/tools/lldb")
970 (delete-file-recursively "vendor/jemalloc-sys/jemalloc")
972 (patches (map search-patch '("rust-reproducible-builds.patch")))
973 ;; the vendor directory has moved to the root of
974 ;; the tarball, so we have to strip an extra prefix
975 (patch-flags '("-p2"))))
977 ;; Downgrade to LLVM 6, all LTO tests appear to fail with LLVM 7.0.1
978 (alist-replace "llvm" (list llvm-6)
979 (package-inputs base-rust)))
981 (substitute-keyword-arguments (package-arguments base-rust)
983 `(modify-phases ,phases
984 ;; Cargo.lock and the vendor/ directory have been moved to the
985 ;; root of the rust tarball
986 (replace 'patch-cargo-checksums
988 (use-modules (guix build cargo-utils))
989 (substitute* "Cargo.lock"
990 (("(\"checksum .* = )\".*\"" all name)
991 (string-append name "\"" ,%cargo-reference-hash "\"")))
992 (generate-all-checksums "vendor")
994 (add-after 'enable-codegen-tests 'override-jemalloc
995 (lambda* (#:key inputs #:allow-other-keys)
996 ;; The compiler is no longer directly built against jemalloc,
997 ;; but rather via the jemalloc-sys crate (which vendors the
998 ;; jemalloc source). To use jemalloc we must enable linking to
999 ;; it (otherwise it would use the system allocator), and set
1000 ;; an environment variable pointing to the compiled jemalloc.
1001 (substitute* "config.toml"
1002 (("^jemalloc =.*$") "")
1003 (("[[]rust[]]") "\n[rust]\njemalloc=true\n"))
1004 (setenv "JEMALLOC_OVERRIDE" (string-append (assoc-ref inputs "jemalloc")
1005 "/lib/libjemalloc_pic.a"))
1007 ;; Remove no longer relevant steps
1008 (delete 'remove-flaky-test)
1009 (delete 'patch-aarch64-test))))))))
1011 (define-public rust-1.33
1013 (rust-bootstrapped-package rust-1.32 "1.33.0"
1014 "152x91mg7bz4ygligwjb05fgm1blwy2i70s2j03zc9jiwvbsh0as")))
1019 (inherit (package-source base-rust))
1021 (patch-flags '("-p1"))))
1023 ;; Upgrade to jemalloc@5.1.0
1024 (alist-replace "jemalloc" (list jemalloc)
1025 (package-inputs base-rust)))
1027 (substitute-keyword-arguments (package-arguments base-rust)
1029 `(modify-phases ,phases
1030 (delete 'ignore-cargo-package-tests)
1031 (add-after 'configure 'configure-test-threads
1032 ;; Several rustc and cargo tests will fail if run on one core
1033 ;; https://github.com/rust-lang/rust/issues/59122
1034 ;; https://github.com/rust-lang/cargo/issues/6746
1035 ;; https://github.com/rust-lang/rust/issues/58907
1036 (lambda* (#:key inputs #:allow-other-keys)
1037 (setenv "RUST_TEST_THREADS" "2")
1040 (define-public rust-1.34
1042 (rust-bootstrapped-package rust-1.33 "1.34.1"
1043 "19s09k7y5j6g3y4d2rk6kg9pvq6ml94c49w6b72dmq8p9lk8bixh")))
1048 (inherit (package-source base-rust))
1050 (delete-file-recursively "src/llvm-emscripten")
1051 (delete-file-recursively "src/llvm-project")
1052 (delete-file-recursively "vendor/jemalloc-sys/jemalloc")
1055 (define-public rust-1.35
1057 (rust-bootstrapped-package rust-1.34 "1.35.0"
1058 "0bbizy6b7002v1rdhrxrf5gijclbyizdhkglhp81ib3bf5x66kas")))
1062 (alist-replace "llvm" (list llvm-8)
1063 (package-inputs base-rust)))
1065 (substitute-keyword-arguments (package-arguments base-rust)
1067 `(modify-phases ,phases
1068 ;; The tidy test includes a pass which ensures large binaries
1069 ;; don't accidentally get checked into the rust git repo.
1070 ;; Unfortunately the test assumes that git is always available,
1071 ;; so we'll comment out the invocation of this pass.
1072 (add-after 'configure 'disable-tidy-bins-check
1074 (substitute* "src/tools/tidy/src/main.rs"
1075 (("bins::check") "//bins::check"))
1078 (define-public rust-1.36
1080 (rust-bootstrapped-package rust-1.35 "1.36.0"
1081 "06xv2p6zq03lidr0yaf029ii8wnjjqa894nkmrm6s0rx47by9i04")))
1085 (substitute-keyword-arguments (package-arguments base-rust)
1087 `(modify-phases ,phases
1088 (delete 'patch-process-docs-rev-cmd))))))))
1092 (rust-bootstrapped-package rust-1.36 "1.37.0"
1093 "1hrqprybhkhs6d9b5pjskfnc5z9v2l2gync7nb39qjb5s0h703hj")))
1097 (substitute-keyword-arguments (package-arguments base-rust)
1099 `(modify-phases ,phases
1100 (add-before 'configure 'configure-cargo-home
1102 (let ((cargo-home (string-append (getcwd) "/.cargo")))
1103 (mkdir-p cargo-home)
1104 (setenv "CARGO_HOME" cargo-home)