Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / gnu / packages / rust.scm
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 Nils Gillmann <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 ;;;
11 ;;; This file is part of GNU Guix.
12 ;;;
13 ;;; GNU Guix is free software; you can redistribute it and/or modify it
14 ;;; under the terms of the GNU General Public License as published by
15 ;;; the Free Software Foundation; either version 3 of the License, or (at
16 ;;; your option) any later version.
17 ;;;
18 ;;; GNU Guix is distributed in the hope that it will be useful, but
19 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;;; GNU General Public License for more details.
22 ;;;
23 ;;; You should have received a copy of the GNU General Public License
24 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
25
26 (define-module (gnu packages rust)
27 #:use-module (gnu packages base)
28 #:use-module (gnu packages bison)
29 #:use-module (gnu packages bootstrap)
30 #:use-module (gnu packages cmake)
31 #:use-module (gnu packages compression)
32 #:use-module (gnu packages curl)
33 #:use-module (gnu packages elf)
34 #:use-module (gnu packages flex)
35 #:use-module (gnu packages gcc)
36 #:use-module (gnu packages gdb)
37 #:use-module (gnu packages jemalloc)
38 #:use-module (gnu packages linux)
39 #:use-module (gnu packages llvm)
40 #:use-module (gnu packages pkg-config)
41 #:use-module (gnu packages python)
42 #:use-module (gnu packages ssh)
43 #:use-module (gnu packages tls)
44 #:use-module (gnu packages)
45 #:use-module (guix build-system cargo)
46 #:use-module (guix build-system gnu)
47 #:use-module (guix build-system trivial)
48 #:use-module (guix download)
49 #:use-module (guix git-download)
50 #:use-module ((guix licenses) #:prefix license:)
51 #:use-module (guix packages)
52 #:use-module ((guix build utils) #:select (alist-replace))
53 #:use-module (guix utils)
54 #:use-module (ice-9 match)
55 #:use-module (srfi srfi-26))
56
57 (define %cargo-reference-project-file "/dev/null")
58 (define %cargo-reference-hash
59 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
60
61 (define* (nix-system->gnu-triplet-for-rust
62 #:optional (system (%current-system)))
63 (match 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))))
70
71 \f
72 (define* (rust-source version hash #:key (patches '()))
73 (origin
74 (method url-fetch)
75 (uri (string-append "https://static.rust-lang.org/dist/"
76 "rustc-" version "-src.tar.gz"))
77 (sha256 (base32 hash))
78 (modules '((guix build utils)))
79 (snippet '(begin (delete-file-recursively "src/llvm") #t))
80 (patches (map search-patch patches))))
81
82 (define* (rust-bootstrapped-package base-rust version checksum
83 #:key (patches '()))
84 "Bootstrap rust VERSION with source checksum CHECKSUM patched with PATCHES using BASE-RUST."
85 (package
86 (inherit base-rust)
87 (version version)
88 (source
89 (rust-source version checksum #:patches patches))
90 (native-inputs
91 (alist-replace "cargo-bootstrap" (list base-rust "cargo")
92 (alist-replace "rustc-bootstrap" (list base-rust)
93 (package-native-inputs base-rust))))))
94
95 (define-public mrustc
96 (let ((rustc-version "1.19.0"))
97 (package
98 (name "mrustc")
99 (version "0.8.0")
100 (source (origin
101 (method git-fetch)
102 (uri (git-reference
103 (url "https://github.com/thepowersgang/mrustc.git")
104 (commit (string-append "v" version))))
105 (file-name (git-file-name name version))
106 (sha256
107 (base32
108 "0a7v8ccyzp1sdkwni8h1698hxpfz2sxhcpx42n6l2pbm0rbjp08i"))))
109 (outputs '("out" "cargo"))
110 (build-system gnu-build-system)
111 (inputs
112 `(("llvm" ,llvm-3.9.1)))
113 (native-inputs
114 `(("bison" ,bison)
115 ("flex" ,flex)
116 ;; Required for the libstd sources.
117 ("rustc"
118 ,(rust-source "1.19.0" "0l8c14qsf42rmkqy92ahij4vf356dbyspxcips1aswpvad81y8qm"))))
119 (arguments
120 `(#:test-target "local_tests"
121 #:make-flags (list (string-append "LLVM_CONFIG="
122 (assoc-ref %build-inputs "llvm")
123 "/bin/llvm-config"))
124 #:phases
125 (modify-phases %standard-phases
126 (add-after 'unpack 'patch-date
127 (lambda _
128 (substitute* "Makefile"
129 (("shell date") "shell date -d @1"))
130 #t))
131 (add-after 'patch-date 'unpack-target-compiler
132 (lambda* (#:key inputs outputs #:allow-other-keys)
133 (substitute* "minicargo.mk"
134 ;; Don't try to build LLVM.
135 (("^[$][(]LLVM_CONFIG[)]:") "xxx:")
136 ;; Build for the correct target architecture.
137 (("^RUSTC_TARGET := x86_64-unknown-linux-gnu")
138 (string-append "RUSTC_TARGET := "
139 ,(or (%current-target-system)
140 (nix-system->gnu-triplet-for-rust)))))
141 (invoke "tar" "xf" (assoc-ref inputs "rustc"))
142 (chdir "rustc-1.19.0-src")
143 (invoke "patch" "-p0" "../rust_src.patch")
144 (chdir "..")
145 #t))
146 (replace 'configure
147 (lambda* (#:key inputs #:allow-other-keys)
148 (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
149 #t))
150 (add-after 'build 'build-minicargo
151 (lambda _
152 (for-each (lambda (target)
153 (invoke "make" "-f" "minicargo.mk" target))
154 '("output/libstd.hir" "output/libpanic_unwind.hir"
155 "output/libproc_macro.hir" "output/libtest.hir"))
156 ;; Technically the above already does it - but we want to be clear.
157 (invoke "make" "-C" "tools/minicargo")))
158 (replace 'install
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 ;; These files are not reproducible.
169 (for-each delete-file (find-files "output" "\\.txt$"))
170 (delete-file-recursively "output/local_tests")
171 (mkdir-p lib)
172 (copy-recursively "output" lib/rust)
173 (mkdir-p bin)
174 (mkdir-p tools-bin)
175 (install-file "bin/mrustc" bin)
176 ;; minicargo uses relative paths to resolve mrustc.
177 (install-file "tools/bin/minicargo" tools-bin)
178 (install-file "tools/bin/minicargo" cargo-bin)
179 #t))))))
180 (synopsis "Compiler for the Rust progamming language")
181 (description "Rust is a systems programming language that provides memory
182 safety and thread safety guarantees.")
183 (home-page "https://github.com/thepowersgang/mrustc")
184 ;; Dual licensed.
185 (license (list license:asl2.0 license:expat)))))
186
187 (define rust-1.19
188 (package
189 (name "rust")
190 (version "1.19.0")
191 (source (rust-source version "0l8c14qsf42rmkqy92ahij4vf356dbyspxcips1aswpvad81y8qm"
192 #:patches '("rust-1.19-mrustc.patch")))
193 (outputs '("out" "cargo"))
194 (properties '((timeout . 72000) ;20 hours
195 (max-silent-time . 18000))) ;5 hours (for armel)
196 (arguments
197 `(#:imported-modules ,%cargo-build-system-modules ;for `generate-checksums'
198 #:modules ((guix build utils) (ice-9 match) (guix build gnu-build-system))
199 #:phases
200 (modify-phases %standard-phases
201 (add-after 'unpack 'set-env
202 (lambda* (#:key inputs #:allow-other-keys)
203 ;; Disable test for cross compilation support.
204 (setenv "CFG_DISABLE_CROSS_TESTS" "1")
205 (setenv "SHELL" (which "sh"))
206 (setenv "CONFIG_SHELL" (which "sh"))
207 (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
208 ;; guix llvm-3.9.1 package installs only shared libraries
209 (setenv "LLVM_LINK_SHARED" "1")
210 #t))
211 (add-after 'unpack 'patch-cargo-tomls
212 (lambda* (#:key inputs outputs #:allow-other-keys)
213 (substitute* "src/librustc_errors/Cargo.toml"
214 (("[[]dependencies[]]") "
215 [dependencies]
216 term = \"0.4.4\"
217 "))
218 (substitute* "src/librustc/Cargo.toml"
219 (("[[]dependencies[]]") "
220 [dependencies]
221 getopts = { path = \"../libgetopts\" }
222 "))
223 (substitute* "src/librustdoc/Cargo.toml"
224 (("[[]dependencies[]]") "
225 [dependencies]
226 test = { path = \"../libtest\" }
227 "))
228 #t))
229 (add-after 'unpack 'patch-tests
230 (lambda* (#:key inputs #:allow-other-keys)
231 (let ((bash (assoc-ref inputs "bash")))
232 (substitute* "src/libstd/process.rs"
233 ;; The newline is intentional.
234 ;; There's a line length "tidy" check in Rust which would
235 ;; fail otherwise.
236 (("\"/bin/sh\"") (string-append "\n\"" bash "/bin/sh\"")))
237 (substitute* "src/libstd/net/tcp.rs"
238 ;; There is no network in build environment
239 (("fn connect_timeout_unroutable")
240 "#[ignore]\nfn connect_timeout_unroutable"))
241 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00222.html>
242 (substitute* "src/libstd/sys/unix/process/process_common.rs"
243 (("fn test_process_mask") "#[allow(unused_attributes)]
244 #[ignore]
245 fn test_process_mask"))
246 #t)))
247 (add-after 'patch-tests 'patch-aarch64-test
248 (lambda* _
249 (substitute* "src/librustc_back/dynamic_lib.rs"
250 ;; This test is known to fail on aarch64 and powerpc64le:
251 ;; https://github.com/rust-lang/rust/issues/45410
252 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
253 #t))
254 (add-after 'patch-tests 'use-readelf-for-tests
255 (lambda* _
256 ;; nm doesn't recognize the file format because of the
257 ;; nonstandard sections used by the Rust compiler, but readelf
258 ;; ignores them.
259 (substitute* "src/test/run-make/atomic-lock-free/Makefile"
260 (("\tnm ")
261 "\treadelf -c "))
262 #t))
263 (add-after 'patch-tests 'remove-unsupported-tests
264 (lambda* _
265 ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH.
266 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html>
267 (delete-file-recursively "src/test/run-make/linker-output-non-utf8")
268 #t))
269 (add-after 'patch-source-shebangs 'patch-cargo-checksums
270 (lambda* _
271 (substitute* "src/Cargo.lock"
272 (("(\"checksum .* = )\".*\"" all name)
273 (string-append name "\"" ,%cargo-reference-hash "\"")))
274 (for-each
275 (lambda (filename)
276 (use-modules (guix build cargo-build-system))
277 (delete-file filename)
278 (let* ((dir (dirname filename)))
279 (display (string-append
280 "patch-cargo-checksums: generate-checksums for "
281 dir "\n"))
282 (generate-checksums dir ,%cargo-reference-project-file)))
283 (find-files "src/vendor" ".cargo-checksum.json"))
284 #t))
285 ;; This phase is overridden by newer versions.
286 (replace 'configure
287 (const #t))
288 ;; This phase is overridden by newer versions.
289 (replace 'build
290 (lambda* (#:key inputs outputs #:allow-other-keys)
291 (let ((rustc-bootstrap (assoc-ref inputs "rustc-bootstrap")))
292 (setenv "CFG_COMPILER_HOST_TRIPLE"
293 ,(nix-system->gnu-triplet (%current-system)))
294 (setenv "CFG_RELEASE" "")
295 (setenv "CFG_RELEASE_CHANNEL" "stable")
296 (setenv "CFG_LIBDIR_RELATIVE" "lib")
297 (setenv "CFG_VERSION" "1.19.0-stable-mrustc")
298 ; bad: (setenv "CFG_PREFIX" "mrustc") ; FIXME output path.
299 (mkdir-p "output")
300 (invoke (string-append rustc-bootstrap "/tools/bin/minicargo")
301 "src/rustc" "--vendor-dir" "src/vendor"
302 "--output-dir" "output/rustc-build"
303 "-L" (string-append rustc-bootstrap "/lib/mrust")
304 "-j" "1")
305 (setenv "CFG_COMPILER_HOST_TRIPLE" #f)
306 (setenv "CFG_RELEASE" #f)
307 (setenv "CFG_RELEASE_CHANNEL" #f)
308 (setenv "CFG_VERSION" #f)
309 (setenv "CFG_PREFIX" #f)
310 (setenv "CFG_LIBDIR_RELATIVE" #f)
311 (invoke (string-append rustc-bootstrap "/tools/bin/minicargo")
312 "src/tools/cargo" "--vendor-dir" "src/vendor"
313 "--output-dir" "output/cargo-build"
314 "-L" "output/"
315 "-L" (string-append rustc-bootstrap "/lib/mrust")
316 "-j" "1")
317 ;; Now use the newly-built rustc to build the libraries.
318 ;; One day that could be replaced by:
319 ;; (invoke "output/cargo-build/cargo" "build"
320 ;; "--manifest-path" "src/bootstrap/Cargo.toml"
321 ;; "--verbose") ; "--locked" "--frozen"
322 ;; but right now, Cargo has problems with libstd's circular
323 ;; dependencies.
324 (mkdir-p "output/target-libs")
325 (for-each (match-lambda
326 ((name . flags)
327 (write name)
328 (newline)
329 (apply invoke
330 "output/rustc-build/rustc"
331 "-C" (string-append "linker="
332 (getenv "CC"))
333 ;; Required for libterm.
334 "-Z" "force-unstable-if-unmarked"
335 "-L" "output/target-libs"
336 (string-append "src/" name "/lib.rs")
337 "-o"
338 (string-append "output/target-libs/"
339 (car (string-split name #\/))
340 ".rlib")
341 flags)))
342 '(("libcore")
343 ("libstd_unicode")
344 ("liballoc")
345 ("libcollections")
346 ("librand")
347 ("liblibc/src" "--cfg" "stdbuild")
348 ("libunwind" "-l" "gcc_s")
349 ("libcompiler_builtins")
350 ("liballoc_system")
351 ("libpanic_unwind")
352 ;; Uses "cc" to link.
353 ("libstd" "-l" "dl" "-l" "rt" "-l" "pthread")
354 ("libarena")
355
356 ;; Test dependencies:
357
358 ("libgetopts")
359 ("libterm")
360 ("libtest")))
361 #t)))
362 ;; This phase is overridden by newer versions.
363 (replace 'check
364 (const #t))
365 ;; This phase is overridden by newer versions.
366 (replace 'install
367 (lambda* (#:key inputs outputs #:allow-other-keys)
368 (let* ((out (assoc-ref outputs "out"))
369 (target-system ,(or (%current-target-system)
370 (nix-system->gnu-triplet
371 (%current-system))))
372 (out-libs (string-append out "/lib/rustlib/"
373 target-system "/lib")))
374 ;(setenv "CFG_PREFIX" out)
375 (mkdir-p out-libs)
376 (copy-recursively "output/target-libs" out-libs)
377 (install-file "output/rustc-build/rustc"
378 (string-append out "/bin"))
379 (install-file "output/rustc-build/rustdoc"
380 (string-append out "/bin"))
381 (install-file "output/cargo-build/cargo"
382 (string-append (assoc-ref outputs "cargo")
383 "/bin")))
384 #t)))))
385 (build-system gnu-build-system)
386 (native-inputs
387 `(("bison" ,bison) ; For the tests
388 ("cmake" ,cmake)
389 ("flex" ,flex) ; For the tests
390 ("gdb" ,gdb) ; For the tests
391 ("procps" ,procps) ; For the tests
392 ("python-2" ,python-2)
393 ("rustc-bootstrap" ,mrustc)
394 ("cargo-bootstrap" ,mrustc "cargo")
395 ("pkg-config" ,pkg-config) ; For "cargo"
396 ("which" ,which)))
397 (inputs
398 `(("jemalloc" ,jemalloc-4.5.0)
399 ("llvm" ,llvm-3.9.1)
400 ("openssl" ,openssl)
401 ("libssh2" ,libssh2) ; For "cargo"
402 ("libcurl" ,curl))) ; For "cargo"
403
404 ;; rustc invokes gcc, so we need to set its search paths accordingly.
405 ;; Note: duplicate its value here to cope with circular dependencies among
406 ;; modules (see <https://bugs.gnu.org/31392>).
407 (native-search-paths
408 (list (search-path-specification
409 (variable "CPATH")
410 (files '("include")))
411 (search-path-specification
412 (variable "LIBRARY_PATH")
413 (files '("lib" "lib64")))))
414
415 (synopsis "Compiler for the Rust progamming language")
416 (description "Rust is a systems programming language that provides memory
417 safety and thread safety guarantees.")
418 (home-page "https://www.rust-lang.org")
419 ;; Dual licensed.
420 (license (list license:asl2.0 license:expat))))
421
422 (define-public rust-1.20
423 (let ((base-rust
424 (rust-bootstrapped-package rust-1.19 "1.20.0"
425 "0542y4rnzlsrricai130mqyxl8r6rd991frb4qsnwb27yigqg91a")))
426 (package
427 (inherit base-rust)
428 (outputs '("out" "doc" "cargo"))
429 (properties '())
430 (arguments
431 (substitute-keyword-arguments (package-arguments rust-1.19)
432 ((#:phases phases)
433 `(modify-phases ,phases
434 (add-after 'patch-tests 'patch-cargo-tests
435 (lambda _
436 (substitute* "src/tools/cargo/tests/build.rs"
437 (("/usr/bin/env") (which "env"))
438 ;; Guix llvm is compiled without asmjs-unknown-emscripten.
439 (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs"))
440 (substitute* "src/tools/cargo/tests/death.rs"
441 ;; This is stuck when built in container.
442 (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone"))
443 ;; Prints test output in the wrong order when built on
444 ;; i686-linux.
445 (substitute* "src/tools/cargo/tests/test.rs"
446 (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env"))
447
448 ;; These tests pull in a dependency on "git", which changes
449 ;; too frequently take part in the Rust toolchain.
450 (substitute* "src/tools/cargo/tests/new.rs"
451 (("fn author_prefers_cargo") "#[ignore]\nfn author_prefers_cargo")
452 (("fn finds_author_git") "#[ignore]\nfn finds_author_git")
453 (("fn finds_local_author_git") "#[ignore]\nfn finds_local_author_git"))
454 #t))
455 (add-after 'patch-cargo-tests 'ignore-glibc-2.27-incompatible-test
456 ;; https://github.com/rust-lang/rust/issues/47863
457 (lambda _
458 (substitute* "src/test/run-pass/out-of-stack.rs"
459 (("// ignore-android") "// ignore-test\n// ignore-android"))
460 #t))
461 (replace 'configure
462 (lambda* (#:key inputs outputs #:allow-other-keys)
463 (let* ((out (assoc-ref outputs "out"))
464 (doc (assoc-ref outputs "doc"))
465 (gcc (assoc-ref inputs "gcc"))
466 (gdb (assoc-ref inputs "gdb"))
467 (binutils (assoc-ref inputs "binutils"))
468 (python (assoc-ref inputs "python-2"))
469 (rustc (assoc-ref inputs "rustc-bootstrap"))
470 (cargo (assoc-ref inputs "cargo-bootstrap"))
471 (llvm (assoc-ref inputs "llvm"))
472 (jemalloc (assoc-ref inputs "jemalloc")))
473 (call-with-output-file "config.toml"
474 (lambda (port)
475 (display (string-append "
476 [llvm]
477 [build]
478 cargo = \"" cargo "/bin/cargo" "\"
479 rustc = \"" rustc "/bin/rustc" "\"
480 docs = true
481 python = \"" python "/bin/python2" "\"
482 gdb = \"" gdb "/bin/gdb" "\"
483 vendor = true
484 submodules = false
485 [install]
486 prefix = \"" out "\"
487 docdir = \"" doc "/share/doc/rust" "\"
488 sysconfdir = \"etc\"
489 [rust]
490 default-linker = \"" gcc "/bin/gcc" "\"
491 channel = \"stable\"
492 rpath = true
493 " ;; There are 2 failed codegen tests:
494 ;; codegen/mainsubprogram.rs and codegen/mainsubprogramstart.rs
495 ;; These tests require a patched LLVM
496 "codegen-tests = false
497 [target." ,(nix-system->gnu-triplet-for-rust) "]
498 llvm-config = \"" llvm "/bin/llvm-config" "\"
499 cc = \"" gcc "/bin/gcc" "\"
500 cxx = \"" gcc "/bin/g++" "\"
501 ar = \"" binutils "/bin/ar" "\"
502 jemalloc = \"" jemalloc "/lib/libjemalloc_pic.a" "\"
503 [dist]
504 ") port)))
505 #t)))
506 (add-after 'configure 'provide-cc
507 (lambda* (#:key inputs #:allow-other-keys)
508 (symlink (string-append (assoc-ref inputs "gcc") "/bin/gcc")
509 "/tmp/cc")
510 (setenv "PATH" (string-append "/tmp:" (getenv "PATH")))
511 #t))
512 (add-after 'provide-cc 'configure-archiver
513 (lambda* (#:key inputs #:allow-other-keys)
514 (substitute* "src/build_helper/lib.rs"
515 ;; Make sure "ar" is always used as the archiver.
516 (("\"musl\"") "\"\"")
517 ;; Then substitute "ar" by our name.
518 (("\"ar\"") (string-append "\""
519 (assoc-ref inputs "binutils")
520 "/bin/ar\"")))
521 #t))
522 (delete 'patch-cargo-tomls)
523 (add-before 'build 'reset-timestamps-after-changes
524 (lambda* _
525 (for-each
526 (lambda (filename)
527 ;; Rust 1.20.0 treats timestamp 0 as "file doesn't exist".
528 ;; Therefore, use timestamp 1.
529 (utime filename 1 1 1 1))
530 (find-files "." #:directories? #t))
531 #t))
532 (replace 'build
533 (lambda* _
534 (invoke "./x.py" "build")
535 (invoke "./x.py" "build" "src/tools/cargo")))
536 (replace 'check
537 (lambda* _
538 ;; Disable parallel execution to prevent EAGAIN errors when
539 ;; running tests.
540 (invoke "./x.py" "-j1" "test" "-vv")
541 (invoke "./x.py" "-j1" "test" "src/tools/cargo")
542 #t))
543 (replace 'install
544 (lambda* (#:key outputs #:allow-other-keys)
545 (invoke "./x.py" "install")
546 (substitute* "config.toml"
547 ;; replace prefix to specific output
548 (("prefix = \"[^\"]*\"")
549 (string-append "prefix = \"" (assoc-ref outputs "cargo") "\"")))
550 (invoke "./x.py" "install" "cargo")))
551 (add-after 'install 'wrap-rustc
552 (lambda* (#:key inputs outputs #:allow-other-keys)
553 (let ((out (assoc-ref outputs "out"))
554 (libc (assoc-ref inputs "libc"))
555 (ld-wrapper (assoc-ref inputs "ld-wrapper")))
556 ;; Let gcc find ld and libc startup files.
557 (wrap-program (string-append out "/bin/rustc")
558 `("PATH" ":" prefix (,(string-append ld-wrapper "/bin")))
559 `("LIBRARY_PATH" ":" suffix (,(string-append libc "/lib"))))
560 #t))))))))))
561
562 (define-public rust-1.21
563 (let ((base-rust (rust-bootstrapped-package rust-1.20 "1.21.0"
564 "1yj8lnxybjrybp00fqhxw8fpr641dh8wcn9mk44xjnsb4i1c21qp")))
565 (package
566 (inherit base-rust)
567 (arguments
568 (substitute-keyword-arguments (package-arguments base-rust)
569 ((#:phases phases)
570 `(modify-phases ,phases
571 (add-after 'configure 'remove-ar
572 (lambda* (#:key inputs #:allow-other-keys)
573 ;; Remove because toml complains about "unknown field".
574 (substitute* "config.toml"
575 (("^ar =.*") "\n"))
576 #t)))))))))
577
578 (define-public rust-1.22
579 (let ((base-rust (rust-bootstrapped-package rust-1.21 "1.22.1"
580 "1lrzzp0nh7s61wgfs2h6ilaqi6iq89f1pd1yaf65l87bssyl4ylb")))
581 (package
582 (inherit base-rust)
583 (arguments
584 (substitute-keyword-arguments (package-arguments base-rust)
585 ((#:phases phases)
586 `(modify-phases ,phases
587 (add-after 'unpack 'remove-flaky-test
588 (lambda _
589 ;; See <https://github.com/rust-lang/rust/issues/43402>.
590 (when (file-exists? "src/test/run-make/issue-26092")
591 (delete-file-recursively "src/test/run-make/issue-26092"))
592 #t)))))))))
593
594 (define-public rust-1.23
595 (let ((base-rust (rust-bootstrapped-package rust-1.22 "1.23.0"
596 "14fb8vhjzsxlbi6yrn1r6fl5dlbdd1m92dn5zj5gmzfwf4w9ar3l")))
597 (package
598 (inherit base-rust)
599 (arguments
600 (substitute-keyword-arguments (package-arguments base-rust)
601 ((#:phases phases)
602 `(modify-phases ,phases
603 (delete 'configure-archiver)
604 (delete 'remove-ar)
605 (add-after 'unpack 'dont-build-native
606 (lambda _
607 ;; XXX: Revisit this when we use gcc 6.
608 (substitute* "src/binaryen/CMakeLists.txt"
609 (("ADD_COMPILE_FLAG\\(\\\"-march=native\\\"\\)") ""))
610 #t)))))))))
611
612 (define-public rust-1.24
613 (let ((base-rust
614 (rust-bootstrapped-package rust-1.23 "1.24.1"
615 "1vv10x2h9kq7fxh2v01damdq8pvlp5acyh1kzcda9sfjx12kv99y")))
616 (package
617 (inherit base-rust)
618 (arguments
619 (substitute-keyword-arguments (package-arguments base-rust)
620 ((#:phases phases)
621 `(modify-phases ,phases
622 (delete 'use-readelf-for-tests)
623 (replace 'patch-aarch64-test
624 (lambda* _
625 (substitute* "src/librustc_metadata/dynamic_lib.rs"
626 ;; This test is known to fail on aarch64 and powerpc64le:
627 ;; https://github.com/rust-lang/rust/issues/45410
628 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
629 #t)))))))))
630
631 ;;; Rust 1.25 release support work with llvm 6--but build with llvm 6 is
632 ;;; not determenistic due to <https://github.com/rust-lang/rust/issues/50556>.
633 ;;; Keep using llvm 3.9.1 until builds become determenistic
634 (define-public rust-1.25
635 (let ((base-rust
636 (rust-bootstrapped-package rust-1.24 "1.25.0"
637 "0baxjr99311lvwdq0s38bipbnj72pn6fgbk6lcq7j555xq53mxpf"
638 #:patches '("rust-1.25-accept-more-detailed-gdb-lines.patch"))))
639 (package
640 (inherit base-rust)
641 (arguments
642 (substitute-keyword-arguments (package-arguments base-rust)
643 ((#:phases phases)
644 `(modify-phases ,phases
645 (add-after 'patch-cargo-tests 'patch-cargo-index-update
646 (lambda _
647 (substitute* "src/tools/cargo/tests/generate-lockfile.rs"
648 ;; This test wants to update the crate index.
649 (("fn no_index_update") "#[ignore]\nfn no_index_update"))
650 #t))
651 (replace 'patch-aarch64-test
652 (lambda _
653 (substitute* "src/librustc_metadata/dynamic_lib.rs"
654 ;; This test is known to fail on aarch64 and powerpc64le:
655 ;; https://github.com/rust-lang/rust/issues/45410
656 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
657 ;; This test fails on aarch64 with llvm@6.0:
658 ;; https://github.com/rust-lang/rust/issues/49807
659 ;; other possible solution:
660 ;; https://github.com/rust-lang/rust/pull/47688
661 (delete-file "src/test/debuginfo/by-value-self-argument-in-trait-impl.rs")
662 #t))
663 (delete 'ignore-glibc-2.27-incompatible-test))))))))
664
665 (define-public rust-1.26
666 (let ((base-rust
667 (rust-bootstrapped-package rust-1.25 "1.26.2"
668 "0047ais0fvmqvngqkdsxgrzhb0kljg8wy85b01kbbjc88hqcz7pv"
669 #:patches '("rust-coresimd-doctest.patch"
670 "rust-1.25-accept-more-detailed-gdb-lines.patch"))))
671 (package
672 (inherit base-rust)
673 (arguments
674 (substitute-keyword-arguments (package-arguments base-rust)
675 ((#:phases phases)
676 `(modify-phases ,phases
677 ;; binaryen was replaced with LLD project from LLVM
678 (delete 'dont-build-native)
679 (replace 'remove-unsupported-tests
680 (lambda* _
681 ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH.
682 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html>
683 (delete-file-recursively "src/test/run-make-fulldeps/linker-output-non-utf8")
684 #t))
685 (replace 'patch-cargo-tests
686 (lambda* _
687 (substitute* "src/tools/cargo/tests/testsuite/build.rs"
688 (("/usr/bin/env") (which "env"))
689 ;; Guix llvm is compiled without asmjs-unknown-emscripten.
690 (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs"))
691 (substitute* "src/tools/cargo/tests/testsuite/death.rs"
692 ;; This is stuck when built in container.
693 (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone"))
694 ;; Prints test output in the wrong order when built on
695 ;; i686-linux.
696 (substitute* "src/tools/cargo/tests/testsuite/test.rs"
697 (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env"))
698
699 ;; Avoid dependency on "git".
700 (substitute* "src/tools/cargo/tests/testsuite/new.rs"
701 (("fn author_prefers_cargo") "#[ignore]\nfn author_prefers_cargo")
702 (("fn finds_author_git") "#[ignore]\nfn finds_author_git")
703 (("fn finds_local_author_git") "#[ignore]\nfn finds_local_author_git"))
704 #t))
705 (add-after 'patch-cargo-tests 'disable-cargo-test-for-nightly-channel
706 (lambda* _
707 ;; This test failed to work on "nightly" channel builds
708 ;; https://github.com/rust-lang/cargo/issues/5648
709 (substitute* "src/tools/cargo/tests/testsuite/resolve.rs"
710 (("fn test_resolving_minimum_version_with_transitive_deps")
711 "#[ignore]\nfn test_resolving_minimum_version_with_transitive_deps"))
712 #t))
713 (replace 'patch-cargo-index-update
714 (lambda* _
715 (substitute* "src/tools/cargo/tests/testsuite/generate_lockfile.rs"
716 ;; This test wants to update the crate index.
717 (("fn no_index_update") "#[ignore]\nfn no_index_update"))
718 #t)))))))))
719
720 (define-public rust-1.27
721 (let ((base-rust
722 (rust-bootstrapped-package rust-1.26 "1.27.2"
723 "0pg1s37bhx9zqbynxyydq5j6q7kij9vxkcv8maz0m25prm88r0cs"
724 #:patches
725 '("rust-coresimd-doctest.patch"
726 "rust-bootstrap-stage0-test.patch"
727 "rust-1.25-accept-more-detailed-gdb-lines.patch"
728 "rust-reproducible-builds.patch"))))
729 (package
730 (inherit base-rust)
731 (arguments
732 (substitute-keyword-arguments (package-arguments base-rust)
733 ((#:phases phases)
734 `(modify-phases ,phases
735 (add-before 'install 'mkdir-prefix-paths
736 (lambda* (#:key outputs #:allow-other-keys)
737 ;; As result of https://github.com/rust-lang/rust/issues/36989
738 ;; `prefix' directory should exist before `install' call
739 (mkdir-p (assoc-ref outputs "out"))
740 (mkdir-p (assoc-ref outputs "cargo"))
741 #t))
742 (add-after 'patch-cargo-tests 'disable-thinlto-test
743 (lambda* _
744 ;; thinlto required llvm 6.0 for work
745 (substitute* "src/tools/cargo/tests/testsuite/path.rs"
746 (("fn thin_lto_works") "#[ignore]\nfn thin_lto_works"))
747 #t)))))))))
748
749 (define-public rust
750 (let ((base-rust
751 (rust-bootstrapped-package rust-1.27 "1.28.0"
752 "11k4rn77bca2rikykkk9fmprrgjswd4x4kaq7fia08vgkir82nhx"
753 #:patches
754 '("rust-coresimd-doctest.patch"
755 "rust-bootstrap-stage0-test.patch"
756 "rust-1.25-accept-more-detailed-gdb-lines.patch"
757 "rust-reproducible-builds.patch"))))
758 (package
759 (inherit base-rust)
760 (inputs
761 ;; Use LLVM 6.0
762 (alist-replace "llvm" (list llvm)
763 (package-inputs base-rust)))
764 (arguments
765 (substitute-keyword-arguments (package-arguments base-rust)
766 ((#:phases phases)
767 `(modify-phases ,phases
768 (add-after 'configure 'enable-codegen-tests
769 ;; Codegen tests should pass with llvm 6, so enable them.
770 (lambda* _
771 (substitute* "config.toml"
772 (("codegen-tests = false") ""))
773 #t))
774 (add-after 'patch-tests 'disable-amd64-avx-test
775 ;; That test would fail on x86_64 machines without avx.
776 (lambda* _
777 (substitute* "src/test/run-pass/issue-44056.rs"
778 (("only-x86_64") "ignore-test"))
779 #t))
780 ;; The thinlto test should pass with llvm 6.
781 (delete 'disable-thinlto-test))))))))