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