gnu: git: Update to 2.28.0.
[jackhill/guix/guix.git] / gnu / packages / rust.scm
CommitLineData
423f9e44
DC
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2016 David Craven <david@craven.ch>
ecee2147 3;;; Copyright © 2016 Eric Le Bihan <eric.le.bihan.dev@free.fr>
3c986a7d 4;;; Copyright © 2016 Nikita <nikita@n0.is>
fa73a7c1 5;;; Copyright © 2017 Ben Woodcroft <donttrustben@gmail.com>
f342bb58 6;;; Copyright © 2017, 2018 Nikolai Merinov <nikolai.merinov@member.fsf.org>
25cdd9f7 7;;; Copyright © 2017, 2019, 2020 Efraim Flashner <efraim@flashner.co.il>
ca31f76b 8;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
a92bf11c 9;;; Copyright © 2018 Danny Milosavljevic <dannym+a@scratchpost.org>
7d141788 10;;; Copyright © 2019 Ivan Petkov <ivanppetkov@gmail.com>
7befec25 11;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
423f9e44
DC
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)
5f3d46ce 30 #:use-module (gnu packages bison)
423f9e44 31 #:use-module (gnu packages bootstrap)
ecee2147 32 #:use-module (gnu packages cmake)
423f9e44 33 #:use-module (gnu packages compression)
b5a09649 34 #:use-module (gnu packages curl)
423f9e44 35 #:use-module (gnu packages elf)
5f3d46ce 36 #:use-module (gnu packages flex)
423f9e44 37 #:use-module (gnu packages gcc)
d53fb678 38 #:use-module (gnu packages gdb)
ecee2147 39 #:use-module (gnu packages jemalloc)
5f3d46ce 40 #:use-module (gnu packages linux)
ecee2147 41 #:use-module (gnu packages llvm)
b5a09649 42 #:use-module (gnu packages pkg-config)
ecee2147 43 #:use-module (gnu packages python)
b5a09649
DC
44 #:use-module (gnu packages ssh)
45 #:use-module (gnu packages tls)
d53fb678 46 #:use-module (gnu packages)
b5a09649 47 #:use-module (guix build-system cargo)
423f9e44
DC
48 #:use-module (guix build-system gnu)
49 #:use-module (guix build-system trivial)
50 #:use-module (guix download)
a92bf11c 51 #:use-module (guix git-download)
423f9e44
DC
52 #:use-module ((guix licenses) #:prefix license:)
53 #:use-module (guix packages)
f342bb58
NM
54 #:use-module ((guix build utils) #:select (alist-replace))
55 #:use-module (guix utils)
423f9e44
DC
56 #:use-module (ice-9 match)
57 #:use-module (srfi srfi-26))
58
9483782a
JK
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.
d53fb678
NM
85(define %cargo-reference-hash
86 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
423f9e44 87
2c790226
MW
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
4ed20d3c
IP
98(define* (rust-uri version #:key (dist "static"))
99 (string-append "https://" dist ".rust-lang.org/dist/"
100 "rustc-" version "-src.tar.gz"))
339c1365 101
4ed20d3c
IP
102(define* (rust-bootstrapped-package base-rust version checksum)
103 "Bootstrap rust VERSION with source checksum CHECKSUM using BASE-RUST."
339c1365
IP
104 (package
105 (inherit base-rust)
106 (version version)
107 (source
4ed20d3c
IP
108 (origin
109 (inherit (package-source base-rust))
110 (uri (rust-uri version))
111 (sha256 (base32 checksum))))
24d298b4
DM
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")
5b600fca 121 (version "0.9")
24d298b4
DM
122 (source (origin
123 (method git-fetch)
124 (uri (git-reference
b0e7b699 125 (url "https://github.com/thepowersgang/mrustc")
24d298b4
DM
126 (commit (string-append "v" version))))
127 (file-name (git-file-name name version))
128 (sha256
129 (base32
5b600fca 130 "194ny7vsks5ygiw7d8yxjmp1qwigd71ilchis6xjl6bb2sj97rd2"))))
24d298b4
DM
131 (outputs '("out" "cargo"))
132 (build-system gnu-build-system)
133 (inputs
b07384b5 134 `(("zlib" ,zlib)))
24d298b4
DM
135 (native-inputs
136 `(("bison" ,bison)
137 ("flex" ,flex)
138 ;; Required for the libstd sources.
b07384b5 139 ("rustc" ,(package-source rust-1.19))))
24d298b4 140 (arguments
5b600fca 141 `(#:test-target "test"
b07384b5
DM
142 #:make-flags
143 (list ,(string-append "RUSTC_TARGET="
144 (or (%current-target-system)
145 (nix-system->gnu-triplet-for-rust))))
24d298b4
DM
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"))
b07384b5
DM
152 (substitute* "run_rustc/Makefile"
153 (("[$]Vtime ") "$V "))
24d298b4
DM
154 #t))
155 (add-after 'patch-date 'unpack-target-compiler
156 (lambda* (#:key inputs outputs #:allow-other-keys)
24d298b4 157 (invoke "tar" "xf" (assoc-ref inputs "rustc"))
b07384b5 158 (chdir ,(string-append "rustc-" rustc-version "-src"))
5b600fca
DM
159 (invoke "patch" "-p0" ,(string-append "../rustc-" rustc-version
160 "-src.patch"))
24d298b4 161 (chdir "..")
5b600fca
DM
162 (setenv "RUSTC_VERSION" ,rustc-version)
163 (setenv "MRUSTC_TARGET_VER"
164 ,(version-major+minor rustc-version))
165 (setenv "OUTDIR_SUF" "")
24d298b4
DM
166 #t))
167 (replace 'configure
168 (lambda* (#:key inputs #:allow-other-keys)
b07384b5
DM
169 (setenv "CC" (string-append (assoc-ref inputs "gcc")
170 "/bin/gcc"))
171 (setenv "CXX" (string-append (assoc-ref inputs "gcc")
172 "/bin/g++"))
24d298b4
DM
173 #t))
174 (add-after 'build 'build-minicargo
b07384b5 175 (lambda* (#:key make-flags #:allow-other-keys)
5b600fca 176 ;; TODO: minicargo.mk: RUSTC_VERSION=$(RUSTC_VERSION) RUSTC_CHANNEL=$(RUSTC_SRC_TY) OUTDIR_SUF=$(OUTDIR_SUF)
b07384b5
DM
177 (apply invoke "make" "-f" "minicargo.mk" "LIBS" make-flags)
178 (apply invoke "make" "-C" "tools/minicargo" make-flags)))
5b600fca
DM
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)))
24d298b4
DM
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"))
b07384b5 194 (gcc (assoc-ref inputs "gcc"))
5b600fca
DM
195 (run_rustc (string-append out
196 "/share/mrustc/run_rustc")))
24d298b4
DM
197 ;; These files are not reproducible.
198 (for-each delete-file (find-files "output" "\\.txt$"))
5b600fca
DM
199 ;(delete-file-recursively "output/local_tests")
200 (mkdir-p (dirname lib/rust))
24d298b4
DM
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)
b07384b5
DM
208 (mkdir-p run_rustc)
209 (copy-file "run_rustc/Makefile"
210 (string-append run_rustc "/Makefile"))
24d298b4 211 #t))))))
7af0f215 212 (synopsis "Compiler for the Rust programming language")
24d298b4
DM
213 (description "Rust is a systems programming language that provides memory
214safety and thread safety guarantees.")
215 (home-page "https://github.com/thepowersgang/mrustc")
216 ;; Dual licensed.
217 (license (list license:asl2.0 license:expat)))))
218
4f963b6f 219(define rust-1.19
ecee2147 220 (package
f342bb58 221 (name "rust")
8fdde581 222 (version "1.19.0")
4ed20d3c
IP
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))
e28a824f 230 (patches (search-patches "rust-1.19-mrustc.patch"))))
8fdde581 231 (outputs '("out" "cargo"))
b7c1c2b8
DM
232 (properties '((timeout . 72000) ;20 hours
233 (max-silent-time . 18000))) ;5 hours (for armel)
ecee2147 234 (arguments
e07b0488 235 `(#:imported-modules ,%cargo-utils-modules ;for `generate-all-checksums'
3159ef7c 236 #:modules ((guix build utils) (ice-9 match) (guix build gnu-build-system))
d53fb678 237 #:phases
ecee2147 238 (modify-phases %standard-phases
ecee2147 239 (add-after 'unpack 'set-env
1bb23335
NM
240 (lambda* (#:key inputs #:allow-other-keys)
241 ;; Disable test for cross compilation support.
242 (setenv "CFG_DISABLE_CROSS_TESTS" "1")
ecee2147 243 (setenv "SHELL" (which "sh"))
326249ba 244 (setenv "CONFIG_SHELL" (which "sh"))
1bb23335 245 (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
d53fb678
NM
246 ;; guix llvm-3.9.1 package installs only shared libraries
247 (setenv "LLVM_LINK_SHARED" "1")
326249ba 248 #t))
3159ef7c
DM
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]
254term = \"0.4.4\"
255"))
256 (substitute* "src/librustc/Cargo.toml"
257 (("[[]dependencies[]]") "
258[dependencies]
259getopts = { path = \"../libgetopts\" }
260"))
261 (substitute* "src/librustdoc/Cargo.toml"
262 (("[[]dependencies[]]") "
263[dependencies]
264test = { path = \"../libtest\" }
265"))
266 #t))
84aac61c
DM
267 (add-after 'unpack 'patch-tests
268 (lambda* (#:key inputs #:allow-other-keys)
9b7a9580 269 (let ((bash (assoc-ref inputs "bash")))
9b7a9580 270 (substitute* "src/libstd/process.rs"
5f3d46ce
DM
271 ;; The newline is intentional.
272 ;; There's a line length "tidy" check in Rust which would
273 ;; fail otherwise.
d53fb678
NM
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>
5f3d46ce 280 (substitute* "src/libstd/sys/unix/process/process_common.rs"
237587f1
DM
281 (("fn test_process_mask") "#[allow(unused_attributes)]
282 #[ignore]
af4ea9c5 283 fn test_process_mask"))
9b7a9580 284 #t)))
b47b2d32
NM
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))
d53fb678 307 (add-after 'patch-source-shebangs 'patch-cargo-checksums
f342bb58 308 (lambda* _
4585859f 309 (use-modules (guix build cargo-utils))
d53fb678
NM
310 (substitute* "src/Cargo.lock"
311 (("(\"checksum .* = )\".*\"" all name)
312 (string-append name "\"" ,%cargo-reference-hash "\"")))
e07b0488 313 (generate-all-checksums "src/vendor")
d53fb678 314 #t))
3159ef7c 315 ;; This phase is overridden by newer versions.
ecee2147 316 (replace 'configure
8fdde581 317 (const #t))
3159ef7c
DM
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")
5b600fca 328 (setenv "MRUSTC_TARGET_VER" ,(version-major+minor version))
3159ef7c
DM
329 ; bad: (setenv "CFG_PREFIX" "mrustc") ; FIXME output path.
330 (mkdir-p "output")
5b600fca
DM
331 ;; mrustc 0.9 doesn't check the search paths for crates anymore.
332 (copy-recursively (string-append rustc-bootstrap "/lib/mrust")
333 "output")
3159ef7c
DM
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")
3159ef7c
DM
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")
0bcd1bc7 359 (for-each (match-lambda
3159ef7c
DM
360 ((name . flags)
361 (write name)
362 (newline)
363 (apply invoke
364 "output/rustc-build/rustc"
365 "-C" (string-append "linker="
366 (getenv "CC"))
6c1a6584
DM
367 ;; Required for libterm.
368 "-Z" "force-unstable-if-unmarked"
3159ef7c
DM
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")
6c1a6584
DM
388 ("libarena")
389
390 ;; Test dependencies:
391
392 ("libgetopts")
393 ("libterm")
394 ("libtest")))
3159ef7c
DM
395 #t)))
396 ;; This phase is overridden by newer versions.
8fdde581
DM
397 (replace 'check
398 (const #t))
3159ef7c 399 ;; This phase is overridden by newer versions.
8fdde581 400 (replace 'install
3159ef7c
DM
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"))
5a3fcf5b
DM
413 (install-file "output/rustc-build/rustdoc"
414 (string-append out "/bin"))
3159ef7c
DM
415 (install-file "output/cargo-build/cargo"
416 (string-append (assoc-ref outputs "cargo")
417 "/bin")))
418 #t)))))
8fdde581
DM
419 (build-system gnu-build-system)
420 (native-inputs
421 `(("bison" ,bison) ; For the tests
c69959f0 422 ("cmake" ,cmake-minimal)
8fdde581 423 ("flex" ,flex) ; For the tests
6ba3980e
MB
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
8fdde581
DM
427 ("procps" ,procps) ; For the tests
428 ("python-2" ,python-2)
3159ef7c
DM
429 ("rustc-bootstrap" ,mrustc)
430 ("cargo-bootstrap" ,mrustc "cargo")
8fdde581
DM
431 ("pkg-config" ,pkg-config) ; For "cargo"
432 ("which" ,which)))
433 (inputs
434 `(("jemalloc" ,jemalloc-4.5.0)
435 ("llvm" ,llvm-3.9.1)
e74f153a 436 ("openssl" ,openssl-1.0)
e027a494
NM
437 ("libssh2" ,libssh2) ; For "cargo"
438 ("libcurl" ,curl))) ; For "cargo"
afc2bf53 439
8fdde581 440 ;; rustc invokes gcc, so we need to set its search paths accordingly.
afc2bf53
LC
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
fd1fde60 445 (variable "C_INCLUDE_PATH")
afc2bf53 446 (files '("include")))
fd1fde60
LC
447 (search-path-specification
448 (variable "CPLUS_INCLUDE_PATH")
449 (files '("include/c++" "include")))
afc2bf53
LC
450 (search-path-specification
451 (variable "LIBRARY_PATH")
452 (files '("lib" "lib64")))))
453
8fdde581
DM
454 (synopsis "Compiler for the Rust progamming language")
455 (description "Rust is a systems programming language that provides memory
456safety and thread safety guarantees.")
457 (home-page "https://www.rust-lang.org")
458 ;; Dual licensed.
459 (license (list license:asl2.0 license:expat))))
460
614cfd5c
DM
461(define-public rust-1.20
462 (let ((base-rust
4ed20d3c 463 (rust-bootstrapped-package rust-1.19 "1.20.0"
614cfd5c
DM
464 "0542y4rnzlsrricai130mqyxl8r6rd991frb4qsnwb27yigqg91a")))
465 (package
466 (inherit base-rust)
4ed20d3c
IP
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 '())))
47cd0feb
MB
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)))
614cfd5c 479 (outputs '("out" "doc" "cargo"))
7311ed3f
DM
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)
614cfd5c
DM
487 (arguments
488 (substitute-keyword-arguments (package-arguments rust-1.19)
489 ((#:phases phases)
490 `(modify-phases ,phases
1bfaae25
DM
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"))
01cef16f
MB
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"))
1bfaae25
DM
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))
614cfd5c
DM
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]
535cargo = \"" cargo "/bin/cargo" "\"
536rustc = \"" rustc "/bin/rustc" "\"
537docs = true
538python = \"" python "/bin/python2" "\"
539gdb = \"" gdb "/bin/gdb" "\"
540vendor = true
541submodules = false
542[install]
543prefix = \"" out "\"
544docdir = \"" doc "/share/doc/rust" "\"
545sysconfdir = \"etc\"
614cfd5c
DM
546[rust]
547default-linker = \"" gcc "/bin/gcc" "\"
614cfd5c
DM
548channel = \"stable\"
549rpath = 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) "]
555llvm-config = \"" llvm "/bin/llvm-config" "\"
556cc = \"" gcc "/bin/gcc" "\"
557cxx = \"" gcc "/bin/g++" "\"
91294b53 558ar = \"" binutils "/bin/ar" "\"
614cfd5c
DM
559jemalloc = \"" 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* _
614cfd5c
DM
582 (for-each
583 (lambda (filename)
e0b07ccc
DM
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))
614cfd5c
DM
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")))
bea01c0d
IP
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)))
614cfd5c
DM
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
05ebff92 637(define-public rust-1.21
4ed20d3c 638 (let ((base-rust (rust-bootstrapped-package rust-1.20 "1.21.0"
7bf169f7
DM
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)))))))))
05ebff92 652
1ab3e1dd 653(define-public rust-1.22
4ed20d3c 654 (let ((base-rust (rust-bootstrapped-package rust-1.21 "1.22.1"
8cddb0d6
DM
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)))))))))
1ab3e1dd 668
8fdde581 669(define-public rust-1.23
4ed20d3c 670 (let ((base-rust (rust-bootstrapped-package rust-1.22 "1.23.0"
44d530ef
DM
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)))))))))
b5a09649 686
fe61c88a 687(define-public rust-1.24
ca523cc5 688 (let ((base-rust
4ed20d3c 689 (rust-bootstrapped-package rust-1.23 "1.24.1"
339c1365 690 "1vv10x2h9kq7fxh2v01damdq8pvlp5acyh1kzcda9sfjx12kv99y")))
f342bb58
NM
691 (package
692 (inherit base-rust)
f342bb58
NM
693 (arguments
694 (substitute-keyword-arguments (package-arguments base-rust)
ca523cc5
DM
695 ((#:phases phases)
696 `(modify-phases ,phases
b47b2d32
NM
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"))
e0b07ccc 704 #t)))))))))
fe61c88a 705
e027a494
NM
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
b47b2d32
NM
709(define-public rust-1.25
710 (let ((base-rust
4ed20d3c
IP
711 (rust-bootstrapped-package rust-1.24 "1.25.0"
712 "0baxjr99311lvwdq0s38bipbnj72pn6fgbk6lcq7j555xq53mxpf")))
fe61c88a
NM
713 (package
714 (inherit base-rust)
4ed20d3c
IP
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))
e28a824f
JK
723 (patches (search-patches
724 "rust-1.25-accept-more-detailed-gdb-lines.patch"))))
fe61c88a
NM
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
080e11b4 730 (lambda _
fe61c88a
NM
731 (substitute* "src/tools/cargo/tests/generate-lockfile.rs"
732 ;; This test wants to update the crate index.
080e11b4
EF
733 (("fn no_index_update") "#[ignore]\nfn no_index_update"))
734 #t))
080e11b4
EF
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))
b47b2d32
NM
747 (delete 'ignore-glibc-2.27-incompatible-test))))))))
748
f510a2b9 749(define-public rust-1.26
b47b2d32 750 (let ((base-rust
4ed20d3c
IP
751 (rust-bootstrapped-package rust-1.25 "1.26.2"
752 "0047ais0fvmqvngqkdsxgrzhb0kljg8wy85b01kbbjc88hqcz7pv")))
b47b2d32
NM
753 (package
754 (inherit base-rust)
4ed20d3c
IP
755 (source
756 (origin
757 (inherit (package-source base-rust))
e28a824f
JK
758 (patches (search-patches
759 "rust-coresimd-doctest.patch"
760 "rust-1.25-accept-more-detailed-gdb-lines.patch"))))
b47b2d32
NM
761 (arguments
762 (substitute-keyword-arguments (package-arguments base-rust)
763 ((#:phases phases)
764 `(modify-phases ,phases
765 ;; binaryen was replaced with LLD project from LLVM
766 (delete 'dont-build-native)
55548cdc
DM
767 (replace 'check
768 (lambda* _
769 ;; Enable parallel execution.
770 (let ((parallel-job-spec
771 (string-append "-j" (number->string
772 (min 4
773 (parallel-job-count))))))
774 (invoke "./x.py" parallel-job-spec "test" "-vv")
775 (invoke "./x.py" parallel-job-spec "test"
776 "src/tools/cargo"))))
b47b2d32
NM
777 (replace 'remove-unsupported-tests
778 (lambda* _
779 ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH.
780 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html>
781 (delete-file-recursively "src/test/run-make-fulldeps/linker-output-non-utf8")
782 #t))
783 (replace 'patch-cargo-tests
784 (lambda* _
785 (substitute* "src/tools/cargo/tests/testsuite/build.rs"
786 (("/usr/bin/env") (which "env"))
787 ;; Guix llvm is compiled without asmjs-unknown-emscripten.
788 (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs"))
789 (substitute* "src/tools/cargo/tests/testsuite/death.rs"
790 ;; This is stuck when built in container.
791 (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone"))
792 ;; Prints test output in the wrong order when built on
793 ;; i686-linux.
794 (substitute* "src/tools/cargo/tests/testsuite/test.rs"
795 (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env"))
01cef16f
MB
796
797 ;; Avoid dependency on "git".
798 (substitute* "src/tools/cargo/tests/testsuite/new.rs"
799 (("fn author_prefers_cargo") "#[ignore]\nfn author_prefers_cargo")
800 (("fn finds_author_git") "#[ignore]\nfn finds_author_git")
801 (("fn finds_local_author_git") "#[ignore]\nfn finds_local_author_git"))
b47b2d32 802 #t))
7befec25 803 ;; TODO(rebuild-rust): Remove this phase in rust-1.28 when rebuilding.
b47b2d32
NM
804 (add-after 'patch-cargo-tests 'disable-cargo-test-for-nightly-channel
805 (lambda* _
806 ;; This test failed to work on "nightly" channel builds
807 ;; https://github.com/rust-lang/cargo/issues/5648
808 (substitute* "src/tools/cargo/tests/testsuite/resolve.rs"
809 (("fn test_resolving_minimum_version_with_transitive_deps")
810 "#[ignore]\nfn test_resolving_minimum_version_with_transitive_deps"))
811 #t))
812 (replace 'patch-cargo-index-update
813 (lambda* _
814 (substitute* "src/tools/cargo/tests/testsuite/generate_lockfile.rs"
815 ;; This test wants to update the crate index.
816 (("fn no_index_update") "#[ignore]\nfn no_index_update"))
817 #t)))))))))
f510a2b9 818
2e2b8635 819(define-public rust-1.27
f510a2b9 820 (let ((base-rust
4ed20d3c
IP
821 (rust-bootstrapped-package rust-1.26 "1.27.2"
822 "0pg1s37bhx9zqbynxyydq5j6q7kij9vxkcv8maz0m25prm88r0cs")))
f510a2b9
NM
823 (package
824 (inherit base-rust)
4ed20d3c
IP
825 (source
826 (origin
827 (inherit (package-source base-rust))
e28a824f
JK
828 (patches (search-patches "rust-coresimd-doctest.patch"
829 "rust-bootstrap-stage0-test.patch"
830 "rust-1.25-accept-more-detailed-gdb-lines.patch"
831 "rust-reproducible-builds.patch"))))
f510a2b9
NM
832 (arguments
833 (substitute-keyword-arguments (package-arguments base-rust)
834 ((#:phases phases)
835 `(modify-phases ,phases
836 (add-before 'install 'mkdir-prefix-paths
837 (lambda* (#:key outputs #:allow-other-keys)
838 ;; As result of https://github.com/rust-lang/rust/issues/36989
839 ;; `prefix' directory should exist before `install' call
840 (mkdir-p (assoc-ref outputs "out"))
841 (mkdir-p (assoc-ref outputs "cargo"))
e027a494
NM
842 #t))
843 (add-after 'patch-cargo-tests 'disable-thinlto-test
844 (lambda* _
845 ;; thinlto required llvm 6.0 for work
846 (substitute* "src/tools/cargo/tests/testsuite/path.rs"
847 (("fn thin_lto_works") "#[ignore]\nfn thin_lto_works"))
f510a2b9 848 #t)))))))))
2e2b8635 849
0e9811f4 850(define-public rust-1.28
2e2b8635 851 (let ((base-rust
4ed20d3c
IP
852 (rust-bootstrapped-package rust-1.27 "1.28.0"
853 "11k4rn77bca2rikykkk9fmprrgjswd4x4kaq7fia08vgkir82nhx")))
2e2b8635
NM
854 (package
855 (inherit base-rust)
4ed20d3c
IP
856 (source
857 (origin
858 (inherit (package-source base-rust))
e28a824f
JK
859 (patches (search-patches "rust-coresimd-doctest.patch"
860 "rust-bootstrap-stage0-test.patch"
861 "rust-1.25-accept-more-detailed-gdb-lines.patch"
862 "rust-reproducible-builds.patch"))))
2e2b8635
NM
863 (inputs
864 ;; Use LLVM 6.0
de6ad8c2 865 (alist-replace "llvm" (list llvm-6)
2e2b8635
NM
866 (package-inputs base-rust)))
867 (arguments
868 (substitute-keyword-arguments (package-arguments base-rust)
869 ((#:phases phases)
870 `(modify-phases ,phases
871 (add-after 'configure 'enable-codegen-tests
872 ;; Codegen tests should pass with llvm 6, so enable them.
873 (lambda* _
874 (substitute* "config.toml"
875 (("codegen-tests = false") ""))
876 #t))
877 (add-after 'patch-tests 'disable-amd64-avx-test
878 ;; That test would fail on x86_64 machines without avx.
879 (lambda* _
880 (substitute* "src/test/run-pass/issue-44056.rs"
881 (("only-x86_64") "ignore-test"))
882 #t))
883 ;; The thinlto test should pass with llvm 6.
884 (delete 'disable-thinlto-test))))))))
0e9811f4 885
1a3db0b2 886(define-public rust-1.29
0e9811f4 887 (let ((base-rust
4ed20d3c
IP
888 (rust-bootstrapped-package rust-1.28 "1.29.2"
889 "1jb787080z754caa2w3w1amsygs4qlzj9rs1vy64firfmabfg22h")))
0e9811f4 890 (package
4ed20d3c
IP
891 (inherit base-rust)
892 (source
893 (origin
894 (inherit (package-source base-rust))
e28a824f
JK
895 (patches (search-patches "rust-1.25-accept-more-detailed-gdb-lines.patch"
896 "rust-reproducible-builds.patch")))))))
1a3db0b2
IP
897
898(define-public rust-1.30
899 (let ((base-rust
4ed20d3c
IP
900 (rust-bootstrapped-package rust-1.29 "1.30.1"
901 "0aavdc1lqv0cjzbqwl5n59yd0bqdlhn0zas61ljf38yrvc18k8rn")))
1a3db0b2
IP
902 (package
903 (inherit base-rust)
4ed20d3c
IP
904 (source
905 (origin
906 (inherit (package-source base-rust))
907 (snippet '(begin
908 (delete-file-recursively "src/jemalloc")
909 (delete-file-recursively "src/llvm")
910 (delete-file-recursively "src/llvm-emscripten")
911 (delete-file-recursively "src/tools/clang")
912 (delete-file-recursively "src/tools/lldb")
f309420b 913 #t))))
1a3db0b2
IP
914 (arguments
915 (substitute-keyword-arguments (package-arguments base-rust)
916 ((#:phases phases)
917 `(modify-phases ,phases
918 (add-after 'patch-cargo-tests 'patch-cargo-env-shebang
919 (lambda* (#:key inputs #:allow-other-keys)
920 (let ((coreutils (assoc-ref inputs "coreutils")))
921 (substitute* "src/tools/cargo/tests/testsuite/fix.rs"
922 ;; Cargo has a test which explicitly sets a
923 ;; RUSTC_WRAPPER environment variable which points
924 ;; to /usr/bin/env. Since it's not a shebang, it
925 ;; needs to be manually patched
926 (("\"/usr/bin/env\"")
927 (string-append "\"" coreutils "/bin/env\"")))
928 #t)))
929 (add-after 'patch-cargo-env-shebang 'ignore-cargo-package-tests
930 (lambda* _
931 (substitute* "src/tools/cargo/tests/testsuite/package.rs"
932 ;; These tests largely check that cargo outputs warning/error
933 ;; messages as expected. It seems that cargo outputs an
934 ;; absolute path to something in the store instead of the
935 ;; expected relative path (e.g. `[..]`) so we'll ignore
936 ;; these for now
937 (("fn include") "#[ignore]\nfn include")
938 (("fn exclude") "#[ignore]\nfn exclude"))
939 #t))
586d30ca
DM
940 ;; The test has been moved elsewhere.
941 (replace 'disable-amd64-avx-test
942 (lambda _
943 (substitute* "src/test/ui/run-pass/issues/issue-44056.rs"
444bc2dd 944 (("only-x86_64") "ignore-test"))
586d30ca 945 #t)))))))))
1a3db0b2 946
444bc2dd
JK
947(define (patch-command-exec-tests-phase test-path)
948 "The command-exec.rs test moves around between releases. We need to apply
949a Guix-specific patch to it for each release. This function generates the phase
950that applies said patch, parametrized by the test-path. This is done this way
951because the phase is more complex than the equivalents for other tests that
952move around."
953 `(lambda* (#:key inputs #:allow-other-keys)
954 (let ((coreutils (assoc-ref inputs "coreutils")))
955 (substitute* ,test-path
956 ;; This test suite includes some tests that the stdlib's
957 ;; `Command` execution properly handles situations where
958 ;; the environment or PATH variable are empty, but this
959 ;; fails since we don't have `echo` available in the usual
960 ;; Linux directories.
961 ;; NB: the leading space is so we don't fail a tidy check
962 ;; for trailing whitespace, and the newlines are to ensure
963 ;; we don't exceed the 100 chars tidy check as well
964 ((" Command::new\\(\"echo\"\\)")
965 (string-append "\nCommand::new(\"" coreutils "/bin/echo\")\n")))
966 #t)))
967
d7d3bdca 968(define-public rust-1.31
1a3db0b2 969 (let ((base-rust
4ed20d3c
IP
970 (rust-bootstrapped-package rust-1.30 "1.31.1"
971 "0sk84ff0cklybcp0jbbxcw7lk7mrm6kb6km5nzd6m64dy0igrlli")))
1a3db0b2
IP
972 (package
973 (inherit base-rust)
974 (arguments
975 (substitute-keyword-arguments (package-arguments base-rust)
976 ((#:phases phases)
977 `(modify-phases ,phases
978 (add-after 'patch-tests 'patch-command-exec-tests
444bc2dd
JK
979 ,(patch-command-exec-tests-phase
980 "src/test/run-pass/command-exec.rs"))
981 ;; The test has been moved elsewhere.
982 (replace 'disable-amd64-avx-test
983 (lambda _
984 (substitute* "src/test/ui/issues/issue-44056.rs"
985 (("only-x86_64") "ignore-test"))
986 #t))
1a3db0b2
IP
987 (add-after 'patch-tests 'patch-process-docs-rev-cmd
988 (lambda* _
989 ;; Disable some doc tests which depend on the "rev" command
990 ;; https://github.com/rust-lang/rust/pull/58746
991 (substitute* "src/libstd/process.rs"
992 (("```rust") "```rust,no_run"))
993 #t)))))))))
d7d3bdca 994
6d511a53 995(define-public rust-1.32
d7d3bdca
IP
996 (let ((base-rust
997 (rust-bootstrapped-package rust-1.31 "1.32.0"
4ed20d3c 998 "0ji2l9xv53y27xy72qagggvq47gayr5lcv2jwvmfirx029vlqnac")))
d7d3bdca
IP
999 (package
1000 (inherit base-rust)
4ed20d3c
IP
1001 (source
1002 (origin
1003 (inherit (package-source base-rust))
1004 (snippet '(begin (delete-file-recursively "src/llvm")
1005 (delete-file-recursively "src/llvm-emscripten")
1006 (delete-file-recursively "src/tools/clang")
1007 (delete-file-recursively "src/tools/lldb")
1008 (delete-file-recursively "vendor/jemalloc-sys/jemalloc")
1009 #t))
e28a824f 1010 (patches (search-patches "rust-reproducible-builds.patch"))
4ed20d3c
IP
1011 ;; the vendor directory has moved to the root of
1012 ;; the tarball, so we have to strip an extra prefix
1013 (patch-flags '("-p2"))))
d7d3bdca
IP
1014 (inputs
1015 ;; Downgrade to LLVM 6, all LTO tests appear to fail with LLVM 7.0.1
1016 (alist-replace "llvm" (list llvm-6)
1017 (package-inputs base-rust)))
1018 (arguments
1019 (substitute-keyword-arguments (package-arguments base-rust)
1020 ((#:phases phases)
1021 `(modify-phases ,phases
1022 ;; Cargo.lock and the vendor/ directory have been moved to the
1023 ;; root of the rust tarball
1024 (replace 'patch-cargo-checksums
1025 (lambda* _
4585859f 1026 (use-modules (guix build cargo-utils))
d7d3bdca
IP
1027 (substitute* "Cargo.lock"
1028 (("(\"checksum .* = )\".*\"" all name)
1029 (string-append name "\"" ,%cargo-reference-hash "\"")))
e07b0488 1030 (generate-all-checksums "vendor")
d7d3bdca
IP
1031 #t))
1032 (add-after 'enable-codegen-tests 'override-jemalloc
1033 (lambda* (#:key inputs #:allow-other-keys)
1034 ;; The compiler is no longer directly built against jemalloc,
1035 ;; but rather via the jemalloc-sys crate (which vendors the
1036 ;; jemalloc source). To use jemalloc we must enable linking to
1037 ;; it (otherwise it would use the system allocator), and set
1038 ;; an environment variable pointing to the compiled jemalloc.
1039 (substitute* "config.toml"
1040 (("^jemalloc =.*$") "")
1041 (("[[]rust[]]") "\n[rust]\njemalloc=true\n"))
1042 (setenv "JEMALLOC_OVERRIDE" (string-append (assoc-ref inputs "jemalloc")
1043 "/lib/libjemalloc_pic.a"))
1044 #t))
1045 ;; Remove no longer relevant steps
1046 (delete 'remove-flaky-test)
1047 (delete 'patch-aarch64-test))))))))
6d511a53
IP
1048
1049(define-public rust-1.33
1050 (let ((base-rust
1051 (rust-bootstrapped-package rust-1.32 "1.33.0"
4ed20d3c 1052 "152x91mg7bz4ygligwjb05fgm1blwy2i70s2j03zc9jiwvbsh0as")))
6d511a53
IP
1053 (package
1054 (inherit base-rust)
4ed20d3c
IP
1055 (source
1056 (origin
1057 (inherit (package-source base-rust))
1058 (patches '())
1059 (patch-flags '("-p1"))))
6d511a53
IP
1060 (inputs
1061 ;; Upgrade to jemalloc@5.1.0
1062 (alist-replace "jemalloc" (list jemalloc)
1063 (package-inputs base-rust)))
1064 (arguments
1065 (substitute-keyword-arguments (package-arguments base-rust)
1066 ((#:phases phases)
1067 `(modify-phases ,phases
1068 (delete 'ignore-cargo-package-tests)
1069 (add-after 'configure 'configure-test-threads
1070 ;; Several rustc and cargo tests will fail if run on one core
1071 ;; https://github.com/rust-lang/rust/issues/59122
1072 ;; https://github.com/rust-lang/cargo/issues/6746
1073 ;; https://github.com/rust-lang/rust/issues/58907
1074 (lambda* (#:key inputs #:allow-other-keys)
1075 (setenv "RUST_TEST_THREADS" "2")
1076 #t)))))))))
1077
0ab5e91e 1078(define-public rust-1.34
a5c72da4 1079 (let ((base-rust
3d8033af
IP
1080 (rust-bootstrapped-package rust-1.33 "1.34.1"
1081 "19s09k7y5j6g3y4d2rk6kg9pvq6ml94c49w6b72dmq8p9lk8bixh")))
a5c72da4
IP
1082 (package
1083 (inherit base-rust)
1084 (source
1085 (origin
1086 (inherit (package-source base-rust))
1087 (snippet '(begin
1088 (delete-file-recursively "src/llvm-emscripten")
1089 (delete-file-recursively "src/llvm-project")
1090 (delete-file-recursively "vendor/jemalloc-sys/jemalloc")
1091 #t)))))))
0ab5e91e 1092
f67f93b6 1093(define-public rust-1.35
0ab5e91e
IP
1094 (let ((base-rust
1095 (rust-bootstrapped-package rust-1.34 "1.35.0"
1096 "0bbizy6b7002v1rdhrxrf5gijclbyizdhkglhp81ib3bf5x66kas")))
1097 (package
1098 (inherit base-rust)
f5de2b9a
IP
1099 (inputs
1100 (alist-replace "llvm" (list llvm-8)
1101 (package-inputs base-rust)))
0ab5e91e
IP
1102 (arguments
1103 (substitute-keyword-arguments (package-arguments base-rust)
1104 ((#:phases phases)
1105 `(modify-phases ,phases
1106 ;; The tidy test includes a pass which ensures large binaries
1107 ;; don't accidentally get checked into the rust git repo.
1108 ;; Unfortunately the test assumes that git is always available,
1109 ;; so we'll comment out the invocation of this pass.
1110 (add-after 'configure 'disable-tidy-bins-check
1111 (lambda* _
1112 (substitute* "src/tools/tidy/src/main.rs"
1113 (("bins::check") "//bins::check"))
1114 #t)))))))))
f67f93b6 1115
02c61278 1116(define-public rust-1.36
f67f93b6
IP
1117 (let ((base-rust
1118 (rust-bootstrapped-package rust-1.35 "1.36.0"
ca31f76b 1119 "06xv2p6zq03lidr0yaf029ii8wnjjqa894nkmrm6s0rx47by9i04")))
f67f93b6
IP
1120 (package
1121 (inherit base-rust)
1122 (arguments
1123 (substitute-keyword-arguments (package-arguments base-rust)
1124 ((#:phases phases)
1125 `(modify-phases ,phases
1126 (delete 'patch-process-docs-rev-cmd))))))))
02c61278 1127
444bc2dd 1128(define-public rust-1.37
02c61278
IP
1129 (let ((base-rust
1130 (rust-bootstrapped-package rust-1.36 "1.37.0"
1131 "1hrqprybhkhs6d9b5pjskfnc5z9v2l2gync7nb39qjb5s0h703hj")))
1132 (package
1133 (inherit base-rust)
1134 (arguments
1135 (substitute-keyword-arguments (package-arguments base-rust)
1136 ((#:phases phases)
1137 `(modify-phases ,phases
1138 (add-before 'configure 'configure-cargo-home
1139 (lambda _
1140 (let ((cargo-home (string-append (getcwd) "/.cargo")))
1141 (mkdir-p cargo-home)
1142 (setenv "CARGO_HOME" cargo-home)
1143 #t))))))))))
444bc2dd 1144
7befec25 1145;; TODO(rebuild-rust): Switch to LLVM 9 in 1.38 instead of 1.40.
444bc2dd
JK
1146(define-public rust-1.38
1147 (let ((base-rust
1148 (rust-bootstrapped-package rust-1.37 "1.38.0"
1149 "101dlpsfkq67p0hbwx4acqq6n90dj4bbprndizpgh1kigk566hk4")))
1150 (package
1151 (inherit base-rust)
7befec25
JK
1152 #;(inputs
1153 (alist-replace "llvm" (list llvm-9)
1154 (package-inputs base-rust)))
444bc2dd
JK
1155 (arguments
1156 (substitute-keyword-arguments (package-arguments base-rust)
1157 ((#:phases phases)
1158 `(modify-phases ,phases
1159 (replace 'patch-command-exec-tests
1160 ,(patch-command-exec-tests-phase
1161 "src/test/ui/command-exec.rs"))
1162 (add-after 'patch-tests 'patch-command-uid-gid-test
1163 (lambda _
1164 (substitute* "src/test/ui/command-uid-gid.rs"
1165 (("/bin/sh") (which "sh"))
1166 (("ignore-sgx") "ignore-sgx\n// ignore-tidy-linelength"))
1167 #t)))))))))
1168
9483782a
JK
1169(define-public rust-1.39
1170 (let ((base-rust
1171 (rust-bootstrapped-package rust-1.38 "1.39.0"
1172 "0mwkc1bnil2cfyf6nglpvbn2y0zfbv44zfhsd5qg4c9rm6vgd8dl")))
1173 (package
1174 (inherit base-rust)
1175 (arguments
1176 (substitute-keyword-arguments (package-arguments base-rust)
1177 ((#:phases phases)
1178 `(modify-phases ,phases
1179 (replace 'patch-cargo-checksums
1180 ;; The Cargo.lock format changed.
1181 (lambda* _
1182 (use-modules (guix build cargo-utils))
1183 (substitute* "Cargo.lock"
1184 (("(checksum = )\".*\"" all name)
1185 (string-append name "\"" ,%cargo-reference-hash "\"")))
1186 (generate-all-checksums "vendor")
1187 #t)))))))))
1188
7befec25
JK
1189(define-public rust-1.40
1190 (let ((base-rust
1191 (rust-bootstrapped-package rust-1.39 "1.40.0"
1192 "1ba9llwhqm49w7sz3z0gqscj039m53ky9wxzhaj11z6yg1ah15yx")))
1193 (package
1194 (inherit base-rust)
1195 (inputs
1196 (alist-replace "llvm" (list llvm-9)
1197 (package-inputs 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 ;; TODO(rebuild-rust): The test in question got fixed long ago.
1253 (delete 'disable-cargo-test-for-nightly-channel)
1254 ;; The test got removed in commit 000fe63b6fc57b09828930cacbab20c2ee6e6d15
1255 ;; "Remove painful test that is not pulling its weight"
1256 (delete 'remove-unsupported-tests)))))))))
1257
1258(define-public rust-1.41
1259 (let ((base-rust
1260 (rust-bootstrapped-package rust-1.40 "1.41.1"
1261 "0ws5x0fxv57fyllsa6025h3q6j9v3m8nb3syl4x0hgkddq0kvj9q")))
1262 (package
1263 (inherit base-rust)
1264 (arguments
1265 (substitute-keyword-arguments (package-arguments base-rust)
1266 ((#:validate-runpath? _) #t))))))
1267
1268(define-public rust-1.42
1269 (rust-bootstrapped-package rust-1.41 "1.42.0"
1270 "0x9lxs82may6c0iln0b908cxyn1cv7h03n5cmbx3j1bas4qzks6j"))
1271
1272(define-public rust-1.43
1273 (rust-bootstrapped-package rust-1.42 "1.43.0"
1274 "18akhk0wz1my6y9vhardriy2ysc482z0fnjdcgs9gy59kmnarxkm"))
1275
1276(define-public rust-1.44
1277 (rust-bootstrapped-package rust-1.43 "1.44.1"
1278 "0ww4z2v3gxgn3zddqzwqya1gln04p91ykbrflnpdbmcd575n8bky"))
1279
17666c09
JK
1280(define-public rust-1.45
1281 (let ((base-rust
1282 (rust-bootstrapped-package rust-1.44 "1.45.0"
1283 "0z6dh0yd3fcm3qh960wi4s6fa6pxz9mh77psycsqfkkx5kqra15s")))
1284 (package
1285 (inherit base-rust)
1286 (source
1287 (origin
1288 (inherit (package-source base-rust))
1289 (patches (search-patches "rust-1.45-linker-locale.patch"))))
1290 (inputs
1291 (alist-replace "llvm" (list llvm-10)
1292 (package-inputs base-rust)))
1293 (arguments
1294 (substitute-keyword-arguments (package-arguments base-rust)
1295 ((#:phases phases)
1296 `(modify-phases ,phases
1297 ;; These tests make sure that the parser behaves properly when
1298 ;; a source file starts with a shebang. Unfortunately,
1299 ;; the patch-shebangs phase changes the meaning of these edge-cases.
1300 ;; We skip the test since it's drastically unlikely Guix's packaging
1301 ;; will introduce a bug here.
1302 (add-after 'patch-tests 'skip-shebang-tests
1303 (lambda _
1304 (with-directory-excursion "src/test/ui/parser/shebang"
1305 (delete-file "shebang-doc-comment.rs")
1306 (delete-file "sneaky-attrib.rs")
1307 #t)))
1308 ;; This test case synchronizes itself by starting a localhost TCP
1309 ;; server. This doesn't work as networking is not available.
1310 (add-after 'patch-tests 'skip-networking-test
1311 (lambda _
1312 (substitute* "src/tools/cargo/tests/testsuite/freshness.rs"
1313 (("fn linking_interrupted" all)
1314 (string-append "#[ignore] " all)))
1315 #t)))))))))
7befec25
JK
1316
1317;; TODO(staging): Bump this variable to the latest packaged rust.
25cdd9f7 1318(define-public rust rust-1.45)