Merge branch 'master' into ungrafting
[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 Nikita <nikita@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, 2020 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>
11 ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
12 ;;; Copyright © 2020 Pierre Langlois <pierre.langlois@gmx.com>
13 ;;;
14 ;;; This file is part of GNU Guix.
15 ;;;
16 ;;; GNU Guix is free software; you can redistribute it and/or modify it
17 ;;; under the terms of the GNU General Public License as published by
18 ;;; the Free Software Foundation; either version 3 of the License, or (at
19 ;;; your option) any later version.
20 ;;;
21 ;;; GNU Guix is distributed in the hope that it will be useful, but
22 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;;; GNU General Public License for more details.
25 ;;;
26 ;;; You should have received a copy of the GNU General Public License
27 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
28
29 (define-module (gnu packages rust)
30 #:use-module (gnu packages base)
31 #:use-module (gnu packages bison)
32 #:use-module (gnu packages bootstrap)
33 #:use-module (gnu packages cmake)
34 #:use-module (gnu packages compression)
35 #:use-module (gnu packages curl)
36 #:use-module (gnu packages elf)
37 #:use-module (gnu packages flex)
38 #:use-module (gnu packages gcc)
39 #:use-module (gnu packages gdb)
40 #:use-module (gnu packages jemalloc)
41 #:use-module (gnu packages linux)
42 #:use-module (gnu packages llvm)
43 #:use-module (gnu packages pkg-config)
44 #:use-module (gnu packages python)
45 #:use-module (gnu packages ssh)
46 #:use-module (gnu packages tls)
47 #:use-module (gnu packages)
48 #:use-module (guix build-system cargo)
49 #:use-module (guix build-system gnu)
50 #:use-module (guix build-system trivial)
51 #:use-module (guix download)
52 #:use-module (guix git-download)
53 #:use-module ((guix licenses) #:prefix license:)
54 #:use-module (guix packages)
55 #:use-module ((guix build utils) #:select (alist-replace))
56 #:use-module (guix utils)
57 #:use-module (ice-9 match)
58 #:use-module (srfi srfi-26))
59
60 ;; This is the hash for the empty file, and the reason it's relevant is not
61 ;; the most obvious.
62 ;;
63 ;; The root of the problem is that Cargo keeps track of a file called
64 ;; Cargo.lock, that contains the hash of the tarball source of each dependency.
65 ;;
66 ;; However, tarball sources aren't handled well by Guix because of the need to
67 ;; patch shebangs in any helper scripts. This is why we use Cargo's vendoring
68 ;; capabilities, where instead of the tarball, a directory is provided in its
69 ;; place. (In the case of rustc, the source code already ships with vendored
70 ;; dependencies, but crates built with cargo-build-system undergo vendoring
71 ;; during the build.)
72 ;;
73 ;; To preserve the advantages of checksumming, vendored dependencies contain
74 ;; a file called .cargo-checksum.json, which contains the hash of the tarball,
75 ;; as well as the list of files in it, with the hash of each file.
76 ;;
77 ;; The patch-cargo-checksums phase of cargo-build-system runs after
78 ;; any Guix-specific patches to the vendored dependencies and regenerates the
79 ;; .cargo-checksum.json files, but it's hard to know the tarball checksum that
80 ;; should be written to the file - and taking care of any unhandled edge case
81 ;; would require rebuilding everything that depends on rust. This is why we lie,
82 ;; and say that the tarball has the hash of an empty file. It's not a problem
83 ;; because cargo-build-system removes the Cargo.lock file. We can't do that
84 ;; for rustc because of a quirk of its build system, so we modify the lock file
85 ;; to substitute the hash.
86 (define %cargo-reference-hash
87 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
88
89 (define* (nix-system->gnu-triplet-for-rust
90 #:optional (system (%current-system)))
91 (match system
92 ("x86_64-linux" "x86_64-unknown-linux-gnu")
93 ("i686-linux" "i686-unknown-linux-gnu")
94 ("armhf-linux" "armv7-unknown-linux-gnueabihf")
95 ("aarch64-linux" "aarch64-unknown-linux-gnu")
96 ("mips64el-linux" "mips64el-unknown-linux-gnuabi64")
97 (_ (nix-system->gnu-triplet system))))
98
99 (define* (rust-uri version #:key (dist "static"))
100 (string-append "https://" dist ".rust-lang.org/dist/"
101 "rustc-" version "-src.tar.gz"))
102
103 (define* (rust-bootstrapped-package base-rust version checksum)
104 "Bootstrap rust VERSION with source checksum CHECKSUM using BASE-RUST."
105 (package
106 (inherit base-rust)
107 (version version)
108 (source
109 (origin
110 (inherit (package-source base-rust))
111 (uri (rust-uri version))
112 (sha256 (base32 checksum))))
113 (native-inputs
114 (alist-replace "cargo-bootstrap" (list base-rust "cargo")
115 (alist-replace "rustc-bootstrap" (list base-rust)
116 (package-native-inputs base-rust))))))
117
118 (define-public mrustc
119 (let ((rustc-version "1.19.0"))
120 (package
121 (name "mrustc")
122 (version "0.9")
123 (source (origin
124 (method git-fetch)
125 (uri (git-reference
126 (url "https://github.com/thepowersgang/mrustc")
127 (commit (string-append "v" version))))
128 (file-name (git-file-name name version))
129 (sha256
130 (base32
131 "194ny7vsks5ygiw7d8yxjmp1qwigd71ilchis6xjl6bb2sj97rd2"))))
132 (outputs '("out" "cargo"))
133 (build-system gnu-build-system)
134 (inputs
135 `(("zlib" ,zlib)))
136 (native-inputs
137 `(("bison" ,bison)
138 ("flex" ,flex)
139 ;; Required for the libstd sources.
140 ("rustc" ,(package-source rust-1.19))))
141 (arguments
142 `(#:test-target "test"
143 #:make-flags
144 (list ,(string-append "RUSTC_TARGET="
145 (or (%current-target-system)
146 (nix-system->gnu-triplet-for-rust))))
147 #:phases
148 (modify-phases %standard-phases
149 (add-after 'unpack 'patch-date
150 (lambda _
151 (substitute* "Makefile"
152 (("shell date") "shell date -d @1"))
153 (substitute* "run_rustc/Makefile"
154 (("[$]Vtime ") "$V "))
155 #t))
156 (add-after 'patch-date 'unpack-target-compiler
157 (lambda* (#:key inputs outputs #:allow-other-keys)
158 (invoke "tar" "xf" (assoc-ref inputs "rustc"))
159 (chdir ,(string-append "rustc-" rustc-version "-src"))
160 (invoke "patch" "-p0" ,(string-append "../rustc-" rustc-version
161 "-src.patch"))
162 (chdir "..")
163 (setenv "RUSTC_VERSION" ,rustc-version)
164 (setenv "MRUSTC_TARGET_VER"
165 ,(version-major+minor rustc-version))
166 (setenv "OUTDIR_SUF" "")
167 #t))
168 (replace 'configure
169 (lambda* (#:key inputs #:allow-other-keys)
170 (setenv "CC" (string-append (assoc-ref inputs "gcc")
171 "/bin/gcc"))
172 (setenv "CXX" (string-append (assoc-ref inputs "gcc")
173 "/bin/g++"))
174 #t))
175 (add-after 'build 'build-minicargo
176 (lambda* (#:key make-flags #:allow-other-keys)
177 ;; TODO: minicargo.mk: RUSTC_VERSION=$(RUSTC_VERSION) RUSTC_CHANNEL=$(RUSTC_SRC_TY) OUTDIR_SUF=$(OUTDIR_SUF)
178 (apply invoke "make" "-f" "minicargo.mk" "LIBS" make-flags)
179 (apply invoke "make" "-C" "tools/minicargo" make-flags)))
180 ;(add-after 'check 'check-locally
181 ; (lambda* (#:key make-flags #:allow-other-keys)
182 ; ;; The enum test wouldn't work otherwise.
183 ; ;; See <https://github.com/thepowersgang/mrustc/issues/137>.
184 ; (setenv "MRUSTC_TARGET_VER" ,(version-major+minor rustc-version))
185 ; (apply invoke "make" "local_tests" make-flags)))
186 (replace 'install
187 (lambda* (#:key inputs outputs #:allow-other-keys)
188 (let* ((out (assoc-ref outputs "out"))
189 (bin (string-append out "/bin"))
190 (tools-bin (string-append out "/tools/bin"))
191 (cargo-out (assoc-ref outputs "cargo"))
192 (cargo-bin (string-append cargo-out "/bin"))
193 (lib (string-append out "/lib"))
194 (lib/rust (string-append lib "/mrust"))
195 (gcc (assoc-ref inputs "gcc"))
196 (run_rustc (string-append out
197 "/share/mrustc/run_rustc")))
198 ;; These files are not reproducible.
199 (for-each delete-file (find-files "output" "\\.txt$"))
200 ;(delete-file-recursively "output/local_tests")
201 (mkdir-p (dirname lib/rust))
202 (copy-recursively "output" lib/rust)
203 (mkdir-p bin)
204 (mkdir-p tools-bin)
205 (install-file "bin/mrustc" bin)
206 ;; minicargo uses relative paths to resolve mrustc.
207 (install-file "tools/bin/minicargo" tools-bin)
208 (install-file "tools/bin/minicargo" cargo-bin)
209 (mkdir-p run_rustc)
210 (copy-file "run_rustc/Makefile"
211 (string-append run_rustc "/Makefile"))
212 #t))))))
213 (synopsis "Compiler for the Rust programming language")
214 (description "Rust is a systems programming language that provides memory
215 safety and thread safety guarantees.")
216 (home-page "https://github.com/thepowersgang/mrustc")
217 ;; Dual licensed.
218 (license (list license:asl2.0 license:expat)))))
219
220 (define rust-1.19
221 (package
222 (name "rust")
223 (version "1.19.0")
224 (source
225 (origin
226 (method url-fetch)
227 (uri (rust-uri "1.19.0"))
228 (sha256 (base32 "0l8c14qsf42rmkqy92ahij4vf356dbyspxcips1aswpvad81y8qm"))
229 (modules '((guix build utils)))
230 (snippet '(begin (delete-file-recursively "src/llvm") #t))
231 (patches (search-patches "rust-1.19-mrustc.patch"))))
232 (outputs '("out" "cargo"))
233 (properties '((timeout . 72000) ;20 hours
234 (max-silent-time . 18000))) ;5 hours (for armel)
235 (arguments
236 `(#:imported-modules ,%cargo-utils-modules ;for `generate-all-checksums'
237 #:modules ((guix build utils) (ice-9 match) (guix build gnu-build-system))
238 #:phases
239 (modify-phases %standard-phases
240 (add-after 'unpack 'set-env
241 (lambda* (#:key inputs #:allow-other-keys)
242 ;; Disable test for cross compilation support.
243 (setenv "CFG_DISABLE_CROSS_TESTS" "1")
244 (setenv "SHELL" (which "sh"))
245 (setenv "CONFIG_SHELL" (which "sh"))
246 (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
247 ;; guix llvm-3.9.1 package installs only shared libraries
248 (setenv "LLVM_LINK_SHARED" "1")
249 #t))
250 (add-after 'unpack 'patch-cargo-tomls
251 (lambda* (#:key inputs outputs #:allow-other-keys)
252 (substitute* "src/librustc_errors/Cargo.toml"
253 (("[[]dependencies[]]") "
254 [dependencies]
255 term = \"0.4.4\"
256 "))
257 (substitute* "src/librustc/Cargo.toml"
258 (("[[]dependencies[]]") "
259 [dependencies]
260 getopts = { path = \"../libgetopts\" }
261 "))
262 (substitute* "src/librustdoc/Cargo.toml"
263 (("[[]dependencies[]]") "
264 [dependencies]
265 test = { path = \"../libtest\" }
266 "))
267 #t))
268 (add-after 'unpack 'patch-tests
269 (lambda* (#:key inputs #:allow-other-keys)
270 (let ((bash (assoc-ref inputs "bash")))
271 (substitute* "src/libstd/process.rs"
272 ;; The newline is intentional.
273 ;; There's a line length "tidy" check in Rust which would
274 ;; fail otherwise.
275 (("\"/bin/sh\"") (string-append "\n\"" bash "/bin/sh\"")))
276 (substitute* "src/libstd/net/tcp.rs"
277 ;; There is no network in build environment
278 (("fn connect_timeout_unroutable")
279 "#[ignore]\nfn connect_timeout_unroutable"))
280 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00222.html>
281 (substitute* "src/libstd/sys/unix/process/process_common.rs"
282 (("fn test_process_mask") "#[allow(unused_attributes)]
283 #[ignore]
284 fn test_process_mask"))
285 #t)))
286 (add-after 'patch-tests 'patch-aarch64-test
287 (lambda* _
288 (substitute* "src/librustc_back/dynamic_lib.rs"
289 ;; This test is known to fail on aarch64 and powerpc64le:
290 ;; https://github.com/rust-lang/rust/issues/45410
291 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
292 #t))
293 (add-after 'patch-tests 'use-readelf-for-tests
294 (lambda* _
295 ;; nm doesn't recognize the file format because of the
296 ;; nonstandard sections used by the Rust compiler, but readelf
297 ;; ignores them.
298 (substitute* "src/test/run-make/atomic-lock-free/Makefile"
299 (("\tnm ")
300 "\treadelf -c "))
301 #t))
302 (add-after 'patch-tests 'remove-unsupported-tests
303 (lambda* _
304 ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH.
305 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html>
306 (delete-file-recursively "src/test/run-make/linker-output-non-utf8")
307 #t))
308 (add-after 'patch-source-shebangs 'patch-cargo-checksums
309 (lambda* _
310 (use-modules (guix build cargo-utils))
311 (substitute* "src/Cargo.lock"
312 (("(\"checksum .* = )\".*\"" all name)
313 (string-append name "\"" ,%cargo-reference-hash "\"")))
314 (generate-all-checksums "src/vendor")
315 #t))
316 ;; This phase is overridden by newer versions.
317 (replace 'configure
318 (const #t))
319 ;; This phase is overridden by newer versions.
320 (replace 'build
321 (lambda* (#:key inputs outputs #:allow-other-keys)
322 (let ((rustc-bootstrap (assoc-ref inputs "rustc-bootstrap")))
323 (setenv "CFG_COMPILER_HOST_TRIPLE"
324 ,(nix-system->gnu-triplet (%current-system)))
325 (setenv "CFG_RELEASE" "")
326 (setenv "CFG_RELEASE_CHANNEL" "stable")
327 (setenv "CFG_LIBDIR_RELATIVE" "lib")
328 (setenv "CFG_VERSION" "1.19.0-stable-mrustc")
329 (setenv "MRUSTC_TARGET_VER" ,(version-major+minor version))
330 ; bad: (setenv "CFG_PREFIX" "mrustc") ; FIXME output path.
331 (mkdir-p "output")
332 ;; mrustc 0.9 doesn't check the search paths for crates anymore.
333 (copy-recursively (string-append rustc-bootstrap "/lib/mrust")
334 "output")
335 (invoke (string-append rustc-bootstrap "/tools/bin/minicargo")
336 "src/rustc" "--vendor-dir" "src/vendor"
337 "--output-dir" "output/rustc-build"
338 "-L" (string-append rustc-bootstrap "/lib/mrust")
339 "-j" "1")
340 (setenv "CFG_COMPILER_HOST_TRIPLE" #f)
341 (setenv "CFG_RELEASE" #f)
342 (setenv "CFG_RELEASE_CHANNEL" #f)
343 (setenv "CFG_VERSION" #f)
344 (setenv "CFG_PREFIX" #f)
345 (setenv "CFG_LIBDIR_RELATIVE" #f)
346 (invoke (string-append rustc-bootstrap "/tools/bin/minicargo")
347 "src/tools/cargo" "--vendor-dir" "src/vendor"
348 "--output-dir" "output/cargo-build"
349 "-L" "output/"
350 "-L" (string-append rustc-bootstrap "/lib/mrust")
351 "-j" "1")
352 ;; Now use the newly-built rustc to build the libraries.
353 ;; One day that could be replaced by:
354 ;; (invoke "output/cargo-build/cargo" "build"
355 ;; "--manifest-path" "src/bootstrap/Cargo.toml"
356 ;; "--verbose") ; "--locked" "--frozen"
357 ;; but right now, Cargo has problems with libstd's circular
358 ;; dependencies.
359 (mkdir-p "output/target-libs")
360 (for-each (match-lambda
361 ((name . flags)
362 (write name)
363 (newline)
364 (apply invoke
365 "output/rustc-build/rustc"
366 "-C" (string-append "linker="
367 (getenv "CC"))
368 ;; Required for libterm.
369 "-Z" "force-unstable-if-unmarked"
370 "-L" "output/target-libs"
371 (string-append "src/" name "/lib.rs")
372 "-o"
373 (string-append "output/target-libs/"
374 (car (string-split name #\/))
375 ".rlib")
376 flags)))
377 '(("libcore")
378 ("libstd_unicode")
379 ("liballoc")
380 ("libcollections")
381 ("librand")
382 ("liblibc/src" "--cfg" "stdbuild")
383 ("libunwind" "-l" "gcc_s")
384 ("libcompiler_builtins")
385 ("liballoc_system")
386 ("libpanic_unwind")
387 ;; Uses "cc" to link.
388 ("libstd" "-l" "dl" "-l" "rt" "-l" "pthread")
389 ("libarena")
390
391 ;; Test dependencies:
392
393 ("libgetopts")
394 ("libterm")
395 ("libtest")))
396 #t)))
397 ;; This phase is overridden by newer versions.
398 (replace 'check
399 (const #t))
400 ;; This phase is overridden by newer versions.
401 (replace 'install
402 (lambda* (#:key inputs outputs #:allow-other-keys)
403 (let* ((out (assoc-ref outputs "out"))
404 (target-system ,(or (%current-target-system)
405 (nix-system->gnu-triplet
406 (%current-system))))
407 (out-libs (string-append out "/lib/rustlib/"
408 target-system "/lib")))
409 ;(setenv "CFG_PREFIX" out)
410 (mkdir-p out-libs)
411 (copy-recursively "output/target-libs" out-libs)
412 (install-file "output/rustc-build/rustc"
413 (string-append out "/bin"))
414 (install-file "output/rustc-build/rustdoc"
415 (string-append out "/bin"))
416 (install-file "output/cargo-build/cargo"
417 (string-append (assoc-ref outputs "cargo")
418 "/bin")))
419 #t)))))
420 (build-system gnu-build-system)
421 (native-inputs
422 `(("bison" ,bison) ; For the tests
423 ("cmake" ,cmake-minimal)
424 ("flex" ,flex) ; For the tests
425 ;; FIXME: Rust 1.27 and some later versions require GDB 8.2 specifically.
426 ;; See <https://bugs.gnu.org/37810>. Use it on all Rusts for simplicity.
427 ("gdb" ,gdb-8.2) ; For the tests
428 ("procps" ,procps) ; For the tests
429 ("python-2" ,python-2)
430 ("rustc-bootstrap" ,mrustc)
431 ("cargo-bootstrap" ,mrustc "cargo")
432 ("pkg-config" ,pkg-config) ; For "cargo"
433 ("which" ,which)))
434 (inputs
435 `(("jemalloc" ,jemalloc-4.5.0)
436 ("llvm" ,llvm-3.9.1)
437 ("openssl" ,openssl-1.0)
438 ("libssh2" ,libssh2) ; For "cargo"
439 ("libcurl" ,curl))) ; For "cargo"
440
441 ;; rustc invokes gcc, so we need to set its search paths accordingly.
442 ;; Note: duplicate its value here to cope with circular dependencies among
443 ;; modules (see <https://bugs.gnu.org/31392>).
444 (native-search-paths
445 (list (search-path-specification
446 (variable "C_INCLUDE_PATH")
447 (files '("include")))
448 (search-path-specification
449 (variable "CPLUS_INCLUDE_PATH")
450 (files '("include/c++" "include")))
451 (search-path-specification
452 (variable "LIBRARY_PATH")
453 (files '("lib" "lib64")))))
454
455 (supported-systems '("x86_64-linux"))
456 (synopsis "Compiler for the Rust programming language")
457 (description "Rust is a systems programming language that provides memory
458 safety and thread safety guarantees.")
459 (home-page "https://www.rust-lang.org")
460 ;; Dual licensed.
461 (license (list license:asl2.0 license:expat))))
462
463 (define-public rust-1.20
464 (let ((base-rust
465 (rust-bootstrapped-package rust-1.19 "1.20.0"
466 "0542y4rnzlsrricai130mqyxl8r6rd991frb4qsnwb27yigqg91a")))
467 (package
468 (inherit base-rust)
469 (source
470 (origin
471 (inherit (package-source base-rust))
472 (snippet '(begin
473 (delete-file-recursively "src/jemalloc")
474 (delete-file-recursively "src/llvm")
475 #t))
476 (patches '())))
477 (native-inputs
478 `(;; The tests fail with newer versions of GNU Make.
479 ("make" ,gnu-make-4.2)
480 ,@(package-native-inputs base-rust)))
481 (outputs '("out" "doc" "cargo"))
482 ;; Since rust-1.19 is local, it's quite probable that Hydra
483 ;; will build rust-1.19 only as a dependency of rust-1.20.
484 ;; But then Hydra will use the wrong properties, the ones here,
485 ;; for rust-1.19. Therefore, we copied the properties of
486 ;; rust-1.19 here.
487 (properties '((timeout . 72000) ;20 hours
488 (max-silent-time . 18000))) ;5 hours (for armel)
489 (arguments
490 (substitute-keyword-arguments (package-arguments rust-1.19)
491 ((#:phases phases)
492 `(modify-phases ,phases
493 (add-after 'patch-tests 'patch-cargo-tests
494 (lambda _
495 (substitute* "src/tools/cargo/tests/build.rs"
496 (("/usr/bin/env") (which "env"))
497 ;; Guix llvm is compiled without asmjs-unknown-emscripten.
498 (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs"))
499 (substitute* "src/tools/cargo/tests/death.rs"
500 ;; This is stuck when built in container.
501 (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone"))
502 ;; Prints test output in the wrong order when built on
503 ;; i686-linux.
504 (substitute* "src/tools/cargo/tests/test.rs"
505 (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env"))
506
507 ;; These tests pull in a dependency on "git", which changes
508 ;; too frequently take part in the Rust toolchain.
509 (substitute* "src/tools/cargo/tests/new.rs"
510 (("fn author_prefers_cargo") "#[ignore]\nfn author_prefers_cargo")
511 (("fn finds_author_git") "#[ignore]\nfn finds_author_git")
512 (("fn finds_local_author_git") "#[ignore]\nfn finds_local_author_git"))
513 #t))
514 (add-after 'patch-cargo-tests 'ignore-glibc-2.27-incompatible-test
515 ;; https://github.com/rust-lang/rust/issues/47863
516 (lambda _
517 (substitute* "src/test/run-pass/out-of-stack.rs"
518 (("// ignore-android") "// ignore-test\n// ignore-android"))
519 #t))
520 (replace 'configure
521 (lambda* (#:key inputs outputs #:allow-other-keys)
522 (let* ((out (assoc-ref outputs "out"))
523 (doc (assoc-ref outputs "doc"))
524 (gcc (assoc-ref inputs "gcc"))
525 (gdb (assoc-ref inputs "gdb"))
526 (binutils (assoc-ref inputs "binutils"))
527 (python (assoc-ref inputs "python-2"))
528 (rustc (assoc-ref inputs "rustc-bootstrap"))
529 (cargo (assoc-ref inputs "cargo-bootstrap"))
530 (llvm (assoc-ref inputs "llvm"))
531 (jemalloc (assoc-ref inputs "jemalloc")))
532 (call-with-output-file "config.toml"
533 (lambda (port)
534 (display (string-append "
535 [llvm]
536 [build]
537 cargo = \"" cargo "/bin/cargo" "\"
538 rustc = \"" rustc "/bin/rustc" "\"
539 docs = true
540 python = \"" python "/bin/python2" "\"
541 gdb = \"" gdb "/bin/gdb" "\"
542 vendor = true
543 submodules = false
544 [install]
545 prefix = \"" out "\"
546 docdir = \"" doc "/share/doc/rust" "\"
547 sysconfdir = \"etc\"
548 [rust]
549 default-linker = \"" gcc "/bin/gcc" "\"
550 channel = \"stable\"
551 rpath = true
552 " ;; There are 2 failed codegen tests:
553 ;; codegen/mainsubprogram.rs and codegen/mainsubprogramstart.rs
554 ;; These tests require a patched LLVM
555 "codegen-tests = false
556 [target." ,(nix-system->gnu-triplet-for-rust) "]
557 llvm-config = \"" llvm "/bin/llvm-config" "\"
558 cc = \"" gcc "/bin/gcc" "\"
559 cxx = \"" gcc "/bin/g++" "\"
560 ar = \"" binutils "/bin/ar" "\"
561 jemalloc = \"" jemalloc "/lib/libjemalloc_pic.a" "\"
562 [dist]
563 ") port)))
564 #t)))
565 (add-after 'configure 'provide-cc
566 (lambda* (#:key inputs #:allow-other-keys)
567 (symlink (string-append (assoc-ref inputs "gcc") "/bin/gcc")
568 "/tmp/cc")
569 (setenv "PATH" (string-append "/tmp:" (getenv "PATH")))
570 #t))
571 (add-after 'provide-cc 'configure-archiver
572 (lambda* (#:key inputs #:allow-other-keys)
573 (substitute* "src/build_helper/lib.rs"
574 ;; Make sure "ar" is always used as the archiver.
575 (("\"musl\"") "\"\"")
576 ;; Then substitute "ar" by our name.
577 (("\"ar\"") (string-append "\""
578 (assoc-ref inputs "binutils")
579 "/bin/ar\"")))
580 #t))
581 (delete 'patch-cargo-tomls)
582 (add-before 'build 'reset-timestamps-after-changes
583 (lambda* _
584 (for-each
585 (lambda (filename)
586 ;; Rust 1.20.0 treats timestamp 0 as "file doesn't exist".
587 ;; Therefore, use timestamp 1.
588 (utime filename 1 1 1 1))
589 (find-files "." #:directories? #t))
590 #t))
591 (replace 'build
592 (lambda* _
593 (invoke "./x.py" "build")
594 (invoke "./x.py" "build" "src/tools/cargo")))
595 (replace 'check
596 (lambda* _
597 ;; Disable parallel execution to prevent EAGAIN errors when
598 ;; running tests.
599 (invoke "./x.py" "-j1" "test" "-vv")
600 (invoke "./x.py" "-j1" "test" "src/tools/cargo")
601 #t))
602 (replace 'install
603 (lambda* (#:key outputs #:allow-other-keys)
604 (invoke "./x.py" "install")
605 (substitute* "config.toml"
606 ;; replace prefix to specific output
607 (("prefix = \"[^\"]*\"")
608 (string-append "prefix = \"" (assoc-ref outputs "cargo") "\"")))
609 (invoke "./x.py" "install" "cargo")))
610 (add-after 'install 'delete-install-logs
611 (lambda* (#:key outputs #:allow-other-keys)
612 (define (delete-manifest-file out-path file)
613 (delete-file (string-append out-path "/lib/rustlib/" file)))
614
615 (let ((out (assoc-ref outputs "out"))
616 (cargo-out (assoc-ref outputs "cargo")))
617 (for-each
618 (lambda (file) (delete-manifest-file out file))
619 '("install.log"
620 "manifest-rust-docs"
621 ,(string-append "manifest-rust-std-"
622 (nix-system->gnu-triplet-for-rust))
623 "manifest-rustc"))
624 (for-each
625 (lambda (file) (delete-manifest-file cargo-out file))
626 '("install.log"
627 "manifest-cargo"))
628 #t)))
629 (add-after 'install 'wrap-rustc
630 (lambda* (#:key inputs outputs #:allow-other-keys)
631 (let ((out (assoc-ref outputs "out"))
632 (libc (assoc-ref inputs "libc"))
633 (ld-wrapper (assoc-ref inputs "ld-wrapper")))
634 ;; Let gcc find ld and libc startup files.
635 (wrap-program (string-append out "/bin/rustc")
636 `("PATH" ":" prefix (,(string-append ld-wrapper "/bin")))
637 `("LIBRARY_PATH" ":" suffix (,(string-append libc "/lib"))))
638 #t))))))))))
639
640 (define-public rust-1.21
641 (let ((base-rust (rust-bootstrapped-package rust-1.20 "1.21.0"
642 "1yj8lnxybjrybp00fqhxw8fpr641dh8wcn9mk44xjnsb4i1c21qp")))
643 (package
644 (inherit base-rust)
645 (arguments
646 (substitute-keyword-arguments (package-arguments base-rust)
647 ((#:phases phases)
648 `(modify-phases ,phases
649 (add-after 'configure 'remove-ar
650 (lambda* (#:key inputs #:allow-other-keys)
651 ;; Remove because toml complains about "unknown field".
652 (substitute* "config.toml"
653 (("^ar =.*") "\n"))
654 #t)))))))))
655
656 (define-public rust-1.22
657 (let ((base-rust (rust-bootstrapped-package rust-1.21 "1.22.1"
658 "1lrzzp0nh7s61wgfs2h6ilaqi6iq89f1pd1yaf65l87bssyl4ylb")))
659 (package
660 (inherit base-rust)
661 (arguments
662 (substitute-keyword-arguments (package-arguments base-rust)
663 ((#:phases phases)
664 `(modify-phases ,phases
665 (add-after 'unpack 'remove-flaky-test
666 (lambda _
667 ;; See <https://github.com/rust-lang/rust/issues/43402>.
668 (when (file-exists? "src/test/run-make/issue-26092")
669 (delete-file-recursively "src/test/run-make/issue-26092"))
670 #t)))))))))
671
672 (define-public rust-1.23
673 (let ((base-rust (rust-bootstrapped-package rust-1.22 "1.23.0"
674 "14fb8vhjzsxlbi6yrn1r6fl5dlbdd1m92dn5zj5gmzfwf4w9ar3l")))
675 (package
676 (inherit base-rust)
677 (arguments
678 (substitute-keyword-arguments (package-arguments base-rust)
679 ((#:phases phases)
680 `(modify-phases ,phases
681 (delete 'configure-archiver)
682 (delete 'remove-ar)
683 (add-after 'unpack 'dont-build-native
684 (lambda _
685 ;; XXX: Revisit this when we use gcc 6.
686 (substitute* "src/binaryen/CMakeLists.txt"
687 (("ADD_COMPILE_FLAG\\(\\\"-march=native\\\"\\)") ""))
688 #t)))))))))
689
690 (define-public rust-1.24
691 (let ((base-rust
692 (rust-bootstrapped-package rust-1.23 "1.24.1"
693 "1vv10x2h9kq7fxh2v01damdq8pvlp5acyh1kzcda9sfjx12kv99y")))
694 (package
695 (inherit base-rust)
696 (arguments
697 (substitute-keyword-arguments (package-arguments base-rust)
698 ((#:phases phases)
699 `(modify-phases ,phases
700 (delete 'use-readelf-for-tests)
701 (replace 'patch-aarch64-test
702 (lambda* _
703 (substitute* "src/librustc_metadata/dynamic_lib.rs"
704 ;; This test is known to fail on aarch64 and powerpc64le:
705 ;; https://github.com/rust-lang/rust/issues/45410
706 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
707 #t)))))))))
708
709 ;;; Rust 1.25 release support work with llvm 6--but build with llvm 6 is
710 ;;; not determenistic due to <https://github.com/rust-lang/rust/issues/50556>.
711 ;;; Keep using llvm 3.9.1 until builds become determenistic
712 (define-public rust-1.25
713 (let ((base-rust
714 (rust-bootstrapped-package rust-1.24 "1.25.0"
715 "0baxjr99311lvwdq0s38bipbnj72pn6fgbk6lcq7j555xq53mxpf")))
716 (package
717 (inherit base-rust)
718 (source
719 (origin
720 (inherit (package-source base-rust))
721 (snippet '(begin
722 (delete-file-recursively "src/jemalloc")
723 (delete-file-recursively "src/llvm")
724 (delete-file-recursively "src/llvm-emscripten")
725 #t))
726 (patches (search-patches
727 "rust-1.25-accept-more-detailed-gdb-lines.patch"))))
728 (arguments
729 (substitute-keyword-arguments (package-arguments base-rust)
730 ((#:phases phases)
731 `(modify-phases ,phases
732 (add-after 'patch-cargo-tests 'patch-cargo-index-update
733 (lambda _
734 (substitute* "src/tools/cargo/tests/generate-lockfile.rs"
735 ;; This test wants to update the crate index.
736 (("fn no_index_update") "#[ignore]\nfn no_index_update"))
737 #t))
738 (replace 'patch-aarch64-test
739 (lambda _
740 (substitute* "src/librustc_metadata/dynamic_lib.rs"
741 ;; This test is known to fail on aarch64 and powerpc64le:
742 ;; https://github.com/rust-lang/rust/issues/45410
743 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
744 ;; This test fails on aarch64 with llvm@6.0:
745 ;; https://github.com/rust-lang/rust/issues/49807
746 ;; other possible solution:
747 ;; https://github.com/rust-lang/rust/pull/47688
748 (delete-file "src/test/debuginfo/by-value-self-argument-in-trait-impl.rs")
749 #t))
750 (delete 'ignore-glibc-2.27-incompatible-test))))))))
751
752 (define-public rust-1.26
753 (let ((base-rust
754 (rust-bootstrapped-package rust-1.25 "1.26.2"
755 "0047ais0fvmqvngqkdsxgrzhb0kljg8wy85b01kbbjc88hqcz7pv")))
756 (package
757 (inherit base-rust)
758 (source
759 (origin
760 (inherit (package-source base-rust))
761 (patches (search-patches
762 "rust-coresimd-doctest.patch"
763 "rust-1.25-accept-more-detailed-gdb-lines.patch"))))
764 (inputs
765 (alist-replace "openssl" (list openssl)
766 (package-inputs base-rust)))
767 (arguments
768 (substitute-keyword-arguments (package-arguments base-rust)
769 ((#:phases phases)
770 `(modify-phases ,phases
771 ;; binaryen was replaced with LLD project from LLVM
772 (delete 'dont-build-native)
773 (replace 'check
774 (lambda* _
775 ;; Enable parallel execution.
776 (let ((parallel-job-spec
777 (string-append "-j" (number->string
778 (min 4
779 (parallel-job-count))))))
780 (invoke "./x.py" parallel-job-spec "test" "-vv")
781 (invoke "./x.py" parallel-job-spec "test"
782 "src/tools/cargo"))))
783 (replace 'remove-unsupported-tests
784 (lambda* _
785 ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH.
786 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html>
787 (delete-file-recursively "src/test/run-make-fulldeps/linker-output-non-utf8")
788 #t))
789 (replace 'patch-cargo-tests
790 (lambda* _
791 (substitute* "src/tools/cargo/tests/testsuite/build.rs"
792 (("/usr/bin/env") (which "env"))
793 ;; Guix llvm is compiled without asmjs-unknown-emscripten.
794 (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs"))
795 (substitute* "src/tools/cargo/tests/testsuite/death.rs"
796 ;; This is stuck when built in container.
797 (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone"))
798 ;; Prints test output in the wrong order when built on
799 ;; i686-linux.
800 (substitute* "src/tools/cargo/tests/testsuite/test.rs"
801 (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env"))
802
803 ;; Avoid dependency on "git".
804 (substitute* "src/tools/cargo/tests/testsuite/new.rs"
805 (("fn author_prefers_cargo") "#[ignore]\nfn author_prefers_cargo")
806 (("fn finds_author_git") "#[ignore]\nfn finds_author_git")
807 (("fn finds_local_author_git") "#[ignore]\nfn finds_local_author_git"))
808 #t))
809 (add-after 'patch-cargo-tests 'disable-cargo-test-for-nightly-channel
810 (lambda* _
811 ;; This test failed to work on "nightly" channel builds
812 ;; https://github.com/rust-lang/cargo/issues/5648
813 (substitute* "src/tools/cargo/tests/testsuite/resolve.rs"
814 (("fn test_resolving_minimum_version_with_transitive_deps")
815 "#[ignore]\nfn test_resolving_minimum_version_with_transitive_deps"))
816 #t))
817 (replace 'patch-cargo-index-update
818 (lambda* _
819 (substitute* "src/tools/cargo/tests/testsuite/generate_lockfile.rs"
820 ;; This test wants to update the crate index.
821 (("fn no_index_update") "#[ignore]\nfn no_index_update"))
822 #t)))))))))
823
824 (define-public rust-1.27
825 (let ((base-rust
826 (rust-bootstrapped-package rust-1.26 "1.27.2"
827 "0pg1s37bhx9zqbynxyydq5j6q7kij9vxkcv8maz0m25prm88r0cs")))
828 (package
829 (inherit base-rust)
830 (source
831 (origin
832 (inherit (package-source base-rust))
833 (patches (search-patches "rust-coresimd-doctest.patch"
834 "rust-bootstrap-stage0-test.patch"
835 "rust-1.25-accept-more-detailed-gdb-lines.patch"
836 "rust-reproducible-builds.patch"))))
837 (arguments
838 (substitute-keyword-arguments (package-arguments base-rust)
839 ((#:phases phases)
840 `(modify-phases ,phases
841 (add-before 'install 'mkdir-prefix-paths
842 (lambda* (#:key outputs #:allow-other-keys)
843 ;; As result of https://github.com/rust-lang/rust/issues/36989
844 ;; `prefix' directory should exist before `install' call
845 (mkdir-p (assoc-ref outputs "out"))
846 (mkdir-p (assoc-ref outputs "cargo"))
847 #t))
848 (add-after 'patch-cargo-tests 'disable-thinlto-test
849 (lambda* _
850 ;; thinlto required llvm 6.0 for work
851 (substitute* "src/tools/cargo/tests/testsuite/path.rs"
852 (("fn thin_lto_works") "#[ignore]\nfn thin_lto_works"))
853 #t)))))))))
854
855 (define-public rust-1.28
856 (let ((base-rust
857 (rust-bootstrapped-package rust-1.27 "1.28.0"
858 "11k4rn77bca2rikykkk9fmprrgjswd4x4kaq7fia08vgkir82nhx")))
859 (package
860 (inherit base-rust)
861 (source
862 (origin
863 (inherit (package-source base-rust))
864 (patches (search-patches "rust-coresimd-doctest.patch"
865 "rust-bootstrap-stage0-test.patch"
866 "rust-1.25-accept-more-detailed-gdb-lines.patch"
867 "rust-reproducible-builds.patch"))))
868 (inputs
869 ;; Use LLVM 6.0
870 (alist-replace "llvm" (list llvm-6)
871 (package-inputs base-rust)))
872 (arguments
873 (substitute-keyword-arguments (package-arguments base-rust)
874 ((#:phases phases)
875 `(modify-phases ,phases
876 (add-after 'configure 'enable-codegen-tests
877 ;; Codegen tests should pass with llvm 6, so enable them.
878 (lambda* _
879 (substitute* "config.toml"
880 (("codegen-tests = false") ""))
881 #t))
882 (add-after 'patch-tests 'disable-amd64-avx-test
883 ;; That test would fail on x86_64 machines without avx.
884 (lambda* _
885 (substitute* "src/test/run-pass/issue-44056.rs"
886 (("only-x86_64") "ignore-test"))
887 #t))
888 ;; This is no longer needed as of 1.28
889 (delete 'disable-cargo-test-for-nightly-channel)
890 ;; The thinlto test should pass with llvm 6.
891 (delete 'disable-thinlto-test))))))))
892
893 (define-public rust-1.29
894 (let ((base-rust
895 (rust-bootstrapped-package rust-1.28 "1.29.2"
896 "1jb787080z754caa2w3w1amsygs4qlzj9rs1vy64firfmabfg22h")))
897 (package
898 (inherit base-rust)
899 (source
900 (origin
901 (inherit (package-source base-rust))
902 (patches (search-patches "rust-1.25-accept-more-detailed-gdb-lines.patch"
903 "rust-reproducible-builds.patch")))))))
904
905 (define-public rust-1.30
906 (let ((base-rust
907 (rust-bootstrapped-package rust-1.29 "1.30.1"
908 "0aavdc1lqv0cjzbqwl5n59yd0bqdlhn0zas61ljf38yrvc18k8rn")))
909 (package
910 (inherit base-rust)
911 (source
912 (origin
913 (inherit (package-source base-rust))
914 (snippet '(begin
915 (delete-file-recursively "src/jemalloc")
916 (delete-file-recursively "src/llvm")
917 (delete-file-recursively "src/llvm-emscripten")
918 (delete-file-recursively "src/tools/clang")
919 (delete-file-recursively "src/tools/lldb")
920 #t))))
921 (arguments
922 (substitute-keyword-arguments (package-arguments base-rust)
923 ((#:phases phases)
924 `(modify-phases ,phases
925 (add-after 'patch-cargo-tests 'patch-cargo-env-shebang
926 (lambda* (#:key inputs #:allow-other-keys)
927 (let ((coreutils (assoc-ref inputs "coreutils")))
928 (substitute* "src/tools/cargo/tests/testsuite/fix.rs"
929 ;; Cargo has a test which explicitly sets a
930 ;; RUSTC_WRAPPER environment variable which points
931 ;; to /usr/bin/env. Since it's not a shebang, it
932 ;; needs to be manually patched
933 (("\"/usr/bin/env\"")
934 (string-append "\"" coreutils "/bin/env\"")))
935 #t)))
936 (add-after 'patch-cargo-env-shebang 'ignore-cargo-package-tests
937 (lambda* _
938 (substitute* "src/tools/cargo/tests/testsuite/package.rs"
939 ;; These tests largely check that cargo outputs warning/error
940 ;; messages as expected. It seems that cargo outputs an
941 ;; absolute path to something in the store instead of the
942 ;; expected relative path (e.g. `[..]`) so we'll ignore
943 ;; these for now
944 (("fn include") "#[ignore]\nfn include")
945 (("fn exclude") "#[ignore]\nfn exclude"))
946 #t))
947 ;; The test has been moved elsewhere.
948 (replace 'disable-amd64-avx-test
949 (lambda _
950 (substitute* "src/test/ui/run-pass/issues/issue-44056.rs"
951 (("only-x86_64") "ignore-test"))
952 #t)))))))))
953
954 (define (patch-command-exec-tests-phase test-path)
955 "The command-exec.rs test moves around between releases. We need to apply
956 a Guix-specific patch to it for each release. This function generates the phase
957 that applies said patch, parametrized by the test-path. This is done this way
958 because the phase is more complex than the equivalents for other tests that
959 move around."
960 `(lambda* (#:key inputs #:allow-other-keys)
961 (let ((coreutils (assoc-ref inputs "coreutils")))
962 (substitute* ,test-path
963 ;; This test suite includes some tests that the stdlib's
964 ;; `Command` execution properly handles situations where
965 ;; the environment or PATH variable are empty, but this
966 ;; fails since we don't have `echo` available in the usual
967 ;; Linux directories.
968 ;; NB: the leading space is so we don't fail a tidy check
969 ;; for trailing whitespace, and the newlines are to ensure
970 ;; we don't exceed the 100 chars tidy check as well
971 ((" Command::new\\(\"echo\"\\)")
972 (string-append "\nCommand::new(\"" coreutils "/bin/echo\")\n")))
973 #t)))
974
975 (define-public rust-1.31
976 (let ((base-rust
977 (rust-bootstrapped-package rust-1.30 "1.31.1"
978 "0sk84ff0cklybcp0jbbxcw7lk7mrm6kb6km5nzd6m64dy0igrlli")))
979 (package
980 (inherit base-rust)
981 (arguments
982 (substitute-keyword-arguments (package-arguments base-rust)
983 ((#:phases phases)
984 `(modify-phases ,phases
985 (add-after 'patch-tests 'patch-command-exec-tests
986 ,(patch-command-exec-tests-phase
987 "src/test/run-pass/command-exec.rs"))
988 ;; The test has been moved elsewhere.
989 (replace 'disable-amd64-avx-test
990 (lambda _
991 (substitute* "src/test/ui/issues/issue-44056.rs"
992 (("only-x86_64") "ignore-test"))
993 #t))
994 (add-after 'patch-tests 'patch-process-docs-rev-cmd
995 (lambda* _
996 ;; Disable some doc tests which depend on the "rev" command
997 ;; https://github.com/rust-lang/rust/pull/58746
998 (substitute* "src/libstd/process.rs"
999 (("```rust") "```rust,no_run"))
1000 #t)))))))))
1001
1002 (define-public rust-1.32
1003 (let ((base-rust
1004 (rust-bootstrapped-package rust-1.31 "1.32.0"
1005 "0ji2l9xv53y27xy72qagggvq47gayr5lcv2jwvmfirx029vlqnac")))
1006 (package
1007 (inherit base-rust)
1008 (source
1009 (origin
1010 (inherit (package-source base-rust))
1011 (snippet '(begin (delete-file-recursively "src/llvm")
1012 (delete-file-recursively "src/llvm-emscripten")
1013 (delete-file-recursively "src/tools/clang")
1014 (delete-file-recursively "src/tools/lldb")
1015 (delete-file-recursively "vendor/jemalloc-sys/jemalloc")
1016 #t))
1017 (patches (search-patches "rust-reproducible-builds.patch"))
1018 ;; the vendor directory has moved to the root of
1019 ;; the tarball, so we have to strip an extra prefix
1020 (patch-flags '("-p2"))))
1021 (inputs
1022 ;; Downgrade to LLVM 6, all LTO tests appear to fail with LLVM 7.0.1
1023 (alist-replace "llvm" (list llvm-6)
1024 (package-inputs base-rust)))
1025 (arguments
1026 (substitute-keyword-arguments (package-arguments base-rust)
1027 ((#:phases phases)
1028 `(modify-phases ,phases
1029 ;; Cargo.lock and the vendor/ directory have been moved to the
1030 ;; root of the rust tarball
1031 (replace 'patch-cargo-checksums
1032 (lambda* _
1033 (use-modules (guix build cargo-utils))
1034 (substitute* "Cargo.lock"
1035 (("(\"checksum .* = )\".*\"" all name)
1036 (string-append name "\"" ,%cargo-reference-hash "\"")))
1037 (generate-all-checksums "vendor")
1038 #t))
1039 (add-after 'enable-codegen-tests 'override-jemalloc
1040 (lambda* (#:key inputs #:allow-other-keys)
1041 ;; The compiler is no longer directly built against jemalloc,
1042 ;; but rather via the jemalloc-sys crate (which vendors the
1043 ;; jemalloc source). To use jemalloc we must enable linking to
1044 ;; it (otherwise it would use the system allocator), and set
1045 ;; an environment variable pointing to the compiled jemalloc.
1046 (substitute* "config.toml"
1047 (("^jemalloc =.*$") "")
1048 (("[[]rust[]]") "\n[rust]\njemalloc=true\n"))
1049 (setenv "JEMALLOC_OVERRIDE" (string-append (assoc-ref inputs "jemalloc")
1050 "/lib/libjemalloc_pic.a"))
1051 #t))
1052 ;; Remove no longer relevant steps
1053 (delete 'remove-flaky-test)
1054 (delete 'patch-aarch64-test))))))))
1055
1056 (define-public rust-1.33
1057 (let ((base-rust
1058 (rust-bootstrapped-package rust-1.32 "1.33.0"
1059 "152x91mg7bz4ygligwjb05fgm1blwy2i70s2j03zc9jiwvbsh0as")))
1060 (package
1061 (inherit base-rust)
1062 (source
1063 (origin
1064 (inherit (package-source base-rust))
1065 (patches '())
1066 (patch-flags '("-p1"))))
1067 (inputs
1068 ;; Upgrade to jemalloc@5.1.0
1069 (alist-replace "jemalloc" (list jemalloc)
1070 (package-inputs base-rust)))
1071 (arguments
1072 (substitute-keyword-arguments (package-arguments base-rust)
1073 ((#:phases phases)
1074 `(modify-phases ,phases
1075 (delete 'ignore-cargo-package-tests)
1076 (add-after 'configure 'configure-test-threads
1077 ;; Several rustc and cargo tests will fail if run on one core
1078 ;; https://github.com/rust-lang/rust/issues/59122
1079 ;; https://github.com/rust-lang/cargo/issues/6746
1080 ;; https://github.com/rust-lang/rust/issues/58907
1081 (lambda* (#:key inputs #:allow-other-keys)
1082 (setenv "RUST_TEST_THREADS" "2")
1083 #t)))))))))
1084
1085 (define-public rust-1.34
1086 (let ((base-rust
1087 (rust-bootstrapped-package rust-1.33 "1.34.1"
1088 "19s09k7y5j6g3y4d2rk6kg9pvq6ml94c49w6b72dmq8p9lk8bixh")))
1089 (package
1090 (inherit base-rust)
1091 (source
1092 (origin
1093 (inherit (package-source base-rust))
1094 (snippet '(begin
1095 (delete-file-recursively "src/llvm-emscripten")
1096 (delete-file-recursively "src/llvm-project")
1097 (delete-file-recursively "vendor/jemalloc-sys/jemalloc")
1098 #t)))))))
1099
1100 (define-public rust-1.35
1101 (let ((base-rust
1102 (rust-bootstrapped-package rust-1.34 "1.35.0"
1103 "0bbizy6b7002v1rdhrxrf5gijclbyizdhkglhp81ib3bf5x66kas")))
1104 (package
1105 (inherit base-rust)
1106 (inputs
1107 (alist-replace "llvm" (list llvm-8)
1108 (package-inputs base-rust)))
1109 (arguments
1110 (substitute-keyword-arguments (package-arguments base-rust)
1111 ((#:phases phases)
1112 `(modify-phases ,phases
1113 ;; The tidy test includes a pass which ensures large binaries
1114 ;; don't accidentally get checked into the rust git repo.
1115 ;; Unfortunately the test assumes that git is always available,
1116 ;; so we'll comment out the invocation of this pass.
1117 (add-after 'configure 'disable-tidy-bins-check
1118 (lambda* _
1119 (substitute* "src/tools/tidy/src/main.rs"
1120 (("bins::check") "//bins::check"))
1121 #t)))))))))
1122
1123 (define-public rust-1.36
1124 (let ((base-rust
1125 (rust-bootstrapped-package rust-1.35 "1.36.0"
1126 "06xv2p6zq03lidr0yaf029ii8wnjjqa894nkmrm6s0rx47by9i04")))
1127 (package
1128 (inherit base-rust)
1129 (arguments
1130 (substitute-keyword-arguments (package-arguments base-rust)
1131 ((#:phases phases)
1132 `(modify-phases ,phases
1133 (delete 'patch-process-docs-rev-cmd))))))))
1134
1135 (define-public rust-1.37
1136 (let ((base-rust
1137 (rust-bootstrapped-package rust-1.36 "1.37.0"
1138 "1hrqprybhkhs6d9b5pjskfnc5z9v2l2gync7nb39qjb5s0h703hj")))
1139 (package
1140 (inherit base-rust)
1141 (arguments
1142 (substitute-keyword-arguments (package-arguments base-rust)
1143 ((#:phases phases)
1144 `(modify-phases ,phases
1145 (add-before 'configure 'configure-cargo-home
1146 (lambda _
1147 (let ((cargo-home (string-append (getcwd) "/.cargo")))
1148 (mkdir-p cargo-home)
1149 (setenv "CARGO_HOME" cargo-home)
1150 #t))))))))))
1151
1152 (define-public rust-1.38
1153 (let ((base-rust
1154 (rust-bootstrapped-package rust-1.37 "1.38.0"
1155 "101dlpsfkq67p0hbwx4acqq6n90dj4bbprndizpgh1kigk566hk4")))
1156 (package
1157 (inherit base-rust)
1158 (inputs
1159 (alist-replace "llvm" (list llvm-9)
1160 (package-inputs base-rust)))
1161 (arguments
1162 (substitute-keyword-arguments (package-arguments base-rust)
1163 ((#:phases phases)
1164 `(modify-phases ,phases
1165 (replace 'patch-command-exec-tests
1166 ,(patch-command-exec-tests-phase
1167 "src/test/ui/command-exec.rs"))
1168 (add-after 'patch-tests 'patch-command-uid-gid-test
1169 (lambda _
1170 (substitute* "src/test/ui/command-uid-gid.rs"
1171 (("/bin/sh") (which "sh"))
1172 (("ignore-sgx") "ignore-sgx\n// ignore-tidy-linelength"))
1173 #t)))))))))
1174
1175 (define-public rust-1.39
1176 (let ((base-rust
1177 (rust-bootstrapped-package rust-1.38 "1.39.0"
1178 "0mwkc1bnil2cfyf6nglpvbn2y0zfbv44zfhsd5qg4c9rm6vgd8dl")))
1179 (package
1180 (inherit base-rust)
1181 (arguments
1182 (substitute-keyword-arguments (package-arguments base-rust)
1183 ((#:phases phases)
1184 `(modify-phases ,phases
1185 (replace 'patch-cargo-checksums
1186 ;; The Cargo.lock format changed.
1187 (lambda* _
1188 (use-modules (guix build cargo-utils))
1189 (substitute* "Cargo.lock"
1190 (("(checksum = )\".*\"" all name)
1191 (string-append name "\"" ,%cargo-reference-hash "\"")))
1192 (generate-all-checksums "vendor")
1193 #t)))))))))
1194
1195 (define-public rust-1.40
1196 (let ((base-rust
1197 (rust-bootstrapped-package rust-1.39 "1.40.0"
1198 "1ba9llwhqm49w7sz3z0gqscj039m53ky9wxzhaj11z6yg1ah15yx")))
1199 (package
1200 (inherit base-rust)
1201 (source
1202 (origin
1203 (inherit (package-source base-rust))
1204 ;; llvm-emscripten is no longer bundled, as that codegen backend
1205 ;; got removed.
1206 (snippet '(begin
1207 (delete-file-recursively "src/llvm-project")
1208 (delete-file-recursively "vendor/jemalloc-sys/jemalloc")
1209 #t))))
1210 (arguments
1211 ;; Rust 1.40 does not ship rustc-internal libraries by default
1212 ;; (see rustc-dev-split). This means that librustc_driver.so is no
1213 ;; longer available in lib/rustlib/$target/lib, which is the directory
1214 ;; included in the runpath of librustc_codegen_llvm-llvm.so.
1215 ;; This is detected by our validate-runpath phase as an error, but it
1216 ;; is harmless as the codegen backend is loaded by librustc_driver.so
1217 ;; itself, which must at that point have been already loaded.
1218 ;; As such, we skip validating the runpath for Rust 1.40.
1219 ;; Rust 1.41 stopped putting the codegen backend in a separate library,
1220 ;; which makes this workaround only necessary for this release.
1221 (cons* #:validate-runpath? #f
1222 (substitute-keyword-arguments (package-arguments base-rust)
1223 ((#:phases phases)
1224 `(modify-phases ,phases
1225 ;; We often need to patch tests with various Guix-specific paths.
1226 ;; This often increases the line length and makes tidy, rustc's
1227 ;; style checker, complain. We could insert additional newlines
1228 ;; or add an "// ignore-tidy-linelength" comment, but as an
1229 ;; ignore comment must be used, both approaches are fragile due
1230 ;; to upstream formatting changes. As such, disable running the
1231 ;; linter during tests, since it's intended for rustc developers
1232 ;; anyway.
1233 ;;
1234 ;; TODO(rebuild-rust): This phase could be added earlier to
1235 ;; simplify a significant amount of code, but it would require
1236 ;; rebuilding the entire rusty universe.
1237 (add-after 'patch-tests 'neuter-tidy
1238 (lambda _
1239 (substitute* "src/bootstrap/builder.rs"
1240 (("^.*::Tidy,") ""))
1241 #t))
1242 ;; TODO(rebuild-rust): Adapt the find-files approach for
1243 ;; earlier testsuite patches.
1244 (replace 'patch-command-uid-gid-test
1245 (lambda _
1246 (match (find-files "src/test" "command-uid-gid\\.rs")
1247 ((file)
1248 (substitute* file
1249 (("/bin/sh") (which "sh")))))
1250 #t))
1251 (replace 'patch-command-exec-tests
1252 ,(patch-command-exec-tests-phase
1253 '(match (find-files "src/test" "command-exec\\.rs")
1254 ((file) file))))
1255 ;; The test got removed in commit 000fe63b6fc57b09828930cacbab20c2ee6e6d15
1256 ;; "Remove painful test that is not pulling its weight"
1257 (delete 'remove-unsupported-tests)))))))))
1258
1259 (define-public rust-1.41
1260 (let ((base-rust
1261 (rust-bootstrapped-package rust-1.40 "1.41.1"
1262 "0ws5x0fxv57fyllsa6025h3q6j9v3m8nb3syl4x0hgkddq0kvj9q")))
1263 (package
1264 (inherit base-rust)
1265 (arguments
1266 (substitute-keyword-arguments (package-arguments base-rust)
1267 ((#:validate-runpath? _) #t))))))
1268
1269 (define-public rust-1.42
1270 (rust-bootstrapped-package rust-1.41 "1.42.0"
1271 "0x9lxs82may6c0iln0b908cxyn1cv7h03n5cmbx3j1bas4qzks6j"))
1272
1273 (define-public rust-1.43
1274 (rust-bootstrapped-package rust-1.42 "1.43.0"
1275 "18akhk0wz1my6y9vhardriy2ysc482z0fnjdcgs9gy59kmnarxkm"))
1276
1277 (define-public rust-1.44
1278 (rust-bootstrapped-package rust-1.43 "1.44.1"
1279 "0ww4z2v3gxgn3zddqzwqya1gln04p91ykbrflnpdbmcd575n8bky"))
1280
1281 (define-public rust-1.45
1282 (let ((base-rust
1283 (rust-bootstrapped-package rust-1.44 "1.45.2"
1284 "0273a1g3f59plyi1n0azf21qjzwml1yqdnj5z472crz37qggr8xp")))
1285 (package
1286 (inherit base-rust)
1287 (source
1288 (origin
1289 (inherit (package-source base-rust))
1290 (patches (search-patches "rust-1.45-linker-locale.patch"))))
1291 (inputs
1292 (alist-replace "llvm" (list llvm-10)
1293 (package-inputs base-rust)))
1294 (arguments
1295 (substitute-keyword-arguments (package-arguments base-rust)
1296 ((#:phases phases)
1297 `(modify-phases ,phases
1298 ;; These tests make sure that the parser behaves properly when
1299 ;; a source file starts with a shebang. Unfortunately,
1300 ;; the patch-shebangs phase changes the meaning of these edge-cases.
1301 ;; We skip the test since it's drastically unlikely Guix's packaging
1302 ;; will introduce a bug here.
1303 (add-after 'patch-tests 'skip-shebang-tests
1304 (lambda _
1305 (with-directory-excursion "src/test/ui/parser/shebang"
1306 (delete-file "shebang-doc-comment.rs")
1307 (delete-file "sneaky-attrib.rs")
1308 #t)))
1309 ;; This test case synchronizes itself by starting a localhost TCP
1310 ;; server. This doesn't work as networking is not available.
1311 (add-after 'patch-tests 'skip-networking-test
1312 (lambda _
1313 (substitute* "src/tools/cargo/tests/testsuite/freshness.rs"
1314 (("fn linking_interrupted" all)
1315 (string-append "#[ignore] " all)))
1316 #t)))))))))
1317
1318 (define-public rust-1.46
1319 (rust-bootstrapped-package rust-1.45 "1.46.0"
1320 "0a17jby2pd050s24cy4dfc0gzvgcl585v3vvyfilniyvjrqknsid"))
1321
1322 ;; TODO(staging): Bump this variable to the latest packaged rust.
1323 (define-public rust rust-1.45)