Merge branch 'ungrafting' into staging
[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 ;;; 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 (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 (let ((base-rust
1320 (rust-bootstrapped-package rust-1.45 "1.46.0"
1321 "0a17jby2pd050s24cy4dfc0gzvgcl585v3vvyfilniyvjrqknsid")))
1322 (package
1323 (inherit base-rust)
1324 (outputs (cons "rustfmt" (package-outputs base-rust)))
1325 (arguments
1326 (substitute-keyword-arguments (package-arguments base-rust)
1327 ((#:phases phases)
1328 `(modify-phases ,phases
1329 (replace 'build
1330 (lambda* _
1331 (invoke "./x.py" "build")
1332 (invoke "./x.py" "build" "src/tools/cargo")
1333 (invoke "./x.py" "build" "src/tools/rustfmt")))
1334 (replace 'check
1335 (lambda* _
1336 ;; Test rustfmt.
1337 (let ((parallel-job-spec
1338 (string-append "-j" (number->string
1339 (min 4
1340 (parallel-job-count))))))
1341 (invoke "./x.py" parallel-job-spec "test" "-vv")
1342 (invoke "./x.py" parallel-job-spec "test"
1343 "src/tools/cargo")
1344 (invoke "./x.py" parallel-job-spec "test"
1345 "src/tools/rustfmt"))))
1346 (replace 'install
1347 (lambda* (#:key outputs #:allow-other-keys)
1348 (invoke "./x.py" "install")
1349 (substitute* "config.toml"
1350 ;; replace prefix to specific output
1351 (("prefix = \"[^\"]*\"")
1352 (string-append "prefix = \"" (assoc-ref outputs "cargo") "\"")))
1353 (invoke "./x.py" "install" "cargo")
1354 (substitute* "config.toml"
1355 ;; replace prefix to specific output
1356 (("prefix = \"[^\"]*\"")
1357 (string-append "prefix = \"" (assoc-ref outputs "rustfmt") "\"")))
1358 (invoke "./x.py" "install" "rustfmt")))
1359 (replace 'delete-install-logs
1360 (lambda* (#:key outputs #:allow-other-keys)
1361 (define (delete-manifest-file out-path file)
1362 (delete-file (string-append out-path "/lib/rustlib/" file)))
1363
1364 (let ((out (assoc-ref outputs "out"))
1365 (cargo-out (assoc-ref outputs "cargo"))
1366 (rustfmt-out (assoc-ref outputs "rustfmt")))
1367 (for-each
1368 (lambda (file) (delete-manifest-file out file))
1369 '("install.log"
1370 "manifest-rust-docs"
1371 ,(string-append "manifest-rust-std-"
1372 (nix-system->gnu-triplet-for-rust))
1373 "manifest-rustc"))
1374 (for-each
1375 (lambda (file) (delete-manifest-file cargo-out file))
1376 '("install.log"
1377 "manifest-cargo"))
1378 (for-each
1379 (lambda (file) (delete-manifest-file rustfmt-out file))
1380 '("install.log"
1381 "manifest-rustfmt-preview"))
1382 #t))))))))))
1383
1384 ;; TODO(staging): Bump this variable to the latest packaged rust.
1385 (define-public rust rust-1.45)