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 Efraim Flashner <efraim@flashner.co.il>
8 ;;; Copyright © 2018 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 "0a7v8ccyzp1sdkwni8h1698hxpfz2sxhcpx42n6l2pbm0rbjp08i"))
105 (search-patches "mrustc-0.8.0-fix-variable-length-integer-receiving.patch"))))
106 (outputs '("out" "cargo"))
107 (build-system gnu-build-system)
109 `(("llvm" ,llvm-3.9.1)))
113 ;; Required for the libstd sources.
114 ("rustc" ,(package-source rust-1.19))))
116 `(#:test-target "local_tests"
117 #:make-flags (list (string-append "LLVM_CONFIG="
118 (assoc-ref %build-inputs "llvm")
121 (modify-phases %standard-phases
122 (add-after 'unpack 'patch-date
124 (substitute* "Makefile"
125 (("shell date") "shell date -d @1"))
127 (add-after 'patch-date 'unpack-target-compiler
128 (lambda* (#:key inputs outputs #:allow-other-keys)
129 (substitute* "minicargo.mk"
130 ;; Don't try to build LLVM.
131 (("^[$][(]LLVM_CONFIG[)]:") "xxx:")
132 ;; Build for the correct target architecture.
133 (("^RUSTC_TARGET := x86_64-unknown-linux-gnu")
134 (string-append "RUSTC_TARGET := "
135 ,(or (%current-target-system)
136 (nix-system->gnu-triplet-for-rust)))))
137 (invoke "tar" "xf" (assoc-ref inputs "rustc"))
138 (chdir "rustc-1.19.0-src")
139 (invoke "patch" "-p0" "../rust_src.patch")
143 (lambda* (#:key inputs #:allow-other-keys)
144 (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
146 (add-after 'build 'build-minicargo
148 (for-each (lambda (target)
149 (invoke "make" "-f" "minicargo.mk" target))
150 '("output/libstd.hir" "output/libpanic_unwind.hir"
151 "output/libproc_macro.hir" "output/libtest.hir"))
152 ;; Technically the above already does it - but we want to be clear.
153 (invoke "make" "-C" "tools/minicargo")))
155 (lambda* (#:key inputs outputs #:allow-other-keys)
156 (let* ((out (assoc-ref outputs "out"))
157 (bin (string-append out "/bin"))
158 (tools-bin (string-append out "/tools/bin"))
159 (cargo-out (assoc-ref outputs "cargo"))
160 (cargo-bin (string-append cargo-out "/bin"))
161 (lib (string-append out "/lib"))
162 (lib/rust (string-append lib "/mrust"))
163 (gcc (assoc-ref inputs "gcc")))
164 ;; These files are not reproducible.
165 (for-each delete-file (find-files "output" "\\.txt$"))
166 (delete-file-recursively "output/local_tests")
168 (copy-recursively "output" lib/rust)
171 (install-file "bin/mrustc" bin)
172 ;; minicargo uses relative paths to resolve mrustc.
173 (install-file "tools/bin/minicargo" tools-bin)
174 (install-file "tools/bin/minicargo" cargo-bin)
176 (synopsis "Compiler for the Rust progamming language")
177 (description "Rust is a systems programming language that provides memory
178 safety and thread safety guarantees.")
179 (home-page "https://github.com/thepowersgang/mrustc")
181 (license (list license:asl2.0 license:expat)))))
190 (uri (rust-uri "1.19.0"))
191 (sha256 (base32 "0l8c14qsf42rmkqy92ahij4vf356dbyspxcips1aswpvad81y8qm"))
192 (modules '((guix build utils)))
193 (snippet '(begin (delete-file-recursively "src/llvm") #t))
194 (patches (map search-patch '("rust-1.19-mrustc.patch")))))
195 (outputs '("out" "cargo"))
196 (properties '((timeout . 72000) ;20 hours
197 (max-silent-time . 18000))) ;5 hours (for armel)
199 `(#:imported-modules ,%cargo-utils-modules ;for `generate-checksums'
200 #:modules ((guix build utils) (ice-9 match) (guix build gnu-build-system))
202 (modify-phases %standard-phases
203 (add-after 'unpack 'set-env
204 (lambda* (#:key inputs #:allow-other-keys)
205 ;; Disable test for cross compilation support.
206 (setenv "CFG_DISABLE_CROSS_TESTS" "1")
207 (setenv "SHELL" (which "sh"))
208 (setenv "CONFIG_SHELL" (which "sh"))
209 (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
210 ;; guix llvm-3.9.1 package installs only shared libraries
211 (setenv "LLVM_LINK_SHARED" "1")
213 (add-after 'unpack 'patch-cargo-tomls
214 (lambda* (#:key inputs outputs #:allow-other-keys)
215 (substitute* "src/librustc_errors/Cargo.toml"
216 (("[[]dependencies[]]") "
220 (substitute* "src/librustc/Cargo.toml"
221 (("[[]dependencies[]]") "
223 getopts = { path = \"../libgetopts\" }
225 (substitute* "src/librustdoc/Cargo.toml"
226 (("[[]dependencies[]]") "
228 test = { path = \"../libtest\" }
231 (add-after 'unpack 'patch-tests
232 (lambda* (#:key inputs #:allow-other-keys)
233 (let ((bash (assoc-ref inputs "bash")))
234 (substitute* "src/libstd/process.rs"
235 ;; The newline is intentional.
236 ;; There's a line length "tidy" check in Rust which would
238 (("\"/bin/sh\"") (string-append "\n\"" bash "/bin/sh\"")))
239 (substitute* "src/libstd/net/tcp.rs"
240 ;; There is no network in build environment
241 (("fn connect_timeout_unroutable")
242 "#[ignore]\nfn connect_timeout_unroutable"))
243 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00222.html>
244 (substitute* "src/libstd/sys/unix/process/process_common.rs"
245 (("fn test_process_mask") "#[allow(unused_attributes)]
247 fn test_process_mask"))
249 (add-after 'patch-tests 'patch-aarch64-test
251 (substitute* "src/librustc_back/dynamic_lib.rs"
252 ;; This test is known to fail on aarch64 and powerpc64le:
253 ;; https://github.com/rust-lang/rust/issues/45410
254 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
256 (add-after 'patch-tests 'use-readelf-for-tests
258 ;; nm doesn't recognize the file format because of the
259 ;; nonstandard sections used by the Rust compiler, but readelf
261 (substitute* "src/test/run-make/atomic-lock-free/Makefile"
265 (add-after 'patch-tests 'remove-unsupported-tests
267 ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH.
268 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html>
269 (delete-file-recursively "src/test/run-make/linker-output-non-utf8")
271 (add-after 'patch-source-shebangs 'patch-cargo-checksums
273 (substitute* "src/Cargo.lock"
274 (("(\"checksum .* = )\".*\"" all name)
275 (string-append name "\"" ,%cargo-reference-hash "\"")))
278 (use-modules (guix build cargo-utils))
279 (delete-file filename)
280 (let* ((dir (dirname filename)))
281 (display (string-append
282 "patch-cargo-checksums: generate-checksums for "
284 (generate-checksums dir)))
285 (find-files "src/vendor" ".cargo-checksum.json"))
287 ;; This phase is overridden by newer versions.
290 ;; This phase is overridden by newer versions.
292 (lambda* (#:key inputs outputs #:allow-other-keys)
293 (let ((rustc-bootstrap (assoc-ref inputs "rustc-bootstrap")))
294 (setenv "CFG_COMPILER_HOST_TRIPLE"
295 ,(nix-system->gnu-triplet (%current-system)))
296 (setenv "CFG_RELEASE" "")
297 (setenv "CFG_RELEASE_CHANNEL" "stable")
298 (setenv "CFG_LIBDIR_RELATIVE" "lib")
299 (setenv "CFG_VERSION" "1.19.0-stable-mrustc")
300 ; bad: (setenv "CFG_PREFIX" "mrustc") ; FIXME output path.
302 (invoke (string-append rustc-bootstrap "/tools/bin/minicargo")
303 "src/rustc" "--vendor-dir" "src/vendor"
304 "--output-dir" "output/rustc-build"
305 "-L" (string-append rustc-bootstrap "/lib/mrust")
307 (setenv "CFG_COMPILER_HOST_TRIPLE" #f)
308 (setenv "CFG_RELEASE" #f)
309 (setenv "CFG_RELEASE_CHANNEL" #f)
310 (setenv "CFG_VERSION" #f)
311 (setenv "CFG_PREFIX" #f)
312 (setenv "CFG_LIBDIR_RELATIVE" #f)
313 (invoke (string-append rustc-bootstrap "/tools/bin/minicargo")
314 "src/tools/cargo" "--vendor-dir" "src/vendor"
315 "--output-dir" "output/cargo-build"
317 "-L" (string-append rustc-bootstrap "/lib/mrust")
319 ;; Now use the newly-built rustc to build the libraries.
320 ;; One day that could be replaced by:
321 ;; (invoke "output/cargo-build/cargo" "build"
322 ;; "--manifest-path" "src/bootstrap/Cargo.toml"
323 ;; "--verbose") ; "--locked" "--frozen"
324 ;; but right now, Cargo has problems with libstd's circular
326 (mkdir-p "output/target-libs")
327 (for-each (match-lambda
332 "output/rustc-build/rustc"
333 "-C" (string-append "linker="
335 ;; Required for libterm.
336 "-Z" "force-unstable-if-unmarked"
337 "-L" "output/target-libs"
338 (string-append "src/" name "/lib.rs")
340 (string-append "output/target-libs/"
341 (car (string-split name #\/))
349 ("liblibc/src" "--cfg" "stdbuild")
350 ("libunwind" "-l" "gcc_s")
351 ("libcompiler_builtins")
354 ;; Uses "cc" to link.
355 ("libstd" "-l" "dl" "-l" "rt" "-l" "pthread")
358 ;; Test dependencies:
364 ;; This phase is overridden by newer versions.
367 ;; This phase is overridden by newer versions.
369 (lambda* (#:key inputs outputs #:allow-other-keys)
370 (let* ((out (assoc-ref outputs "out"))
371 (target-system ,(or (%current-target-system)
372 (nix-system->gnu-triplet
374 (out-libs (string-append out "/lib/rustlib/"
375 target-system "/lib")))
376 ;(setenv "CFG_PREFIX" out)
378 (copy-recursively "output/target-libs" out-libs)
379 (install-file "output/rustc-build/rustc"
380 (string-append out "/bin"))
381 (install-file "output/rustc-build/rustdoc"
382 (string-append out "/bin"))
383 (install-file "output/cargo-build/cargo"
384 (string-append (assoc-ref outputs "cargo")
387 (build-system gnu-build-system)
389 `(("bison" ,bison) ; For the tests
391 ("flex" ,flex) ; For the tests
392 ("gdb" ,gdb) ; For the tests
393 ("procps" ,procps) ; For the tests
394 ("python-2" ,python-2)
395 ("rustc-bootstrap" ,mrustc)
396 ("cargo-bootstrap" ,mrustc "cargo")
397 ("pkg-config" ,pkg-config) ; For "cargo"
400 `(("jemalloc" ,jemalloc-4.5.0)
403 ("libssh2" ,libssh2) ; For "cargo"
404 ("libcurl" ,curl))) ; For "cargo"
406 ;; rustc invokes gcc, so we need to set its search paths accordingly.
407 ;; Note: duplicate its value here to cope with circular dependencies among
408 ;; modules (see <https://bugs.gnu.org/31392>).
410 (list (search-path-specification
411 (variable "C_INCLUDE_PATH")
412 (files '("include")))
413 (search-path-specification
414 (variable "CPLUS_INCLUDE_PATH")
415 (files '("include")))
416 (search-path-specification
417 (variable "LIBRARY_PATH")
418 (files '("lib" "lib64")))))
420 (synopsis "Compiler for the Rust progamming language")
421 (description "Rust is a systems programming language that provides memory
422 safety and thread safety guarantees.")
423 (home-page "https://www.rust-lang.org")
425 (license (list license:asl2.0 license:expat))))
427 (define-public rust-1.20
429 (rust-bootstrapped-package rust-1.19 "1.20.0"
430 "0542y4rnzlsrricai130mqyxl8r6rd991frb4qsnwb27yigqg91a")))
435 (inherit (package-source base-rust))
437 (delete-file-recursively "src/jemalloc")
438 (delete-file-recursively "src/llvm")
441 (outputs '("out" "doc" "cargo"))
442 ;; Since rust-1.19 is local, it's quite probable that Hydra
443 ;; will build rust-1.19 only as a dependency of rust-1.20.
444 ;; But then Hydra will use the wrong properties, the ones here,
445 ;; for rust-1.19. Therefore, we copied the properties of
447 (properties '((timeout . 72000) ;20 hours
448 (max-silent-time . 18000))) ;5 hours (for armel)
450 (substitute-keyword-arguments (package-arguments rust-1.19)
452 `(modify-phases ,phases
453 (add-after 'patch-tests 'patch-cargo-tests
455 (substitute* "src/tools/cargo/tests/build.rs"
456 (("/usr/bin/env") (which "env"))
457 ;; Guix llvm is compiled without asmjs-unknown-emscripten.
458 (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs"))
459 (substitute* "src/tools/cargo/tests/death.rs"
460 ;; This is stuck when built in container.
461 (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone"))
462 ;; Prints test output in the wrong order when built on
464 (substitute* "src/tools/cargo/tests/test.rs"
465 (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env"))
467 ;; These tests pull in a dependency on "git", which changes
468 ;; too frequently take part in the Rust toolchain.
469 (substitute* "src/tools/cargo/tests/new.rs"
470 (("fn author_prefers_cargo") "#[ignore]\nfn author_prefers_cargo")
471 (("fn finds_author_git") "#[ignore]\nfn finds_author_git")
472 (("fn finds_local_author_git") "#[ignore]\nfn finds_local_author_git"))
474 (add-after 'patch-cargo-tests 'ignore-glibc-2.27-incompatible-test
475 ;; https://github.com/rust-lang/rust/issues/47863
477 (substitute* "src/test/run-pass/out-of-stack.rs"
478 (("// ignore-android") "// ignore-test\n// ignore-android"))
481 (lambda* (#:key inputs outputs #:allow-other-keys)
482 (let* ((out (assoc-ref outputs "out"))
483 (doc (assoc-ref outputs "doc"))
484 (gcc (assoc-ref inputs "gcc"))
485 (gdb (assoc-ref inputs "gdb"))
486 (binutils (assoc-ref inputs "binutils"))
487 (python (assoc-ref inputs "python-2"))
488 (rustc (assoc-ref inputs "rustc-bootstrap"))
489 (cargo (assoc-ref inputs "cargo-bootstrap"))
490 (llvm (assoc-ref inputs "llvm"))
491 (jemalloc (assoc-ref inputs "jemalloc")))
492 (call-with-output-file "config.toml"
494 (display (string-append "
497 cargo = \"" cargo "/bin/cargo" "\"
498 rustc = \"" rustc "/bin/rustc" "\"
500 python = \"" python "/bin/python2" "\"
501 gdb = \"" gdb "/bin/gdb" "\"
506 docdir = \"" doc "/share/doc/rust" "\"
509 default-linker = \"" gcc "/bin/gcc" "\"
512 " ;; There are 2 failed codegen tests:
513 ;; codegen/mainsubprogram.rs and codegen/mainsubprogramstart.rs
514 ;; These tests require a patched LLVM
515 "codegen-tests = false
516 [target." ,(nix-system->gnu-triplet-for-rust) "]
517 llvm-config = \"" llvm "/bin/llvm-config" "\"
518 cc = \"" gcc "/bin/gcc" "\"
519 cxx = \"" gcc "/bin/g++" "\"
520 ar = \"" binutils "/bin/ar" "\"
521 jemalloc = \"" jemalloc "/lib/libjemalloc_pic.a" "\"
525 (add-after 'configure 'provide-cc
526 (lambda* (#:key inputs #:allow-other-keys)
527 (symlink (string-append (assoc-ref inputs "gcc") "/bin/gcc")
529 (setenv "PATH" (string-append "/tmp:" (getenv "PATH")))
531 (add-after 'provide-cc 'configure-archiver
532 (lambda* (#:key inputs #:allow-other-keys)
533 (substitute* "src/build_helper/lib.rs"
534 ;; Make sure "ar" is always used as the archiver.
535 (("\"musl\"") "\"\"")
536 ;; Then substitute "ar" by our name.
537 (("\"ar\"") (string-append "\""
538 (assoc-ref inputs "binutils")
541 (delete 'patch-cargo-tomls)
542 (add-before 'build 'reset-timestamps-after-changes
546 ;; Rust 1.20.0 treats timestamp 0 as "file doesn't exist".
547 ;; Therefore, use timestamp 1.
548 (utime filename 1 1 1 1))
549 (find-files "." #:directories? #t))
553 (invoke "./x.py" "build")
554 (invoke "./x.py" "build" "src/tools/cargo")))
557 ;; Disable parallel execution to prevent EAGAIN errors when
559 (invoke "./x.py" "-j1" "test" "-vv")
560 (invoke "./x.py" "-j1" "test" "src/tools/cargo")
563 (lambda* (#:key outputs #:allow-other-keys)
564 (invoke "./x.py" "install")
565 (substitute* "config.toml"
566 ;; replace prefix to specific output
567 (("prefix = \"[^\"]*\"")
568 (string-append "prefix = \"" (assoc-ref outputs "cargo") "\"")))
569 (invoke "./x.py" "install" "cargo")))
570 (add-after 'install 'delete-install-logs
571 (lambda* (#:key outputs #:allow-other-keys)
572 (define (delete-manifest-file out-path file)
573 (delete-file (string-append out-path "/lib/rustlib/" file)))
575 (let ((out (assoc-ref outputs "out"))
576 (cargo-out (assoc-ref outputs "cargo")))
578 (lambda (file) (delete-manifest-file out file))
581 "manifest-rust-std-x86_64-unknown-linux-gnu"
584 (lambda (file) (delete-manifest-file cargo-out file))
588 (add-after 'install 'wrap-rustc
589 (lambda* (#:key inputs outputs #:allow-other-keys)
590 (let ((out (assoc-ref outputs "out"))
591 (libc (assoc-ref inputs "libc"))
592 (ld-wrapper (assoc-ref inputs "ld-wrapper")))
593 ;; Let gcc find ld and libc startup files.
594 (wrap-program (string-append out "/bin/rustc")
595 `("PATH" ":" prefix (,(string-append ld-wrapper "/bin")))
596 `("LIBRARY_PATH" ":" suffix (,(string-append libc "/lib"))))
599 (define-public rust-1.21
600 (let ((base-rust (rust-bootstrapped-package rust-1.20 "1.21.0"
601 "1yj8lnxybjrybp00fqhxw8fpr641dh8wcn9mk44xjnsb4i1c21qp")))
605 (substitute-keyword-arguments (package-arguments base-rust)
607 `(modify-phases ,phases
608 (add-after 'configure 'remove-ar
609 (lambda* (#:key inputs #:allow-other-keys)
610 ;; Remove because toml complains about "unknown field".
611 (substitute* "config.toml"
615 (define-public rust-1.22
616 (let ((base-rust (rust-bootstrapped-package rust-1.21 "1.22.1"
617 "1lrzzp0nh7s61wgfs2h6ilaqi6iq89f1pd1yaf65l87bssyl4ylb")))
621 (substitute-keyword-arguments (package-arguments base-rust)
623 `(modify-phases ,phases
624 (add-after 'unpack 'remove-flaky-test
626 ;; See <https://github.com/rust-lang/rust/issues/43402>.
627 (when (file-exists? "src/test/run-make/issue-26092")
628 (delete-file-recursively "src/test/run-make/issue-26092"))
631 (define-public rust-1.23
632 (let ((base-rust (rust-bootstrapped-package rust-1.22 "1.23.0"
633 "14fb8vhjzsxlbi6yrn1r6fl5dlbdd1m92dn5zj5gmzfwf4w9ar3l")))
637 (substitute-keyword-arguments (package-arguments base-rust)
639 `(modify-phases ,phases
640 (delete 'configure-archiver)
642 (add-after 'unpack 'dont-build-native
644 ;; XXX: Revisit this when we use gcc 6.
645 (substitute* "src/binaryen/CMakeLists.txt"
646 (("ADD_COMPILE_FLAG\\(\\\"-march=native\\\"\\)") ""))
649 (define-public rust-1.24
651 (rust-bootstrapped-package rust-1.23 "1.24.1"
652 "1vv10x2h9kq7fxh2v01damdq8pvlp5acyh1kzcda9sfjx12kv99y")))
656 (substitute-keyword-arguments (package-arguments base-rust)
658 `(modify-phases ,phases
659 (delete 'use-readelf-for-tests)
660 (replace 'patch-aarch64-test
662 (substitute* "src/librustc_metadata/dynamic_lib.rs"
663 ;; This test is known to fail on aarch64 and powerpc64le:
664 ;; https://github.com/rust-lang/rust/issues/45410
665 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
668 ;;; Rust 1.25 release support work with llvm 6--but build with llvm 6 is
669 ;;; not determenistic due to <https://github.com/rust-lang/rust/issues/50556>.
670 ;;; Keep using llvm 3.9.1 until builds become determenistic
671 (define-public rust-1.25
673 (rust-bootstrapped-package rust-1.24 "1.25.0"
674 "0baxjr99311lvwdq0s38bipbnj72pn6fgbk6lcq7j555xq53mxpf")))
679 (inherit (package-source base-rust))
681 (delete-file-recursively "src/jemalloc")
682 (delete-file-recursively "src/llvm")
683 (delete-file-recursively "src/llvm-emscripten")
685 (patches (map search-patch
686 '("rust-1.25-accept-more-detailed-gdb-lines.patch")))))
688 (substitute-keyword-arguments (package-arguments base-rust)
690 `(modify-phases ,phases
691 (add-after 'patch-cargo-tests 'patch-cargo-index-update
693 (substitute* "src/tools/cargo/tests/generate-lockfile.rs"
694 ;; This test wants to update the crate index.
695 (("fn no_index_update") "#[ignore]\nfn no_index_update"))
697 (replace 'patch-aarch64-test
699 (substitute* "src/librustc_metadata/dynamic_lib.rs"
700 ;; This test is known to fail on aarch64 and powerpc64le:
701 ;; https://github.com/rust-lang/rust/issues/45410
702 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
703 ;; This test fails on aarch64 with llvm@6.0:
704 ;; https://github.com/rust-lang/rust/issues/49807
705 ;; other possible solution:
706 ;; https://github.com/rust-lang/rust/pull/47688
707 (delete-file "src/test/debuginfo/by-value-self-argument-in-trait-impl.rs")
709 (delete 'ignore-glibc-2.27-incompatible-test))))))))
711 (define-public rust-1.26
713 (rust-bootstrapped-package rust-1.25 "1.26.2"
714 "0047ais0fvmqvngqkdsxgrzhb0kljg8wy85b01kbbjc88hqcz7pv")))
719 (inherit (package-source base-rust))
720 (patches (map search-patch
721 '("rust-coresimd-doctest.patch"
722 "rust-1.25-accept-more-detailed-gdb-lines.patch")))))
724 (substitute-keyword-arguments (package-arguments base-rust)
726 `(modify-phases ,phases
727 ;; binaryen was replaced with LLD project from LLVM
728 (delete 'dont-build-native)
731 ;; Enable parallel execution.
732 (let ((parallel-job-spec
733 (string-append "-j" (number->string
735 (parallel-job-count))))))
736 (invoke "./x.py" parallel-job-spec "test" "-vv")
737 (invoke "./x.py" parallel-job-spec "test"
738 "src/tools/cargo"))))
739 (replace 'remove-unsupported-tests
741 ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH.
742 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html>
743 (delete-file-recursively "src/test/run-make-fulldeps/linker-output-non-utf8")
745 (replace 'patch-cargo-tests
747 (substitute* "src/tools/cargo/tests/testsuite/build.rs"
748 (("/usr/bin/env") (which "env"))
749 ;; Guix llvm is compiled without asmjs-unknown-emscripten.
750 (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs"))
751 (substitute* "src/tools/cargo/tests/testsuite/death.rs"
752 ;; This is stuck when built in container.
753 (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone"))
754 ;; Prints test output in the wrong order when built on
756 (substitute* "src/tools/cargo/tests/testsuite/test.rs"
757 (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env"))
759 ;; Avoid dependency on "git".
760 (substitute* "src/tools/cargo/tests/testsuite/new.rs"
761 (("fn author_prefers_cargo") "#[ignore]\nfn author_prefers_cargo")
762 (("fn finds_author_git") "#[ignore]\nfn finds_author_git")
763 (("fn finds_local_author_git") "#[ignore]\nfn finds_local_author_git"))
765 (add-after 'patch-cargo-tests 'disable-cargo-test-for-nightly-channel
767 ;; This test failed to work on "nightly" channel builds
768 ;; https://github.com/rust-lang/cargo/issues/5648
769 (substitute* "src/tools/cargo/tests/testsuite/resolve.rs"
770 (("fn test_resolving_minimum_version_with_transitive_deps")
771 "#[ignore]\nfn test_resolving_minimum_version_with_transitive_deps"))
773 (replace 'patch-cargo-index-update
775 (substitute* "src/tools/cargo/tests/testsuite/generate_lockfile.rs"
776 ;; This test wants to update the crate index.
777 (("fn no_index_update") "#[ignore]\nfn no_index_update"))
780 (define-public rust-1.27
782 (rust-bootstrapped-package rust-1.26 "1.27.2"
783 "0pg1s37bhx9zqbynxyydq5j6q7kij9vxkcv8maz0m25prm88r0cs")))
788 (inherit (package-source base-rust))
789 (patches (map search-patch '("rust-coresimd-doctest.patch"
790 "rust-bootstrap-stage0-test.patch"
791 "rust-1.25-accept-more-detailed-gdb-lines.patch"
792 "rust-reproducible-builds.patch")))))
794 (substitute-keyword-arguments (package-arguments base-rust)
796 `(modify-phases ,phases
797 (add-before 'install 'mkdir-prefix-paths
798 (lambda* (#:key outputs #:allow-other-keys)
799 ;; As result of https://github.com/rust-lang/rust/issues/36989
800 ;; `prefix' directory should exist before `install' call
801 (mkdir-p (assoc-ref outputs "out"))
802 (mkdir-p (assoc-ref outputs "cargo"))
804 (add-after 'patch-cargo-tests 'disable-thinlto-test
806 ;; thinlto required llvm 6.0 for work
807 (substitute* "src/tools/cargo/tests/testsuite/path.rs"
808 (("fn thin_lto_works") "#[ignore]\nfn thin_lto_works"))
811 (define-public rust-1.28
813 (rust-bootstrapped-package rust-1.27 "1.28.0"
814 "11k4rn77bca2rikykkk9fmprrgjswd4x4kaq7fia08vgkir82nhx")))
819 (inherit (package-source base-rust))
820 (patches (map search-patch '("rust-coresimd-doctest.patch"
821 "rust-bootstrap-stage0-test.patch"
822 "rust-1.25-accept-more-detailed-gdb-lines.patch"
823 "rust-reproducible-builds.patch")))))
826 (alist-replace "llvm" (list llvm-6)
827 (package-inputs base-rust)))
829 (substitute-keyword-arguments (package-arguments base-rust)
831 `(modify-phases ,phases
832 (add-after 'configure 'enable-codegen-tests
833 ;; Codegen tests should pass with llvm 6, so enable them.
835 (substitute* "config.toml"
836 (("codegen-tests = false") ""))
838 (add-after 'patch-tests 'disable-amd64-avx-test
839 ;; That test would fail on x86_64 machines without avx.
841 (substitute* "src/test/run-pass/issue-44056.rs"
842 (("only-x86_64") "ignore-test"))
844 ;; The thinlto test should pass with llvm 6.
845 (delete 'disable-thinlto-test))))))))
847 (define-public rust-1.29
849 (rust-bootstrapped-package rust-1.28 "1.29.2"
850 "1jb787080z754caa2w3w1amsygs4qlzj9rs1vy64firfmabfg22h")))
855 (inherit (package-source base-rust))
856 (patches (map search-patch '("rust-1.25-accept-more-detailed-gdb-lines.patch"
857 "rust-reproducible-builds.patch"))))))))
859 (define-public rust-1.30
861 (rust-bootstrapped-package rust-1.29 "1.30.1"
862 "0aavdc1lqv0cjzbqwl5n59yd0bqdlhn0zas61ljf38yrvc18k8rn")))
867 (inherit (package-source base-rust))
869 (delete-file-recursively "src/jemalloc")
870 (delete-file-recursively "src/llvm")
871 (delete-file-recursively "src/llvm-emscripten")
872 (delete-file-recursively "src/tools/clang")
873 (delete-file-recursively "src/tools/lldb")
876 (substitute-keyword-arguments (package-arguments base-rust)
878 `(modify-phases ,phases
879 (add-after 'patch-cargo-tests 'patch-cargo-env-shebang
880 (lambda* (#:key inputs #:allow-other-keys)
881 (let ((coreutils (assoc-ref inputs "coreutils")))
882 (substitute* "src/tools/cargo/tests/testsuite/fix.rs"
883 ;; Cargo has a test which explicitly sets a
884 ;; RUSTC_WRAPPER environment variable which points
885 ;; to /usr/bin/env. Since it's not a shebang, it
886 ;; needs to be manually patched
887 (("\"/usr/bin/env\"")
888 (string-append "\"" coreutils "/bin/env\"")))
890 (add-after 'patch-cargo-env-shebang 'ignore-cargo-package-tests
892 (substitute* "src/tools/cargo/tests/testsuite/package.rs"
893 ;; These tests largely check that cargo outputs warning/error
894 ;; messages as expected. It seems that cargo outputs an
895 ;; absolute path to something in the store instead of the
896 ;; expected relative path (e.g. `[..]`) so we'll ignore
898 (("fn include") "#[ignore]\nfn include")
899 (("fn exclude") "#[ignore]\nfn exclude"))
901 ;; The test has been moved elsewhere.
902 (replace 'disable-amd64-avx-test
904 (substitute* "src/test/ui/run-pass/issues/issue-44056.rs"
905 (("only-x86_64") "ignore-test"))
908 (define-public rust-1.31
910 (rust-bootstrapped-package rust-1.30 "1.31.1"
911 "0sk84ff0cklybcp0jbbxcw7lk7mrm6kb6km5nzd6m64dy0igrlli")))
915 (substitute-keyword-arguments (package-arguments base-rust)
917 `(modify-phases ,phases
918 (add-after 'patch-tests 'patch-command-exec-tests
919 (lambda* (#:key inputs #:allow-other-keys)
920 (let ((coreutils (assoc-ref inputs "coreutils")))
921 (substitute* "src/test/run-pass/command-exec.rs"
922 ;; This test suite includes some tests that the stdlib's
923 ;; `Command` execution properly handles situations where
924 ;; the environment or PATH variable are empty, but this
925 ;; fails since we don't have `echo` available in the usual
926 ;; Linux directories.
927 ;; NB: the leading space is so we don't fail a tidy check
928 ;; for trailing whitespace, and the newlines are to ensure
929 ;; we don't exceed the 100 chars tidy check as well
930 ((" Command::new\\(\"echo\"\\)")
931 (string-append "\nCommand::new(\"" coreutils "/bin/echo\")\n")))
933 ;; The test has been moved elsewhere.
934 (replace 'disable-amd64-avx-test
936 (substitute* "src/test/ui/issues/issue-44056.rs"
937 (("only-x86_64") "ignore-test"))
939 (add-after 'patch-tests 'patch-process-docs-rev-cmd
941 ;; Disable some doc tests which depend on the "rev" command
942 ;; https://github.com/rust-lang/rust/pull/58746
943 (substitute* "src/libstd/process.rs"
944 (("```rust") "```rust,no_run"))
947 (define-public rust-1.32
949 (rust-bootstrapped-package rust-1.31 "1.32.0"
950 "0ji2l9xv53y27xy72qagggvq47gayr5lcv2jwvmfirx029vlqnac")))
955 (inherit (package-source base-rust))
956 (snippet '(begin (delete-file-recursively "src/llvm")
957 (delete-file-recursively "src/llvm-emscripten")
958 (delete-file-recursively "src/tools/clang")
959 (delete-file-recursively "src/tools/lldb")
960 (delete-file-recursively "vendor/jemalloc-sys/jemalloc")
962 (patches (map search-patch '("rust-reproducible-builds.patch")))
963 ;; the vendor directory has moved to the root of
964 ;; the tarball, so we have to strip an extra prefix
965 (patch-flags '("-p2"))))
967 ;; Downgrade to LLVM 6, all LTO tests appear to fail with LLVM 7.0.1
968 (alist-replace "llvm" (list llvm-6)
969 (package-inputs base-rust)))
971 (substitute-keyword-arguments (package-arguments base-rust)
973 `(modify-phases ,phases
974 ;; Cargo.lock and the vendor/ directory have been moved to the
975 ;; root of the rust tarball
976 (replace 'patch-cargo-checksums
978 (substitute* "Cargo.lock"
979 (("(\"checksum .* = )\".*\"" all name)
980 (string-append name "\"" ,%cargo-reference-hash "\"")))
983 (use-modules (guix build cargo-utils))
984 (delete-file filename)
985 (let* ((dir (dirname filename)))
986 (display (string-append
987 "patch-cargo-checksums: generate-checksums for "
989 (generate-checksums dir)))
990 (find-files "vendor" ".cargo-checksum.json"))
992 (add-after 'enable-codegen-tests 'override-jemalloc
993 (lambda* (#:key inputs #:allow-other-keys)
994 ;; The compiler is no longer directly built against jemalloc,
995 ;; but rather via the jemalloc-sys crate (which vendors the
996 ;; jemalloc source). To use jemalloc we must enable linking to
997 ;; it (otherwise it would use the system allocator), and set
998 ;; an environment variable pointing to the compiled jemalloc.
999 (substitute* "config.toml"
1000 (("^jemalloc =.*$") "")
1001 (("[[]rust[]]") "\n[rust]\njemalloc=true\n"))
1002 (setenv "JEMALLOC_OVERRIDE" (string-append (assoc-ref inputs "jemalloc")
1003 "/lib/libjemalloc_pic.a"))
1005 ;; Remove no longer relevant steps
1006 (delete 'remove-flaky-test)
1007 (delete 'patch-aarch64-test))))))))
1009 (define-public rust-1.33
1011 (rust-bootstrapped-package rust-1.32 "1.33.0"
1012 "152x91mg7bz4ygligwjb05fgm1blwy2i70s2j03zc9jiwvbsh0as")))
1017 (inherit (package-source base-rust))
1019 (patch-flags '("-p1"))))
1021 ;; Upgrade to jemalloc@5.1.0
1022 (alist-replace "jemalloc" (list jemalloc)
1023 (package-inputs base-rust)))
1025 (substitute-keyword-arguments (package-arguments base-rust)
1027 `(modify-phases ,phases
1028 (delete 'ignore-cargo-package-tests)
1029 (add-after 'configure 'configure-test-threads
1030 ;; Several rustc and cargo tests will fail if run on one core
1031 ;; https://github.com/rust-lang/rust/issues/59122
1032 ;; https://github.com/rust-lang/cargo/issues/6746
1033 ;; https://github.com/rust-lang/rust/issues/58907
1034 (lambda* (#:key inputs #:allow-other-keys)
1035 (setenv "RUST_TEST_THREADS" "2")
1038 (define-public rust-1.34
1040 (rust-bootstrapped-package rust-1.33 "1.34.1"
1041 "19s09k7y5j6g3y4d2rk6kg9pvq6ml94c49w6b72dmq8p9lk8bixh")))
1046 (inherit (package-source base-rust))
1048 (delete-file-recursively "src/llvm-emscripten")
1049 (delete-file-recursively "src/llvm-project")
1050 (delete-file-recursively "vendor/jemalloc-sys/jemalloc")
1053 (define-public rust-1.35
1055 (rust-bootstrapped-package rust-1.34 "1.35.0"
1056 "0bbizy6b7002v1rdhrxrf5gijclbyizdhkglhp81ib3bf5x66kas")))
1060 (alist-replace "llvm" (list llvm-8)
1061 (package-inputs base-rust)))
1063 (substitute-keyword-arguments (package-arguments base-rust)
1065 `(modify-phases ,phases
1066 ;; The tidy test includes a pass which ensures large binaries
1067 ;; don't accidentally get checked into the rust git repo.
1068 ;; Unfortunately the test assumes that git is always available,
1069 ;; so we'll comment out the invocation of this pass.
1070 (add-after 'configure 'disable-tidy-bins-check
1072 (substitute* "src/tools/tidy/src/main.rs"
1073 (("bins::check") "//bins::check"))
1078 (rust-bootstrapped-package rust-1.35 "1.36.0"
1079 "18r688ih4xi9m8gv55g1amb8inrwkdxp5fbcqb6i4gqxi90l3i0m")))
1083 (substitute-keyword-arguments (package-arguments base-rust)
1085 `(modify-phases ,phases
1086 (delete 'patch-process-docs-rev-cmd))))))))