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