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 programming 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
417 (files '("include")))
418 (search-path-specification
419 (variable "LIBRARY_PATH")
420 (files '("lib" "lib64")))))
422 (synopsis "Compiler for the Rust progamming language")
423 (description "Rust is a systems programming language that provides memory
424 safety and thread safety guarantees.")
425 (home-page "https://www.rust-lang.org")
427 (license (list license:asl2.0 license:expat))))
429 (define-public rust-1.20
431 (rust-bootstrapped-package rust-1.19 "1.20.0"
432 "0542y4rnzlsrricai130mqyxl8r6rd991frb4qsnwb27yigqg91a")))
437 (inherit (package-source base-rust))
439 (delete-file-recursively "src/jemalloc")
440 (delete-file-recursively "src/llvm")
443 (outputs '("out" "doc" "cargo"))
444 ;; Since rust-1.19 is local, it's quite probable that Hydra
445 ;; will build rust-1.19 only as a dependency of rust-1.20.
446 ;; But then Hydra will use the wrong properties, the ones here,
447 ;; for rust-1.19. Therefore, we copied the properties of
449 (properties '((timeout . 72000) ;20 hours
450 (max-silent-time . 18000))) ;5 hours (for armel)
452 (substitute-keyword-arguments (package-arguments rust-1.19)
454 `(modify-phases ,phases
455 (add-after 'patch-tests 'patch-cargo-tests
457 (substitute* "src/tools/cargo/tests/build.rs"
458 (("/usr/bin/env") (which "env"))
459 ;; Guix llvm is compiled without asmjs-unknown-emscripten.
460 (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs"))
461 (substitute* "src/tools/cargo/tests/death.rs"
462 ;; This is stuck when built in container.
463 (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone"))
464 ;; Prints test output in the wrong order when built on
466 (substitute* "src/tools/cargo/tests/test.rs"
467 (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env"))
469 ;; These tests pull in a dependency on "git", which changes
470 ;; too frequently take part in the Rust toolchain.
471 (substitute* "src/tools/cargo/tests/new.rs"
472 (("fn author_prefers_cargo") "#[ignore]\nfn author_prefers_cargo")
473 (("fn finds_author_git") "#[ignore]\nfn finds_author_git")
474 (("fn finds_local_author_git") "#[ignore]\nfn finds_local_author_git"))
476 (add-after 'patch-cargo-tests 'ignore-glibc-2.27-incompatible-test
477 ;; https://github.com/rust-lang/rust/issues/47863
479 (substitute* "src/test/run-pass/out-of-stack.rs"
480 (("// ignore-android") "// ignore-test\n// ignore-android"))
483 (lambda* (#:key inputs outputs #:allow-other-keys)
484 (let* ((out (assoc-ref outputs "out"))
485 (doc (assoc-ref outputs "doc"))
486 (gcc (assoc-ref inputs "gcc"))
487 (gdb (assoc-ref inputs "gdb"))
488 (binutils (assoc-ref inputs "binutils"))
489 (python (assoc-ref inputs "python-2"))
490 (rustc (assoc-ref inputs "rustc-bootstrap"))
491 (cargo (assoc-ref inputs "cargo-bootstrap"))
492 (llvm (assoc-ref inputs "llvm"))
493 (jemalloc (assoc-ref inputs "jemalloc")))
494 (call-with-output-file "config.toml"
496 (display (string-append "
499 cargo = \"" cargo "/bin/cargo" "\"
500 rustc = \"" rustc "/bin/rustc" "\"
502 python = \"" python "/bin/python2" "\"
503 gdb = \"" gdb "/bin/gdb" "\"
508 docdir = \"" doc "/share/doc/rust" "\"
511 default-linker = \"" gcc "/bin/gcc" "\"
514 " ;; There are 2 failed codegen tests:
515 ;; codegen/mainsubprogram.rs and codegen/mainsubprogramstart.rs
516 ;; These tests require a patched LLVM
517 "codegen-tests = false
518 [target." ,(nix-system->gnu-triplet-for-rust) "]
519 llvm-config = \"" llvm "/bin/llvm-config" "\"
520 cc = \"" gcc "/bin/gcc" "\"
521 cxx = \"" gcc "/bin/g++" "\"
522 ar = \"" binutils "/bin/ar" "\"
523 jemalloc = \"" jemalloc "/lib/libjemalloc_pic.a" "\"
527 (add-after 'configure 'provide-cc
528 (lambda* (#:key inputs #:allow-other-keys)
529 (symlink (string-append (assoc-ref inputs "gcc") "/bin/gcc")
531 (setenv "PATH" (string-append "/tmp:" (getenv "PATH")))
533 (add-after 'provide-cc 'configure-archiver
534 (lambda* (#:key inputs #:allow-other-keys)
535 (substitute* "src/build_helper/lib.rs"
536 ;; Make sure "ar" is always used as the archiver.
537 (("\"musl\"") "\"\"")
538 ;; Then substitute "ar" by our name.
539 (("\"ar\"") (string-append "\""
540 (assoc-ref inputs "binutils")
543 (delete 'patch-cargo-tomls)
544 (add-before 'build 'reset-timestamps-after-changes
548 ;; Rust 1.20.0 treats timestamp 0 as "file doesn't exist".
549 ;; Therefore, use timestamp 1.
550 (utime filename 1 1 1 1))
551 (find-files "." #:directories? #t))
555 (invoke "./x.py" "build")
556 (invoke "./x.py" "build" "src/tools/cargo")))
559 ;; Disable parallel execution to prevent EAGAIN errors when
561 (invoke "./x.py" "-j1" "test" "-vv")
562 (invoke "./x.py" "-j1" "test" "src/tools/cargo")
565 (lambda* (#:key outputs #:allow-other-keys)
566 (invoke "./x.py" "install")
567 (substitute* "config.toml"
568 ;; replace prefix to specific output
569 (("prefix = \"[^\"]*\"")
570 (string-append "prefix = \"" (assoc-ref outputs "cargo") "\"")))
571 (invoke "./x.py" "install" "cargo")))
572 (add-after 'install 'delete-install-logs
573 (lambda* (#:key outputs #:allow-other-keys)
574 (define (delete-manifest-file out-path file)
575 (delete-file (string-append out-path "/lib/rustlib/" file)))
577 (let ((out (assoc-ref outputs "out"))
578 (cargo-out (assoc-ref outputs "cargo")))
580 (lambda (file) (delete-manifest-file out file))
583 "manifest-rust-std-x86_64-unknown-linux-gnu"
586 (lambda (file) (delete-manifest-file cargo-out file))
590 (add-after 'install 'wrap-rustc
591 (lambda* (#:key inputs outputs #:allow-other-keys)
592 (let ((out (assoc-ref outputs "out"))
593 (libc (assoc-ref inputs "libc"))
594 (ld-wrapper (assoc-ref inputs "ld-wrapper")))
595 ;; Let gcc find ld and libc startup files.
596 (wrap-program (string-append out "/bin/rustc")
597 `("PATH" ":" prefix (,(string-append ld-wrapper "/bin")))
598 `("LIBRARY_PATH" ":" suffix (,(string-append libc "/lib"))))
601 (define-public rust-1.21
602 (let ((base-rust (rust-bootstrapped-package rust-1.20 "1.21.0"
603 "1yj8lnxybjrybp00fqhxw8fpr641dh8wcn9mk44xjnsb4i1c21qp")))
607 (substitute-keyword-arguments (package-arguments base-rust)
609 `(modify-phases ,phases
610 (add-after 'configure 'remove-ar
611 (lambda* (#:key inputs #:allow-other-keys)
612 ;; Remove because toml complains about "unknown field".
613 (substitute* "config.toml"
617 (define-public rust-1.22
618 (let ((base-rust (rust-bootstrapped-package rust-1.21 "1.22.1"
619 "1lrzzp0nh7s61wgfs2h6ilaqi6iq89f1pd1yaf65l87bssyl4ylb")))
623 (substitute-keyword-arguments (package-arguments base-rust)
625 `(modify-phases ,phases
626 (add-after 'unpack 'remove-flaky-test
628 ;; See <https://github.com/rust-lang/rust/issues/43402>.
629 (when (file-exists? "src/test/run-make/issue-26092")
630 (delete-file-recursively "src/test/run-make/issue-26092"))
633 (define-public rust-1.23
634 (let ((base-rust (rust-bootstrapped-package rust-1.22 "1.23.0"
635 "14fb8vhjzsxlbi6yrn1r6fl5dlbdd1m92dn5zj5gmzfwf4w9ar3l")))
639 (substitute-keyword-arguments (package-arguments base-rust)
641 `(modify-phases ,phases
642 (delete 'configure-archiver)
644 (add-after 'unpack 'dont-build-native
646 ;; XXX: Revisit this when we use gcc 6.
647 (substitute* "src/binaryen/CMakeLists.txt"
648 (("ADD_COMPILE_FLAG\\(\\\"-march=native\\\"\\)") ""))
651 (define-public rust-1.24
653 (rust-bootstrapped-package rust-1.23 "1.24.1"
654 "1vv10x2h9kq7fxh2v01damdq8pvlp5acyh1kzcda9sfjx12kv99y")))
658 (substitute-keyword-arguments (package-arguments base-rust)
660 `(modify-phases ,phases
661 (delete 'use-readelf-for-tests)
662 (replace 'patch-aarch64-test
664 (substitute* "src/librustc_metadata/dynamic_lib.rs"
665 ;; This test is known to fail on aarch64 and powerpc64le:
666 ;; https://github.com/rust-lang/rust/issues/45410
667 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
670 ;;; Rust 1.25 release support work with llvm 6--but build with llvm 6 is
671 ;;; not determenistic due to <https://github.com/rust-lang/rust/issues/50556>.
672 ;;; Keep using llvm 3.9.1 until builds become determenistic
673 (define-public rust-1.25
675 (rust-bootstrapped-package rust-1.24 "1.25.0"
676 "0baxjr99311lvwdq0s38bipbnj72pn6fgbk6lcq7j555xq53mxpf")))
681 (inherit (package-source base-rust))
683 (delete-file-recursively "src/jemalloc")
684 (delete-file-recursively "src/llvm")
685 (delete-file-recursively "src/llvm-emscripten")
687 (patches (map search-patch
688 '("rust-1.25-accept-more-detailed-gdb-lines.patch")))))
690 (substitute-keyword-arguments (package-arguments base-rust)
692 `(modify-phases ,phases
693 (add-after 'patch-cargo-tests 'patch-cargo-index-update
695 (substitute* "src/tools/cargo/tests/generate-lockfile.rs"
696 ;; This test wants to update the crate index.
697 (("fn no_index_update") "#[ignore]\nfn no_index_update"))
699 (replace 'patch-aarch64-test
701 (substitute* "src/librustc_metadata/dynamic_lib.rs"
702 ;; This test is known to fail on aarch64 and powerpc64le:
703 ;; https://github.com/rust-lang/rust/issues/45410
704 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
705 ;; This test fails on aarch64 with llvm@6.0:
706 ;; https://github.com/rust-lang/rust/issues/49807
707 ;; other possible solution:
708 ;; https://github.com/rust-lang/rust/pull/47688
709 (delete-file "src/test/debuginfo/by-value-self-argument-in-trait-impl.rs")
711 (delete 'ignore-glibc-2.27-incompatible-test))))))))
713 (define-public rust-1.26
715 (rust-bootstrapped-package rust-1.25 "1.26.2"
716 "0047ais0fvmqvngqkdsxgrzhb0kljg8wy85b01kbbjc88hqcz7pv")))
721 (inherit (package-source base-rust))
722 (patches (map search-patch
723 '("rust-coresimd-doctest.patch"
724 "rust-1.25-accept-more-detailed-gdb-lines.patch")))))
726 (substitute-keyword-arguments (package-arguments base-rust)
728 `(modify-phases ,phases
729 ;; binaryen was replaced with LLD project from LLVM
730 (delete 'dont-build-native)
733 ;; Enable parallel execution.
734 (let ((parallel-job-spec
735 (string-append "-j" (number->string
737 (parallel-job-count))))))
738 (invoke "./x.py" parallel-job-spec "test" "-vv")
739 (invoke "./x.py" parallel-job-spec "test"
740 "src/tools/cargo"))))
741 (replace 'remove-unsupported-tests
743 ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH.
744 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html>
745 (delete-file-recursively "src/test/run-make-fulldeps/linker-output-non-utf8")
747 (replace 'patch-cargo-tests
749 (substitute* "src/tools/cargo/tests/testsuite/build.rs"
750 (("/usr/bin/env") (which "env"))
751 ;; Guix llvm is compiled without asmjs-unknown-emscripten.
752 (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs"))
753 (substitute* "src/tools/cargo/tests/testsuite/death.rs"
754 ;; This is stuck when built in container.
755 (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone"))
756 ;; Prints test output in the wrong order when built on
758 (substitute* "src/tools/cargo/tests/testsuite/test.rs"
759 (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env"))
761 ;; Avoid dependency on "git".
762 (substitute* "src/tools/cargo/tests/testsuite/new.rs"
763 (("fn author_prefers_cargo") "#[ignore]\nfn author_prefers_cargo")
764 (("fn finds_author_git") "#[ignore]\nfn finds_author_git")
765 (("fn finds_local_author_git") "#[ignore]\nfn finds_local_author_git"))
767 (add-after 'patch-cargo-tests 'disable-cargo-test-for-nightly-channel
769 ;; This test failed to work on "nightly" channel builds
770 ;; https://github.com/rust-lang/cargo/issues/5648
771 (substitute* "src/tools/cargo/tests/testsuite/resolve.rs"
772 (("fn test_resolving_minimum_version_with_transitive_deps")
773 "#[ignore]\nfn test_resolving_minimum_version_with_transitive_deps"))
775 (replace 'patch-cargo-index-update
777 (substitute* "src/tools/cargo/tests/testsuite/generate_lockfile.rs"
778 ;; This test wants to update the crate index.
779 (("fn no_index_update") "#[ignore]\nfn no_index_update"))
782 (define-public rust-1.27
784 (rust-bootstrapped-package rust-1.26 "1.27.2"
785 "0pg1s37bhx9zqbynxyydq5j6q7kij9vxkcv8maz0m25prm88r0cs")))
790 (inherit (package-source base-rust))
791 (patches (map search-patch '("rust-coresimd-doctest.patch"
792 "rust-bootstrap-stage0-test.patch"
793 "rust-1.25-accept-more-detailed-gdb-lines.patch"
794 "rust-reproducible-builds.patch")))))
796 ;; FIXME: Rust 1.27 and some later versions require GDB 8.2 specifically.
797 ;; See <https://bugs.gnu.org/37810>.
798 (alist-replace "gdb" (list gdb-8.2)
799 (package-native-inputs base-rust)))
801 (substitute-keyword-arguments (package-arguments base-rust)
803 `(modify-phases ,phases
804 (add-before 'install 'mkdir-prefix-paths
805 (lambda* (#:key outputs #:allow-other-keys)
806 ;; As result of https://github.com/rust-lang/rust/issues/36989
807 ;; `prefix' directory should exist before `install' call
808 (mkdir-p (assoc-ref outputs "out"))
809 (mkdir-p (assoc-ref outputs "cargo"))
811 (add-after 'patch-cargo-tests 'disable-thinlto-test
813 ;; thinlto required llvm 6.0 for work
814 (substitute* "src/tools/cargo/tests/testsuite/path.rs"
815 (("fn thin_lto_works") "#[ignore]\nfn thin_lto_works"))
818 (define-public rust-1.28
820 (rust-bootstrapped-package rust-1.27 "1.28.0"
821 "11k4rn77bca2rikykkk9fmprrgjswd4x4kaq7fia08vgkir82nhx")))
826 (inherit (package-source base-rust))
827 (patches (map search-patch '("rust-coresimd-doctest.patch"
828 "rust-bootstrap-stage0-test.patch"
829 "rust-1.25-accept-more-detailed-gdb-lines.patch"
830 "rust-reproducible-builds.patch")))))
833 (alist-replace "llvm" (list llvm-6)
834 (package-inputs base-rust)))
836 (substitute-keyword-arguments (package-arguments base-rust)
838 `(modify-phases ,phases
839 (add-after 'configure 'enable-codegen-tests
840 ;; Codegen tests should pass with llvm 6, so enable them.
842 (substitute* "config.toml"
843 (("codegen-tests = false") ""))
845 (add-after 'patch-tests 'disable-amd64-avx-test
846 ;; That test would fail on x86_64 machines without avx.
848 (substitute* "src/test/run-pass/issue-44056.rs"
849 (("only-x86_64") "ignore-test"))
851 ;; The thinlto test should pass with llvm 6.
852 (delete 'disable-thinlto-test))))))))
854 (define-public rust-1.29
856 (rust-bootstrapped-package rust-1.28 "1.29.2"
857 "1jb787080z754caa2w3w1amsygs4qlzj9rs1vy64firfmabfg22h")))
862 (inherit (package-source base-rust))
863 (patches (map search-patch '("rust-1.25-accept-more-detailed-gdb-lines.patch"
864 "rust-reproducible-builds.patch"))))))))
866 (define-public rust-1.30
868 (rust-bootstrapped-package rust-1.29 "1.30.1"
869 "0aavdc1lqv0cjzbqwl5n59yd0bqdlhn0zas61ljf38yrvc18k8rn")))
874 (inherit (package-source base-rust))
876 (delete-file-recursively "src/jemalloc")
877 (delete-file-recursively "src/llvm")
878 (delete-file-recursively "src/llvm-emscripten")
879 (delete-file-recursively "src/tools/clang")
880 (delete-file-recursively "src/tools/lldb")
883 (substitute-keyword-arguments (package-arguments base-rust)
885 `(modify-phases ,phases
886 (add-after 'patch-cargo-tests 'patch-cargo-env-shebang
887 (lambda* (#:key inputs #:allow-other-keys)
888 (let ((coreutils (assoc-ref inputs "coreutils")))
889 (substitute* "src/tools/cargo/tests/testsuite/fix.rs"
890 ;; Cargo has a test which explicitly sets a
891 ;; RUSTC_WRAPPER environment variable which points
892 ;; to /usr/bin/env. Since it's not a shebang, it
893 ;; needs to be manually patched
894 (("\"/usr/bin/env\"")
895 (string-append "\"" coreutils "/bin/env\"")))
897 (add-after 'patch-cargo-env-shebang 'ignore-cargo-package-tests
899 (substitute* "src/tools/cargo/tests/testsuite/package.rs"
900 ;; These tests largely check that cargo outputs warning/error
901 ;; messages as expected. It seems that cargo outputs an
902 ;; absolute path to something in the store instead of the
903 ;; expected relative path (e.g. `[..]`) so we'll ignore
905 (("fn include") "#[ignore]\nfn include")
906 (("fn exclude") "#[ignore]\nfn exclude"))
908 ;; The test has been moved elsewhere.
909 (replace 'disable-amd64-avx-test
911 (substitute* "src/test/ui/run-pass/issues/issue-44056.rs"
912 (("only-x86_64") "ignore-test"))
915 (define-public rust-1.31
917 (rust-bootstrapped-package rust-1.30 "1.31.1"
918 "0sk84ff0cklybcp0jbbxcw7lk7mrm6kb6km5nzd6m64dy0igrlli")))
922 (substitute-keyword-arguments (package-arguments base-rust)
924 `(modify-phases ,phases
925 (add-after 'patch-tests 'patch-command-exec-tests
926 (lambda* (#:key inputs #:allow-other-keys)
927 (let ((coreutils (assoc-ref inputs "coreutils")))
928 (substitute* "src/test/run-pass/command-exec.rs"
929 ;; This test suite includes some tests that the stdlib's
930 ;; `Command` execution properly handles situations where
931 ;; the environment or PATH variable are empty, but this
932 ;; fails since we don't have `echo` available in the usual
933 ;; Linux directories.
934 ;; NB: the leading space is so we don't fail a tidy check
935 ;; for trailing whitespace, and the newlines are to ensure
936 ;; we don't exceed the 100 chars tidy check as well
937 ((" Command::new\\(\"echo\"\\)")
938 (string-append "\nCommand::new(\"" coreutils "/bin/echo\")\n")))
940 ;; The test has been moved elsewhere.
941 (replace 'disable-amd64-avx-test
943 (substitute* "src/test/ui/issues/issue-44056.rs"
944 (("only-x86_64") "ignore-test"))
946 (add-after 'patch-tests 'patch-process-docs-rev-cmd
948 ;; Disable some doc tests which depend on the "rev" command
949 ;; https://github.com/rust-lang/rust/pull/58746
950 (substitute* "src/libstd/process.rs"
951 (("```rust") "```rust,no_run"))
954 (define-public rust-1.32
956 (rust-bootstrapped-package rust-1.31 "1.32.0"
957 "0ji2l9xv53y27xy72qagggvq47gayr5lcv2jwvmfirx029vlqnac")))
962 (inherit (package-source base-rust))
963 (snippet '(begin (delete-file-recursively "src/llvm")
964 (delete-file-recursively "src/llvm-emscripten")
965 (delete-file-recursively "src/tools/clang")
966 (delete-file-recursively "src/tools/lldb")
967 (delete-file-recursively "vendor/jemalloc-sys/jemalloc")
969 (patches (map search-patch '("rust-reproducible-builds.patch")))
970 ;; the vendor directory has moved to the root of
971 ;; the tarball, so we have to strip an extra prefix
972 (patch-flags '("-p2"))))
974 ;; Downgrade to LLVM 6, all LTO tests appear to fail with LLVM 7.0.1
975 (alist-replace "llvm" (list llvm-6)
976 (package-inputs base-rust)))
978 (substitute-keyword-arguments (package-arguments base-rust)
980 `(modify-phases ,phases
981 ;; Cargo.lock and the vendor/ directory have been moved to the
982 ;; root of the rust tarball
983 (replace 'patch-cargo-checksums
985 (use-modules (guix build cargo-utils))
986 (substitute* "Cargo.lock"
987 (("(\"checksum .* = )\".*\"" all name)
988 (string-append name "\"" ,%cargo-reference-hash "\"")))
989 (generate-all-checksums "vendor")
991 (add-after 'enable-codegen-tests 'override-jemalloc
992 (lambda* (#:key inputs #:allow-other-keys)
993 ;; The compiler is no longer directly built against jemalloc,
994 ;; but rather via the jemalloc-sys crate (which vendors the
995 ;; jemalloc source). To use jemalloc we must enable linking to
996 ;; it (otherwise it would use the system allocator), and set
997 ;; an environment variable pointing to the compiled jemalloc.
998 (substitute* "config.toml"
999 (("^jemalloc =.*$") "")
1000 (("[[]rust[]]") "\n[rust]\njemalloc=true\n"))
1001 (setenv "JEMALLOC_OVERRIDE" (string-append (assoc-ref inputs "jemalloc")
1002 "/lib/libjemalloc_pic.a"))
1004 ;; Remove no longer relevant steps
1005 (delete 'remove-flaky-test)
1006 (delete 'patch-aarch64-test))))))))
1008 (define-public rust-1.33
1010 (rust-bootstrapped-package rust-1.32 "1.33.0"
1011 "152x91mg7bz4ygligwjb05fgm1blwy2i70s2j03zc9jiwvbsh0as")))
1016 (inherit (package-source base-rust))
1018 (patch-flags '("-p1"))))
1020 ;; Upgrade to jemalloc@5.1.0
1021 (alist-replace "jemalloc" (list jemalloc)
1022 (package-inputs base-rust)))
1024 (substitute-keyword-arguments (package-arguments base-rust)
1026 `(modify-phases ,phases
1027 (delete 'ignore-cargo-package-tests)
1028 (add-after 'configure 'configure-test-threads
1029 ;; Several rustc and cargo tests will fail if run on one core
1030 ;; https://github.com/rust-lang/rust/issues/59122
1031 ;; https://github.com/rust-lang/cargo/issues/6746
1032 ;; https://github.com/rust-lang/rust/issues/58907
1033 (lambda* (#:key inputs #:allow-other-keys)
1034 (setenv "RUST_TEST_THREADS" "2")
1037 (define-public rust-1.34
1039 (rust-bootstrapped-package rust-1.33 "1.34.1"
1040 "19s09k7y5j6g3y4d2rk6kg9pvq6ml94c49w6b72dmq8p9lk8bixh")))
1045 (inherit (package-source base-rust))
1047 (delete-file-recursively "src/llvm-emscripten")
1048 (delete-file-recursively "src/llvm-project")
1049 (delete-file-recursively "vendor/jemalloc-sys/jemalloc")
1052 (define-public rust-1.35
1054 (rust-bootstrapped-package rust-1.34 "1.35.0"
1055 "0bbizy6b7002v1rdhrxrf5gijclbyizdhkglhp81ib3bf5x66kas")))
1059 (alist-replace "llvm" (list llvm-8)
1060 (package-inputs base-rust)))
1062 (substitute-keyword-arguments (package-arguments base-rust)
1064 `(modify-phases ,phases
1065 ;; The tidy test includes a pass which ensures large binaries
1066 ;; don't accidentally get checked into the rust git repo.
1067 ;; Unfortunately the test assumes that git is always available,
1068 ;; so we'll comment out the invocation of this pass.
1069 (add-after 'configure 'disable-tidy-bins-check
1071 (substitute* "src/tools/tidy/src/main.rs"
1072 (("bins::check") "//bins::check"))
1075 (define-public rust-1.36
1077 (rust-bootstrapped-package rust-1.35 "1.36.0"
1078 "06xv2p6zq03lidr0yaf029ii8wnjjqa894nkmrm6s0rx47by9i04")))
1082 (substitute-keyword-arguments (package-arguments base-rust)
1084 `(modify-phases ,phases
1085 (delete 'patch-process-docs-rev-cmd))))))))
1089 (rust-bootstrapped-package rust-1.36 "1.37.0"
1090 "1hrqprybhkhs6d9b5pjskfnc5z9v2l2gync7nb39qjb5s0h703hj")))
1094 (substitute-keyword-arguments (package-arguments base-rust)
1096 `(modify-phases ,phases
1097 (add-before 'configure 'configure-cargo-home
1099 (let ((cargo-home (string-append (getcwd) "/.cargo")))
1100 (mkdir-p cargo-home)
1101 (setenv "CARGO_HOME" cargo-home)