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