gnu: Add wl-clipboard.
[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>
4a78fd46 4;;; Copyright © 2016 Nils Gillmann <ng0@n0.is>
fa73a7c1 5;;; Copyright © 2017 Ben Woodcroft <donttrustben@gmail.com>
f342bb58 6;;; Copyright © 2017, 2018 Nikolai Merinov <nikolai.merinov@member.fsf.org>
fd3ddefa 7;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
af38b2dd 8;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
a92bf11c 9;;; Copyright © 2018 Danny Milosavljevic <dannym+a@scratchpost.org>
423f9e44
DC
10;;;
11;;; This file is part of GNU Guix.
12;;;
13;;; GNU Guix is free software; you can redistribute it and/or modify it
14;;; under the terms of the GNU General Public License as published by
15;;; the Free Software Foundation; either version 3 of the License, or (at
16;;; your option) any later version.
17;;;
18;;; GNU Guix is distributed in the hope that it will be useful, but
19;;; WITHOUT ANY WARRANTY; without even the implied warranty of
20;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21;;; GNU General Public License for more details.
22;;;
23;;; You should have received a copy of the GNU General Public License
24;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
25
26(define-module (gnu packages rust)
27 #:use-module (gnu packages base)
5f3d46ce 28 #:use-module (gnu packages bison)
423f9e44 29 #:use-module (gnu packages bootstrap)
ecee2147 30 #:use-module (gnu packages cmake)
423f9e44 31 #:use-module (gnu packages compression)
b5a09649 32 #:use-module (gnu packages curl)
423f9e44 33 #:use-module (gnu packages elf)
5f3d46ce 34 #:use-module (gnu packages flex)
423f9e44 35 #:use-module (gnu packages gcc)
d53fb678 36 #:use-module (gnu packages gdb)
ecee2147 37 #:use-module (gnu packages jemalloc)
5f3d46ce 38 #:use-module (gnu packages linux)
ecee2147 39 #:use-module (gnu packages llvm)
b5a09649 40 #:use-module (gnu packages pkg-config)
ecee2147 41 #:use-module (gnu packages python)
b5a09649
DC
42 #:use-module (gnu packages ssh)
43 #:use-module (gnu packages tls)
d53fb678 44 #:use-module (gnu packages)
b5a09649 45 #:use-module (guix build-system cargo)
423f9e44
DC
46 #:use-module (guix build-system gnu)
47 #:use-module (guix build-system trivial)
48 #:use-module (guix download)
a92bf11c 49 #:use-module (guix git-download)
423f9e44
DC
50 #:use-module ((guix licenses) #:prefix license:)
51 #:use-module (guix packages)
f342bb58
NM
52 #:use-module ((guix build utils) #:select (alist-replace))
53 #:use-module (guix utils)
423f9e44
DC
54 #:use-module (ice-9 match)
55 #:use-module (srfi srfi-26))
56
d53fb678
NM
57(define %cargo-reference-project-file "/dev/null")
58(define %cargo-reference-hash
59 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
423f9e44 60
2c790226
MW
61(define* (nix-system->gnu-triplet-for-rust
62 #:optional (system (%current-system)))
63 (match system
64 ("x86_64-linux" "x86_64-unknown-linux-gnu")
65 ("i686-linux" "i686-unknown-linux-gnu")
66 ("armhf-linux" "armv7-unknown-linux-gnueabihf")
67 ("aarch64-linux" "aarch64-unknown-linux-gnu")
68 ("mips64el-linux" "mips64el-unknown-linux-gnuabi64")
69 (_ (nix-system->gnu-triplet system))))
70
d53fb678 71\f
b47b2d32 72(define* (rust-source version hash #:key (patches '()))
f342bb58
NM
73 (origin
74 (method url-fetch)
75 (uri (string-append "https://static.rust-lang.org/dist/"
76 "rustc-" version "-src.tar.gz"))
77 (sha256 (base32 hash))
78 (modules '((guix build utils)))
b47b2d32
NM
79 (snippet '(begin (delete-file-recursively "src/llvm") #t))
80 (patches (map search-patch patches))))
f342bb58 81
24d298b4
DM
82(define* (rust-bootstrapped-package base-rust version checksum
83 #:key (patches '()))
84 "Bootstrap rust VERSION with source checksum CHECKSUM patched with PATCHES using BASE-RUST."
85 (package
86 (inherit base-rust)
87 (version version)
88 (source
89 (rust-source version checksum #:patches patches))
90 (native-inputs
91 (alist-replace "cargo-bootstrap" (list base-rust "cargo")
92 (alist-replace "rustc-bootstrap" (list base-rust)
93 (package-native-inputs base-rust))))))
94
95(define-public mrustc
96 (let ((rustc-version "1.19.0"))
97 (package
98 (name "mrustc")
99 (version "0.8.0")
100 (source (origin
101 (method git-fetch)
102 (uri (git-reference
103 (url "https://github.com/thepowersgang/mrustc.git")
104 (commit (string-append "v" version))))
105 (file-name (git-file-name name version))
106 (sha256
107 (base32
108 "0a7v8ccyzp1sdkwni8h1698hxpfz2sxhcpx42n6l2pbm0rbjp08i"))))
109 (outputs '("out" "cargo"))
110 (build-system gnu-build-system)
111 (inputs
112 `(("llvm" ,llvm-3.9.1)))
113 (native-inputs
114 `(("bison" ,bison)
115 ("flex" ,flex)
116 ;; Required for the libstd sources.
117 ("rustc"
118 ,(rust-source "1.19.0" "0l8c14qsf42rmkqy92ahij4vf356dbyspxcips1aswpvad81y8qm"))))
119 (arguments
4a90fcf9 120 `(#:test-target "local_tests"
24d298b4
DM
121 #:make-flags (list (string-append "LLVM_CONFIG="
122 (assoc-ref %build-inputs "llvm")
123 "/bin/llvm-config"))
124 #:phases
125 (modify-phases %standard-phases
126 (add-after 'unpack 'patch-date
127 (lambda _
128 (substitute* "Makefile"
129 (("shell date") "shell date -d @1"))
130 #t))
131 (add-after 'patch-date 'unpack-target-compiler
132 (lambda* (#:key inputs outputs #:allow-other-keys)
133 (substitute* "minicargo.mk"
134 ;; Don't try to build LLVM.
135 (("^[$][(]LLVM_CONFIG[)]:") "xxx:")
136 ;; Build for the correct target architecture.
137 (("^RUSTC_TARGET := x86_64-unknown-linux-gnu")
138 (string-append "RUSTC_TARGET := "
139 ,(or (%current-target-system)
140 (nix-system->gnu-triplet-for-rust)))))
141 (invoke "tar" "xf" (assoc-ref inputs "rustc"))
142 (chdir "rustc-1.19.0-src")
143 (invoke "patch" "-p0" "../rust_src.patch")
144 (chdir "..")
145 #t))
146 (replace 'configure
147 (lambda* (#:key inputs #:allow-other-keys)
148 (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
149 #t))
150 (add-after 'build 'build-minicargo
151 (lambda _
152 (for-each (lambda (target)
153 (invoke "make" "-f" "minicargo.mk" target))
154 '("output/libstd.hir" "output/libpanic_unwind.hir"
155 "output/libproc_macro.hir" "output/libtest.hir"))
156 ;; Technically the above already does it - but we want to be clear.
157 (invoke "make" "-C" "tools/minicargo")))
158 (replace 'install
159 (lambda* (#:key inputs outputs #:allow-other-keys)
160 (let* ((out (assoc-ref outputs "out"))
161 (bin (string-append out "/bin"))
162 (tools-bin (string-append out "/tools/bin"))
163 (cargo-out (assoc-ref outputs "cargo"))
164 (cargo-bin (string-append cargo-out "/bin"))
165 (lib (string-append out "/lib"))
166 (lib/rust (string-append lib "/mrust"))
167 (gcc (assoc-ref inputs "gcc")))
168 ;; These files are not reproducible.
169 (for-each delete-file (find-files "output" "\\.txt$"))
4a90fcf9 170 (delete-file-recursively "output/local_tests")
24d298b4
DM
171 (mkdir-p lib)
172 (copy-recursively "output" lib/rust)
173 (mkdir-p bin)
174 (mkdir-p tools-bin)
175 (install-file "bin/mrustc" bin)
176 ;; minicargo uses relative paths to resolve mrustc.
177 (install-file "tools/bin/minicargo" tools-bin)
178 (install-file "tools/bin/minicargo" cargo-bin)
179 #t))))))
180 (synopsis "Compiler for the Rust progamming language")
181 (description "Rust is a systems programming language that provides memory
182safety and thread safety guarantees.")
183 (home-page "https://github.com/thepowersgang/mrustc")
184 ;; Dual licensed.
185 (license (list license:asl2.0 license:expat)))))
186
4f963b6f 187(define rust-1.19
ecee2147 188 (package
f342bb58 189 (name "rust")
8fdde581 190 (version "1.19.0")
3159ef7c
DM
191 (source (rust-source version "0l8c14qsf42rmkqy92ahij4vf356dbyspxcips1aswpvad81y8qm"
192 #:patches '("rust-1.19-mrustc.patch")))
8fdde581 193 (outputs '("out" "cargo"))
b7c1c2b8
DM
194 (properties '((timeout . 72000) ;20 hours
195 (max-silent-time . 18000))) ;5 hours (for armel)
ecee2147 196 (arguments
d53fb678 197 `(#:imported-modules ,%cargo-build-system-modules ;for `generate-checksums'
3159ef7c 198 #:modules ((guix build utils) (ice-9 match) (guix build gnu-build-system))
d53fb678 199 #:phases
ecee2147 200 (modify-phases %standard-phases
ecee2147 201 (add-after 'unpack 'set-env
1bb23335
NM
202 (lambda* (#:key inputs #:allow-other-keys)
203 ;; Disable test for cross compilation support.
204 (setenv "CFG_DISABLE_CROSS_TESTS" "1")
ecee2147 205 (setenv "SHELL" (which "sh"))
326249ba 206 (setenv "CONFIG_SHELL" (which "sh"))
1bb23335 207 (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
d53fb678
NM
208 ;; guix llvm-3.9.1 package installs only shared libraries
209 (setenv "LLVM_LINK_SHARED" "1")
326249ba 210 #t))
3159ef7c
DM
211 (add-after 'unpack 'patch-cargo-tomls
212 (lambda* (#:key inputs outputs #:allow-other-keys)
213 (substitute* "src/librustc_errors/Cargo.toml"
214 (("[[]dependencies[]]") "
215[dependencies]
216term = \"0.4.4\"
217"))
218 (substitute* "src/librustc/Cargo.toml"
219 (("[[]dependencies[]]") "
220[dependencies]
221getopts = { path = \"../libgetopts\" }
222"))
223 (substitute* "src/librustdoc/Cargo.toml"
224 (("[[]dependencies[]]") "
225[dependencies]
226test = { path = \"../libtest\" }
227"))
228 #t))
84aac61c
DM
229 (add-after 'unpack 'patch-tests
230 (lambda* (#:key inputs #:allow-other-keys)
9b7a9580 231 (let ((bash (assoc-ref inputs "bash")))
9b7a9580 232 (substitute* "src/libstd/process.rs"
5f3d46ce
DM
233 ;; The newline is intentional.
234 ;; There's a line length "tidy" check in Rust which would
235 ;; fail otherwise.
d53fb678
NM
236 (("\"/bin/sh\"") (string-append "\n\"" bash "/bin/sh\"")))
237 (substitute* "src/libstd/net/tcp.rs"
238 ;; There is no network in build environment
239 (("fn connect_timeout_unroutable")
240 "#[ignore]\nfn connect_timeout_unroutable"))
241 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00222.html>
5f3d46ce 242 (substitute* "src/libstd/sys/unix/process/process_common.rs"
237587f1
DM
243 (("fn test_process_mask") "#[allow(unused_attributes)]
244 #[ignore]
af4ea9c5 245 fn test_process_mask"))
9b7a9580 246 #t)))
b47b2d32
NM
247 (add-after 'patch-tests 'patch-aarch64-test
248 (lambda* _
249 (substitute* "src/librustc_back/dynamic_lib.rs"
250 ;; This test is known to fail on aarch64 and powerpc64le:
251 ;; https://github.com/rust-lang/rust/issues/45410
252 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
253 #t))
254 (add-after 'patch-tests 'use-readelf-for-tests
255 (lambda* _
256 ;; nm doesn't recognize the file format because of the
257 ;; nonstandard sections used by the Rust compiler, but readelf
258 ;; ignores them.
259 (substitute* "src/test/run-make/atomic-lock-free/Makefile"
260 (("\tnm ")
261 "\treadelf -c "))
262 #t))
263 (add-after 'patch-tests 'remove-unsupported-tests
264 (lambda* _
265 ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH.
266 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html>
267 (delete-file-recursively "src/test/run-make/linker-output-non-utf8")
268 #t))
d53fb678 269 (add-after 'patch-source-shebangs 'patch-cargo-checksums
f342bb58 270 (lambda* _
d53fb678
NM
271 (substitute* "src/Cargo.lock"
272 (("(\"checksum .* = )\".*\"" all name)
273 (string-append name "\"" ,%cargo-reference-hash "\"")))
274 (for-each
275 (lambda (filename)
276 (use-modules (guix build cargo-build-system))
277 (delete-file filename)
278 (let* ((dir (dirname filename)))
279 (display (string-append
280 "patch-cargo-checksums: generate-checksums for "
281 dir "\n"))
282 (generate-checksums dir ,%cargo-reference-project-file)))
283 (find-files "src/vendor" ".cargo-checksum.json"))
284 #t))
3159ef7c 285 ;; This phase is overridden by newer versions.
ecee2147 286 (replace 'configure
8fdde581 287 (const #t))
3159ef7c
DM
288 ;; This phase is overridden by newer versions.
289 (replace 'build
290 (lambda* (#:key inputs outputs #:allow-other-keys)
291 (let ((rustc-bootstrap (assoc-ref inputs "rustc-bootstrap")))
292 (setenv "CFG_COMPILER_HOST_TRIPLE"
293 ,(nix-system->gnu-triplet (%current-system)))
294 (setenv "CFG_RELEASE" "")
295 (setenv "CFG_RELEASE_CHANNEL" "stable")
296 (setenv "CFG_LIBDIR_RELATIVE" "lib")
297 (setenv "CFG_VERSION" "1.19.0-stable-mrustc")
298 ; bad: (setenv "CFG_PREFIX" "mrustc") ; FIXME output path.
299 (mkdir-p "output")
300 (invoke (string-append rustc-bootstrap "/tools/bin/minicargo")
301 "src/rustc" "--vendor-dir" "src/vendor"
302 "--output-dir" "output/rustc-build"
303 "-L" (string-append rustc-bootstrap "/lib/mrust")
304 "-j" "1")
3159ef7c
DM
305 (setenv "CFG_COMPILER_HOST_TRIPLE" #f)
306 (setenv "CFG_RELEASE" #f)
307 (setenv "CFG_RELEASE_CHANNEL" #f)
308 (setenv "CFG_VERSION" #f)
309 (setenv "CFG_PREFIX" #f)
310 (setenv "CFG_LIBDIR_RELATIVE" #f)
311 (invoke (string-append rustc-bootstrap "/tools/bin/minicargo")
312 "src/tools/cargo" "--vendor-dir" "src/vendor"
313 "--output-dir" "output/cargo-build"
314 "-L" "output/"
315 "-L" (string-append rustc-bootstrap "/lib/mrust")
316 "-j" "1")
317 ;; Now use the newly-built rustc to build the libraries.
318 ;; One day that could be replaced by:
319 ;; (invoke "output/cargo-build/cargo" "build"
320 ;; "--manifest-path" "src/bootstrap/Cargo.toml"
321 ;; "--verbose") ; "--locked" "--frozen"
322 ;; but right now, Cargo has problems with libstd's circular
323 ;; dependencies.
324 (mkdir-p "output/target-libs")
0bcd1bc7 325 (for-each (match-lambda
3159ef7c
DM
326 ((name . flags)
327 (write name)
328 (newline)
329 (apply invoke
330 "output/rustc-build/rustc"
331 "-C" (string-append "linker="
332 (getenv "CC"))
6c1a6584
DM
333 ;; Required for libterm.
334 "-Z" "force-unstable-if-unmarked"
3159ef7c
DM
335 "-L" "output/target-libs"
336 (string-append "src/" name "/lib.rs")
337 "-o"
338 (string-append "output/target-libs/"
339 (car (string-split name #\/))
340 ".rlib")
341 flags)))
342 '(("libcore")
343 ("libstd_unicode")
344 ("liballoc")
345 ("libcollections")
346 ("librand")
347 ("liblibc/src" "--cfg" "stdbuild")
348 ("libunwind" "-l" "gcc_s")
349 ("libcompiler_builtins")
350 ("liballoc_system")
351 ("libpanic_unwind")
352 ;; Uses "cc" to link.
353 ("libstd" "-l" "dl" "-l" "rt" "-l" "pthread")
6c1a6584
DM
354 ("libarena")
355
356 ;; Test dependencies:
357
358 ("libgetopts")
359 ("libterm")
360 ("libtest")))
3159ef7c
DM
361 #t)))
362 ;; This phase is overridden by newer versions.
8fdde581
DM
363 (replace 'check
364 (const #t))
3159ef7c 365 ;; This phase is overridden by newer versions.
8fdde581 366 (replace 'install
3159ef7c
DM
367 (lambda* (#:key inputs outputs #:allow-other-keys)
368 (let* ((out (assoc-ref outputs "out"))
369 (target-system ,(or (%current-target-system)
370 (nix-system->gnu-triplet
371 (%current-system))))
372 (out-libs (string-append out "/lib/rustlib/"
373 target-system "/lib")))
374 ;(setenv "CFG_PREFIX" out)
375 (mkdir-p out-libs)
376 (copy-recursively "output/target-libs" out-libs)
377 (install-file "output/rustc-build/rustc"
378 (string-append out "/bin"))
5a3fcf5b
DM
379 (install-file "output/rustc-build/rustdoc"
380 (string-append out "/bin"))
3159ef7c
DM
381 (install-file "output/cargo-build/cargo"
382 (string-append (assoc-ref outputs "cargo")
383 "/bin")))
384 #t)))))
8fdde581
DM
385 (build-system gnu-build-system)
386 (native-inputs
387 `(("bison" ,bison) ; For the tests
388 ("cmake" ,cmake)
389 ("flex" ,flex) ; For the tests
390 ("gdb" ,gdb) ; For the tests
8fdde581
DM
391 ("procps" ,procps) ; For the tests
392 ("python-2" ,python-2)
3159ef7c
DM
393 ("rustc-bootstrap" ,mrustc)
394 ("cargo-bootstrap" ,mrustc "cargo")
8fdde581
DM
395 ("pkg-config" ,pkg-config) ; For "cargo"
396 ("which" ,which)))
397 (inputs
398 `(("jemalloc" ,jemalloc-4.5.0)
399 ("llvm" ,llvm-3.9.1)
400 ("openssl" ,openssl)
e027a494
NM
401 ("libssh2" ,libssh2) ; For "cargo"
402 ("libcurl" ,curl))) ; For "cargo"
afc2bf53 403
8fdde581 404 ;; rustc invokes gcc, so we need to set its search paths accordingly.
afc2bf53
LC
405 ;; Note: duplicate its value here to cope with circular dependencies among
406 ;; modules (see <https://bugs.gnu.org/31392>).
407 (native-search-paths
408 (list (search-path-specification
409 (variable "C_INCLUDE_PATH")
410 (files '("include")))
411 (search-path-specification
412 (variable "CPLUS_INCLUDE_PATH")
413 (files '("include")))
414 (search-path-specification
415 (variable "LIBRARY_PATH")
416 (files '("lib" "lib64")))))
417
8fdde581
DM
418 (synopsis "Compiler for the Rust progamming language")
419 (description "Rust is a systems programming language that provides memory
420safety and thread safety guarantees.")
421 (home-page "https://www.rust-lang.org")
422 ;; Dual licensed.
423 (license (list license:asl2.0 license:expat))))
424
614cfd5c
DM
425(define-public rust-1.20
426 (let ((base-rust
427 (rust-bootstrapped-package rust-1.19 "1.20.0"
428 "0542y4rnzlsrricai130mqyxl8r6rd991frb4qsnwb27yigqg91a")))
429 (package
430 (inherit base-rust)
431 (outputs '("out" "doc" "cargo"))
b7c1c2b8 432 (properties '())
614cfd5c
DM
433 (arguments
434 (substitute-keyword-arguments (package-arguments rust-1.19)
435 ((#:phases phases)
436 `(modify-phases ,phases
1bfaae25
DM
437 (add-after 'patch-tests 'patch-cargo-tests
438 (lambda _
439 (substitute* "src/tools/cargo/tests/build.rs"
440 (("/usr/bin/env") (which "env"))
441 ;; Guix llvm is compiled without asmjs-unknown-emscripten.
442 (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs"))
443 (substitute* "src/tools/cargo/tests/death.rs"
444 ;; This is stuck when built in container.
445 (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone"))
446 ;; Prints test output in the wrong order when built on
447 ;; i686-linux.
448 (substitute* "src/tools/cargo/tests/test.rs"
449 (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env"))
01cef16f
MB
450
451 ;; These tests pull in a dependency on "git", which changes
452 ;; too frequently take part in the Rust toolchain.
453 (substitute* "src/tools/cargo/tests/new.rs"
454 (("fn author_prefers_cargo") "#[ignore]\nfn author_prefers_cargo")
455 (("fn finds_author_git") "#[ignore]\nfn finds_author_git")
456 (("fn finds_local_author_git") "#[ignore]\nfn finds_local_author_git"))
1bfaae25
DM
457 #t))
458 (add-after 'patch-cargo-tests 'ignore-glibc-2.27-incompatible-test
459 ;; https://github.com/rust-lang/rust/issues/47863
460 (lambda _
461 (substitute* "src/test/run-pass/out-of-stack.rs"
462 (("// ignore-android") "// ignore-test\n// ignore-android"))
463 #t))
614cfd5c
DM
464 (replace 'configure
465 (lambda* (#:key inputs outputs #:allow-other-keys)
466 (let* ((out (assoc-ref outputs "out"))
467 (doc (assoc-ref outputs "doc"))
468 (gcc (assoc-ref inputs "gcc"))
469 (gdb (assoc-ref inputs "gdb"))
470 (binutils (assoc-ref inputs "binutils"))
471 (python (assoc-ref inputs "python-2"))
472 (rustc (assoc-ref inputs "rustc-bootstrap"))
473 (cargo (assoc-ref inputs "cargo-bootstrap"))
474 (llvm (assoc-ref inputs "llvm"))
475 (jemalloc (assoc-ref inputs "jemalloc")))
476 (call-with-output-file "config.toml"
477 (lambda (port)
478 (display (string-append "
479[llvm]
480[build]
481cargo = \"" cargo "/bin/cargo" "\"
482rustc = \"" rustc "/bin/rustc" "\"
483docs = true
484python = \"" python "/bin/python2" "\"
485gdb = \"" gdb "/bin/gdb" "\"
486vendor = true
487submodules = false
488[install]
489prefix = \"" out "\"
490docdir = \"" doc "/share/doc/rust" "\"
491sysconfdir = \"etc\"
614cfd5c
DM
492[rust]
493default-linker = \"" gcc "/bin/gcc" "\"
614cfd5c
DM
494channel = \"stable\"
495rpath = true
496" ;; There are 2 failed codegen tests:
497;; codegen/mainsubprogram.rs and codegen/mainsubprogramstart.rs
498;; These tests require a patched LLVM
499"codegen-tests = false
500[target." ,(nix-system->gnu-triplet-for-rust) "]
501llvm-config = \"" llvm "/bin/llvm-config" "\"
502cc = \"" gcc "/bin/gcc" "\"
503cxx = \"" gcc "/bin/g++" "\"
91294b53 504ar = \"" binutils "/bin/ar" "\"
614cfd5c
DM
505jemalloc = \"" jemalloc "/lib/libjemalloc_pic.a" "\"
506[dist]
507") port)))
508 #t)))
509 (add-after 'configure 'provide-cc
510 (lambda* (#:key inputs #:allow-other-keys)
511 (symlink (string-append (assoc-ref inputs "gcc") "/bin/gcc")
512 "/tmp/cc")
513 (setenv "PATH" (string-append "/tmp:" (getenv "PATH")))
514 #t))
515 (add-after 'provide-cc 'configure-archiver
516 (lambda* (#:key inputs #:allow-other-keys)
517 (substitute* "src/build_helper/lib.rs"
518 ;; Make sure "ar" is always used as the archiver.
519 (("\"musl\"") "\"\"")
520 ;; Then substitute "ar" by our name.
521 (("\"ar\"") (string-append "\""
522 (assoc-ref inputs "binutils")
523 "/bin/ar\"")))
524 #t))
525 (delete 'patch-cargo-tomls)
526 (add-before 'build 'reset-timestamps-after-changes
527 (lambda* _
614cfd5c
DM
528 (for-each
529 (lambda (filename)
e0b07ccc
DM
530 ;; Rust 1.20.0 treats timestamp 0 as "file doesn't exist".
531 ;; Therefore, use timestamp 1.
532 (utime filename 1 1 1 1))
614cfd5c
DM
533 (find-files "." #:directories? #t))
534 #t))
535 (replace 'build
536 (lambda* _
537 (invoke "./x.py" "build")
538 (invoke "./x.py" "build" "src/tools/cargo")))
539 (replace 'check
540 (lambda* _
541 ;; Disable parallel execution to prevent EAGAIN errors when
542 ;; running tests.
543 (invoke "./x.py" "-j1" "test" "-vv")
544 (invoke "./x.py" "-j1" "test" "src/tools/cargo")
545 #t))
546 (replace 'install
547 (lambda* (#:key outputs #:allow-other-keys)
548 (invoke "./x.py" "install")
549 (substitute* "config.toml"
550 ;; replace prefix to specific output
551 (("prefix = \"[^\"]*\"")
552 (string-append "prefix = \"" (assoc-ref outputs "cargo") "\"")))
553 (invoke "./x.py" "install" "cargo")))
554 (add-after 'install 'wrap-rustc
555 (lambda* (#:key inputs outputs #:allow-other-keys)
556 (let ((out (assoc-ref outputs "out"))
557 (libc (assoc-ref inputs "libc"))
558 (ld-wrapper (assoc-ref inputs "ld-wrapper")))
559 ;; Let gcc find ld and libc startup files.
560 (wrap-program (string-append out "/bin/rustc")
561 `("PATH" ":" prefix (,(string-append ld-wrapper "/bin")))
562 `("LIBRARY_PATH" ":" suffix (,(string-append libc "/lib"))))
563 #t))))))))))
564
05ebff92 565(define-public rust-1.21
7bf169f7
DM
566 (let ((base-rust (rust-bootstrapped-package rust-1.20 "1.21.0"
567 "1yj8lnxybjrybp00fqhxw8fpr641dh8wcn9mk44xjnsb4i1c21qp")))
568 (package
569 (inherit base-rust)
570 (arguments
571 (substitute-keyword-arguments (package-arguments base-rust)
572 ((#:phases phases)
573 `(modify-phases ,phases
574 (add-after 'configure 'remove-ar
575 (lambda* (#:key inputs #:allow-other-keys)
576 ;; Remove because toml complains about "unknown field".
577 (substitute* "config.toml"
578 (("^ar =.*") "\n"))
579 #t)))))))))
05ebff92 580
1ab3e1dd 581(define-public rust-1.22
8cddb0d6
DM
582 (let ((base-rust (rust-bootstrapped-package rust-1.21 "1.22.1"
583 "1lrzzp0nh7s61wgfs2h6ilaqi6iq89f1pd1yaf65l87bssyl4ylb")))
584 (package
585 (inherit base-rust)
586 (arguments
587 (substitute-keyword-arguments (package-arguments base-rust)
588 ((#:phases phases)
589 `(modify-phases ,phases
590 (add-after 'unpack 'remove-flaky-test
591 (lambda _
592 ;; See <https://github.com/rust-lang/rust/issues/43402>.
593 (when (file-exists? "src/test/run-make/issue-26092")
594 (delete-file-recursively "src/test/run-make/issue-26092"))
595 #t)))))))))
1ab3e1dd 596
8fdde581 597(define-public rust-1.23
44d530ef
DM
598 (let ((base-rust (rust-bootstrapped-package rust-1.22 "1.23.0"
599 "14fb8vhjzsxlbi6yrn1r6fl5dlbdd1m92dn5zj5gmzfwf4w9ar3l")))
600 (package
601 (inherit base-rust)
602 (arguments
603 (substitute-keyword-arguments (package-arguments base-rust)
604 ((#:phases phases)
605 `(modify-phases ,phases
606 (delete 'configure-archiver)
607 (delete 'remove-ar)
608 (add-after 'unpack 'dont-build-native
609 (lambda _
610 ;; XXX: Revisit this when we use gcc 6.
611 (substitute* "src/binaryen/CMakeLists.txt"
612 (("ADD_COMPILE_FLAG\\(\\\"-march=native\\\"\\)") ""))
613 #t)))))))))
b5a09649 614
fe61c88a 615(define-public rust-1.24
ca523cc5
DM
616 (let ((base-rust
617 (rust-bootstrapped-package rust-1.23 "1.24.1"
618 "1vv10x2h9kq7fxh2v01damdq8pvlp5acyh1kzcda9sfjx12kv99y")))
f342bb58
NM
619 (package
620 (inherit base-rust)
f342bb58
NM
621 (arguments
622 (substitute-keyword-arguments (package-arguments base-rust)
ca523cc5
DM
623 ((#:phases phases)
624 `(modify-phases ,phases
b47b2d32
NM
625 (delete 'use-readelf-for-tests)
626 (replace 'patch-aarch64-test
627 (lambda* _
628 (substitute* "src/librustc_metadata/dynamic_lib.rs"
629 ;; This test is known to fail on aarch64 and powerpc64le:
630 ;; https://github.com/rust-lang/rust/issues/45410
631 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
e0b07ccc 632 #t)))))))))
fe61c88a 633
e027a494
NM
634;;; Rust 1.25 release support work with llvm 6--but build with llvm 6 is
635;;; not determenistic due to <https://github.com/rust-lang/rust/issues/50556>.
636;;; Keep using llvm 3.9.1 until builds become determenistic
b47b2d32
NM
637(define-public rust-1.25
638 (let ((base-rust
639 (rust-bootstrapped-package rust-1.24 "1.25.0"
6fe73b48
DM
640 "0baxjr99311lvwdq0s38bipbnj72pn6fgbk6lcq7j555xq53mxpf"
641 #:patches '("rust-1.25-accept-more-detailed-gdb-lines.patch"))))
fe61c88a
NM
642 (package
643 (inherit base-rust)
fe61c88a
NM
644 (arguments
645 (substitute-keyword-arguments (package-arguments base-rust)
646 ((#:phases phases)
647 `(modify-phases ,phases
648 (add-after 'patch-cargo-tests 'patch-cargo-index-update
080e11b4 649 (lambda _
fe61c88a
NM
650 (substitute* "src/tools/cargo/tests/generate-lockfile.rs"
651 ;; This test wants to update the crate index.
080e11b4
EF
652 (("fn no_index_update") "#[ignore]\nfn no_index_update"))
653 #t))
080e11b4
EF
654 (replace 'patch-aarch64-test
655 (lambda _
656 (substitute* "src/librustc_metadata/dynamic_lib.rs"
657 ;; This test is known to fail on aarch64 and powerpc64le:
658 ;; https://github.com/rust-lang/rust/issues/45410
659 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
660 ;; This test fails on aarch64 with llvm@6.0:
661 ;; https://github.com/rust-lang/rust/issues/49807
662 ;; other possible solution:
663 ;; https://github.com/rust-lang/rust/pull/47688
664 (delete-file "src/test/debuginfo/by-value-self-argument-in-trait-impl.rs")
665 #t))
b47b2d32
NM
666 (delete 'ignore-glibc-2.27-incompatible-test))))))))
667
f510a2b9 668(define-public rust-1.26
b47b2d32
NM
669 (let ((base-rust
670 (rust-bootstrapped-package rust-1.25 "1.26.2"
6fe73b48
DM
671 "0047ais0fvmqvngqkdsxgrzhb0kljg8wy85b01kbbjc88hqcz7pv"
672 #:patches '("rust-coresimd-doctest.patch"
673 "rust-1.25-accept-more-detailed-gdb-lines.patch"))))
b47b2d32
NM
674 (package
675 (inherit base-rust)
676 (arguments
677 (substitute-keyword-arguments (package-arguments base-rust)
678 ((#:phases phases)
679 `(modify-phases ,phases
680 ;; binaryen was replaced with LLD project from LLVM
681 (delete 'dont-build-native)
682 (replace 'remove-unsupported-tests
683 (lambda* _
684 ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH.
685 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html>
686 (delete-file-recursively "src/test/run-make-fulldeps/linker-output-non-utf8")
687 #t))
688 (replace 'patch-cargo-tests
689 (lambda* _
690 (substitute* "src/tools/cargo/tests/testsuite/build.rs"
691 (("/usr/bin/env") (which "env"))
692 ;; Guix llvm is compiled without asmjs-unknown-emscripten.
693 (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs"))
694 (substitute* "src/tools/cargo/tests/testsuite/death.rs"
695 ;; This is stuck when built in container.
696 (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone"))
697 ;; Prints test output in the wrong order when built on
698 ;; i686-linux.
699 (substitute* "src/tools/cargo/tests/testsuite/test.rs"
700 (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env"))
01cef16f
MB
701
702 ;; Avoid dependency on "git".
703 (substitute* "src/tools/cargo/tests/testsuite/new.rs"
704 (("fn author_prefers_cargo") "#[ignore]\nfn author_prefers_cargo")
705 (("fn finds_author_git") "#[ignore]\nfn finds_author_git")
706 (("fn finds_local_author_git") "#[ignore]\nfn finds_local_author_git"))
b47b2d32
NM
707 #t))
708 (add-after 'patch-cargo-tests 'disable-cargo-test-for-nightly-channel
709 (lambda* _
710 ;; This test failed to work on "nightly" channel builds
711 ;; https://github.com/rust-lang/cargo/issues/5648
712 (substitute* "src/tools/cargo/tests/testsuite/resolve.rs"
713 (("fn test_resolving_minimum_version_with_transitive_deps")
714 "#[ignore]\nfn test_resolving_minimum_version_with_transitive_deps"))
715 #t))
716 (replace 'patch-cargo-index-update
717 (lambda* _
718 (substitute* "src/tools/cargo/tests/testsuite/generate_lockfile.rs"
719 ;; This test wants to update the crate index.
720 (("fn no_index_update") "#[ignore]\nfn no_index_update"))
721 #t)))))))))
f510a2b9 722
2e2b8635 723(define-public rust-1.27
f510a2b9 724 (let ((base-rust
317b139c
DM
725 (rust-bootstrapped-package rust-1.26 "1.27.2"
726 "0pg1s37bhx9zqbynxyydq5j6q7kij9vxkcv8maz0m25prm88r0cs"
f510a2b9
NM
727 #:patches
728 '("rust-coresimd-doctest.patch"
6fe73b48 729 "rust-bootstrap-stage0-test.patch"
e027a494 730 "rust-1.25-accept-more-detailed-gdb-lines.patch"
f2c99fe5 731 "rust-reproducible-builds.patch"))))
f510a2b9
NM
732 (package
733 (inherit base-rust)
734 (arguments
735 (substitute-keyword-arguments (package-arguments base-rust)
736 ((#:phases phases)
737 `(modify-phases ,phases
738 (add-before 'install 'mkdir-prefix-paths
739 (lambda* (#:key outputs #:allow-other-keys)
740 ;; As result of https://github.com/rust-lang/rust/issues/36989
741 ;; `prefix' directory should exist before `install' call
742 (mkdir-p (assoc-ref outputs "out"))
743 (mkdir-p (assoc-ref outputs "cargo"))
e027a494
NM
744 #t))
745 (add-after 'patch-cargo-tests 'disable-thinlto-test
746 (lambda* _
747 ;; thinlto required llvm 6.0 for work
748 (substitute* "src/tools/cargo/tests/testsuite/path.rs"
749 (("fn thin_lto_works") "#[ignore]\nfn thin_lto_works"))
f510a2b9 750 #t)))))))))
2e2b8635
NM
751
752(define-public rust
753 (let ((base-rust
754 (rust-bootstrapped-package rust-1.27 "1.28.0"
755 "11k4rn77bca2rikykkk9fmprrgjswd4x4kaq7fia08vgkir82nhx"
756 #:patches
757 '("rust-coresimd-doctest.patch"
758 "rust-bootstrap-stage0-test.patch"
759 "rust-1.25-accept-more-detailed-gdb-lines.patch"
f2c99fe5 760 "rust-reproducible-builds.patch"))))
2e2b8635
NM
761 (package
762 (inherit base-rust)
763 (inputs
764 ;; Use LLVM 6.0
765 (alist-replace "llvm" (list llvm)
766 (package-inputs base-rust)))
767 (arguments
768 (substitute-keyword-arguments (package-arguments base-rust)
769 ((#:phases phases)
770 `(modify-phases ,phases
771 (add-after 'configure 'enable-codegen-tests
772 ;; Codegen tests should pass with llvm 6, so enable them.
773 (lambda* _
774 (substitute* "config.toml"
775 (("codegen-tests = false") ""))
776 #t))
777 (add-after 'patch-tests 'disable-amd64-avx-test
778 ;; That test would fail on x86_64 machines without avx.
779 (lambda* _
780 (substitute* "src/test/run-pass/issue-44056.rs"
781 (("only-x86_64") "ignore-test"))
782 #t))
783 ;; The thinlto test should pass with llvm 6.
784 (delete 'disable-thinlto-test))))))))