gnu: rust@1.23.0: Inherit from rust@1.22.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>
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)
ecee2147 44 #:use-module (gnu packages version-control)
d53fb678 45 #:use-module (gnu packages)
b5a09649 46 #:use-module (guix build-system cargo)
423f9e44
DC
47 #:use-module (guix build-system gnu)
48 #:use-module (guix build-system trivial)
49 #:use-module (guix download)
a92bf11c 50 #:use-module (guix git-download)
423f9e44
DC
51 #:use-module ((guix licenses) #:prefix license:)
52 #:use-module (guix packages)
f342bb58
NM
53 #:use-module ((guix build utils) #:select (alist-replace))
54 #:use-module (guix utils)
423f9e44
DC
55 #:use-module (ice-9 match)
56 #:use-module (srfi srfi-26))
57
d53fb678
NM
58(define %cargo-reference-project-file "/dev/null")
59(define %cargo-reference-hash
60 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
423f9e44 61
2c790226
MW
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
f342bb58 72(define rust-bootstrap
423f9e44 73 (package
f342bb58
NM
74 (name "rust-bootstrap")
75 (version "1.22.1")
514026d7 76 (source #f)
423f9e44
DC
77 (build-system gnu-build-system)
78 (native-inputs
79 `(("patchelf" ,patchelf)))
80 (inputs
f342bb58
NM
81 `(("gcc" ,(canonical-package gcc))
82 ("gcc:lib" ,(canonical-package gcc) "lib")
514026d7
RT
83 ("zlib" ,zlib)
84 ("source"
85 ,(origin
86 (method url-fetch)
87 (uri (string-append
88 "https://static.rust-lang.org/dist/"
2c790226
MW
89 "rust-" version "-" (nix-system->gnu-triplet-for-rust)
90 ".tar.gz"))
514026d7
RT
91 (sha256
92 (base32
2c790226 93 (match (nix-system->gnu-triplet-for-rust)
514026d7
RT
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 (_ ""))))))))
f342bb58 105 (outputs '("out" "cargo"))
423f9e44
DC
106 (arguments
107 `(#:tests? #f
108 #:strip-binaries? #f
423f9e44
DC
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"))
f342bb58 116 (cargo-out (assoc-ref outputs "cargo"))
423f9e44
DC
117 (gcc:lib (assoc-ref inputs "gcc:lib"))
118 (libc (assoc-ref inputs "libc"))
119 (zlib (assoc-ref inputs "zlib"))
d53fb678 120 (ld-so (string-append libc ,(glibc-dynamic-linker)))
423f9e44
DC
121 (rpath (string-append out "/lib:" zlib "/lib:"
122 libc "/lib:" gcc:lib "/lib"))
f342bb58
NM
123 (cargo-rpath (string-append cargo-out "/lib:" libc "/lib:"
124 gcc:lib "/lib"))
423f9e44 125 (rustc (string-append out "/bin/rustc"))
f342bb58
NM
126 (rustdoc (string-append out "/bin/rustdoc"))
127 (cargo (string-append cargo-out "/bin/cargo"))
128 (gcc (assoc-ref inputs "gcc")))
e69b1a7c 129 ;; Install rustc/rustdoc.
f342bb58 130 (invoke "bash" "install.sh"
423f9e44
DC
131 (string-append "--prefix=" out)
132 (string-append "--components=rustc,"
2c790226
MW
133 "rust-std-"
134 ,(nix-system->gnu-triplet-for-rust)))
e69b1a7c 135 ;; Install cargo.
f342bb58
NM
136 (invoke "bash" "install.sh"
137 (string-append "--prefix=" cargo-out)
138 (string-append "--components=cargo"))
423f9e44 139 (for-each (lambda (file)
f342bb58 140 (invoke "patchelf" "--set-rpath" rpath file))
423f9e44 141 (cons* rustc rustdoc (find-files out "\\.so$")))
f342bb58 142 (invoke "patchelf" "--set-rpath" cargo-rpath cargo)
423f9e44 143 (for-each (lambda (file)
f342bb58
NM
144 (invoke "patchelf" "--set-interpreter" ld-so file))
145 (list rustc rustdoc cargo))
f342bb58 146 #t))))))
423f9e44 147 (home-page "https://www.rust-lang.org")
f342bb58
NM
148 (synopsis "Prebuilt rust compiler and cargo package manager")
149 (description "This package provides a pre-built @command{rustc} compiler
b3884bbf 150and a pre-built @command{cargo} package manager, which can
f342bb58 151in turn be used to build the final Rust.")
423f9e44
DC
152 (license license:asl2.0)))
153
d53fb678 154\f
b47b2d32 155(define* (rust-source version hash #:key (patches '()))
f342bb58
NM
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)))
b47b2d32
NM
162 (snippet '(begin (delete-file-recursively "src/llvm") #t))
163 (patches (map search-patch patches))))
f342bb58 164
24d298b4
DM
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
4a90fcf9 203 `(#:test-target "local_tests"
24d298b4
DM
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$"))
4a90fcf9 253 (delete-file-recursively "output/local_tests")
24d298b4
DM
254 (mkdir-p lib)
255 (copy-recursively "output" lib/rust)
256 (mkdir-p bin)
257 (mkdir-p tools-bin)
258 (install-file "bin/mrustc" bin)
259 ;; minicargo uses relative paths to resolve mrustc.
260 (install-file "tools/bin/minicargo" tools-bin)
261 (install-file "tools/bin/minicargo" cargo-bin)
262 #t))))))
263 (synopsis "Compiler for the Rust progamming language")
264 (description "Rust is a systems programming language that provides memory
265safety and thread safety guarantees.")
266 (home-page "https://github.com/thepowersgang/mrustc")
267 ;; Dual licensed.
268 (license (list license:asl2.0 license:expat)))))
269
4f963b6f 270(define rust-1.19
ecee2147 271 (package
f342bb58 272 (name "rust")
8fdde581 273 (version "1.19.0")
3159ef7c
DM
274 (source (rust-source version "0l8c14qsf42rmkqy92ahij4vf356dbyspxcips1aswpvad81y8qm"
275 #:patches '("rust-1.19-mrustc.patch")))
8fdde581 276 (outputs '("out" "cargo"))
ecee2147 277 (arguments
d53fb678 278 `(#:imported-modules ,%cargo-build-system-modules ;for `generate-checksums'
3159ef7c 279 #:modules ((guix build utils) (ice-9 match) (guix build gnu-build-system))
d53fb678 280 #:phases
ecee2147 281 (modify-phases %standard-phases
ecee2147 282 (add-after 'unpack 'set-env
1bb23335
NM
283 (lambda* (#:key inputs #:allow-other-keys)
284 ;; Disable test for cross compilation support.
285 (setenv "CFG_DISABLE_CROSS_TESTS" "1")
ecee2147 286 (setenv "SHELL" (which "sh"))
326249ba 287 (setenv "CONFIG_SHELL" (which "sh"))
1bb23335 288 (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
d53fb678
NM
289 ;; guix llvm-3.9.1 package installs only shared libraries
290 (setenv "LLVM_LINK_SHARED" "1")
326249ba 291 #t))
3159ef7c
DM
292 (add-after 'unpack 'patch-cargo-tomls
293 (lambda* (#:key inputs outputs #:allow-other-keys)
294 (substitute* "src/librustc_errors/Cargo.toml"
295 (("[[]dependencies[]]") "
296[dependencies]
297term = \"0.4.4\"
298"))
299 (substitute* "src/librustc/Cargo.toml"
300 (("[[]dependencies[]]") "
301[dependencies]
302getopts = { path = \"../libgetopts\" }
303"))
304 (substitute* "src/librustdoc/Cargo.toml"
305 (("[[]dependencies[]]") "
306[dependencies]
307test = { path = \"../libtest\" }
308"))
309 #t))
84aac61c
DM
310 (add-after 'unpack 'patch-tests
311 (lambda* (#:key inputs #:allow-other-keys)
9b7a9580 312 (let ((bash (assoc-ref inputs "bash")))
9b7a9580 313 (substitute* "src/libstd/process.rs"
5f3d46ce
DM
314 ;; The newline is intentional.
315 ;; There's a line length "tidy" check in Rust which would
316 ;; fail otherwise.
d53fb678
NM
317 (("\"/bin/sh\"") (string-append "\n\"" bash "/bin/sh\"")))
318 (substitute* "src/libstd/net/tcp.rs"
319 ;; There is no network in build environment
320 (("fn connect_timeout_unroutable")
321 "#[ignore]\nfn connect_timeout_unroutable"))
322 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00222.html>
5f3d46ce 323 (substitute* "src/libstd/sys/unix/process/process_common.rs"
237587f1
DM
324 (("fn test_process_mask") "#[allow(unused_attributes)]
325 #[ignore]
af4ea9c5 326 fn test_process_mask"))
9b7a9580 327 #t)))
b47b2d32
NM
328 (add-after 'patch-tests 'patch-aarch64-test
329 (lambda* _
330 (substitute* "src/librustc_back/dynamic_lib.rs"
331 ;; This test is known to fail on aarch64 and powerpc64le:
332 ;; https://github.com/rust-lang/rust/issues/45410
333 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
334 #t))
335 (add-after 'patch-tests 'use-readelf-for-tests
336 (lambda* _
337 ;; nm doesn't recognize the file format because of the
338 ;; nonstandard sections used by the Rust compiler, but readelf
339 ;; ignores them.
340 (substitute* "src/test/run-make/atomic-lock-free/Makefile"
341 (("\tnm ")
342 "\treadelf -c "))
343 #t))
344 (add-after 'patch-tests 'remove-unsupported-tests
345 (lambda* _
346 ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH.
347 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html>
348 (delete-file-recursively "src/test/run-make/linker-output-non-utf8")
349 #t))
d53fb678 350 (add-after 'patch-source-shebangs 'patch-cargo-checksums
f342bb58 351 (lambda* _
d53fb678
NM
352 (substitute* "src/Cargo.lock"
353 (("(\"checksum .* = )\".*\"" all name)
354 (string-append name "\"" ,%cargo-reference-hash "\"")))
355 (for-each
356 (lambda (filename)
357 (use-modules (guix build cargo-build-system))
358 (delete-file filename)
359 (let* ((dir (dirname filename)))
360 (display (string-append
361 "patch-cargo-checksums: generate-checksums for "
362 dir "\n"))
363 (generate-checksums dir ,%cargo-reference-project-file)))
364 (find-files "src/vendor" ".cargo-checksum.json"))
365 #t))
3159ef7c 366 ;; This phase is overridden by newer versions.
ecee2147 367 (replace 'configure
8fdde581 368 (const #t))
3159ef7c
DM
369 ;; This phase is overridden by newer versions.
370 (replace 'build
371 (lambda* (#:key inputs outputs #:allow-other-keys)
372 (let ((rustc-bootstrap (assoc-ref inputs "rustc-bootstrap")))
373 (setenv "CFG_COMPILER_HOST_TRIPLE"
374 ,(nix-system->gnu-triplet (%current-system)))
375 (setenv "CFG_RELEASE" "")
376 (setenv "CFG_RELEASE_CHANNEL" "stable")
377 (setenv "CFG_LIBDIR_RELATIVE" "lib")
378 (setenv "CFG_VERSION" "1.19.0-stable-mrustc")
379 ; bad: (setenv "CFG_PREFIX" "mrustc") ; FIXME output path.
380 (mkdir-p "output")
381 (invoke (string-append rustc-bootstrap "/tools/bin/minicargo")
382 "src/rustc" "--vendor-dir" "src/vendor"
383 "--output-dir" "output/rustc-build"
384 "-L" (string-append rustc-bootstrap "/lib/mrust")
385 "-j" "1")
3159ef7c
DM
386 (setenv "CFG_COMPILER_HOST_TRIPLE" #f)
387 (setenv "CFG_RELEASE" #f)
388 (setenv "CFG_RELEASE_CHANNEL" #f)
389 (setenv "CFG_VERSION" #f)
390 (setenv "CFG_PREFIX" #f)
391 (setenv "CFG_LIBDIR_RELATIVE" #f)
392 (invoke (string-append rustc-bootstrap "/tools/bin/minicargo")
393 "src/tools/cargo" "--vendor-dir" "src/vendor"
394 "--output-dir" "output/cargo-build"
395 "-L" "output/"
396 "-L" (string-append rustc-bootstrap "/lib/mrust")
397 "-j" "1")
398 ;; Now use the newly-built rustc to build the libraries.
399 ;; One day that could be replaced by:
400 ;; (invoke "output/cargo-build/cargo" "build"
401 ;; "--manifest-path" "src/bootstrap/Cargo.toml"
402 ;; "--verbose") ; "--locked" "--frozen"
403 ;; but right now, Cargo has problems with libstd's circular
404 ;; dependencies.
405 (mkdir-p "output/target-libs")
0bcd1bc7 406 (for-each (match-lambda
3159ef7c
DM
407 ((name . flags)
408 (write name)
409 (newline)
410 (apply invoke
411 "output/rustc-build/rustc"
412 "-C" (string-append "linker="
413 (getenv "CC"))
6c1a6584
DM
414 ;; Required for libterm.
415 "-Z" "force-unstable-if-unmarked"
3159ef7c
DM
416 "-L" "output/target-libs"
417 (string-append "src/" name "/lib.rs")
418 "-o"
419 (string-append "output/target-libs/"
420 (car (string-split name #\/))
421 ".rlib")
422 flags)))
423 '(("libcore")
424 ("libstd_unicode")
425 ("liballoc")
426 ("libcollections")
427 ("librand")
428 ("liblibc/src" "--cfg" "stdbuild")
429 ("libunwind" "-l" "gcc_s")
430 ("libcompiler_builtins")
431 ("liballoc_system")
432 ("libpanic_unwind")
433 ;; Uses "cc" to link.
434 ("libstd" "-l" "dl" "-l" "rt" "-l" "pthread")
6c1a6584
DM
435 ("libarena")
436
437 ;; Test dependencies:
438
439 ("libgetopts")
440 ("libterm")
441 ("libtest")))
3159ef7c
DM
442 #t)))
443 ;; This phase is overridden by newer versions.
8fdde581
DM
444 (replace 'check
445 (const #t))
3159ef7c 446 ;; This phase is overridden by newer versions.
8fdde581 447 (replace 'install
3159ef7c
DM
448 (lambda* (#:key inputs outputs #:allow-other-keys)
449 (let* ((out (assoc-ref outputs "out"))
450 (target-system ,(or (%current-target-system)
451 (nix-system->gnu-triplet
452 (%current-system))))
453 (out-libs (string-append out "/lib/rustlib/"
454 target-system "/lib")))
455 ;(setenv "CFG_PREFIX" out)
456 (mkdir-p out-libs)
457 (copy-recursively "output/target-libs" out-libs)
458 (install-file "output/rustc-build/rustc"
459 (string-append out "/bin"))
5a3fcf5b
DM
460 (install-file "output/rustc-build/rustdoc"
461 (string-append out "/bin"))
3159ef7c
DM
462 (install-file "output/cargo-build/cargo"
463 (string-append (assoc-ref outputs "cargo")
464 "/bin")))
465 #t)))))
8fdde581
DM
466 (build-system gnu-build-system)
467 (native-inputs
468 `(("bison" ,bison) ; For the tests
469 ("cmake" ,cmake)
470 ("flex" ,flex) ; For the tests
471 ("gdb" ,gdb) ; For the tests
472 ("git" ,git)
473 ("procps" ,procps) ; For the tests
474 ("python-2" ,python-2)
3159ef7c
DM
475 ("rustc-bootstrap" ,mrustc)
476 ("cargo-bootstrap" ,mrustc "cargo")
8fdde581
DM
477 ("pkg-config" ,pkg-config) ; For "cargo"
478 ("which" ,which)))
479 (inputs
480 `(("jemalloc" ,jemalloc-4.5.0)
481 ("llvm" ,llvm-3.9.1)
482 ("openssl" ,openssl)
e027a494
NM
483 ("libssh2" ,libssh2) ; For "cargo"
484 ("libcurl" ,curl))) ; For "cargo"
afc2bf53 485
8fdde581 486 ;; rustc invokes gcc, so we need to set its search paths accordingly.
afc2bf53
LC
487 ;; Note: duplicate its value here to cope with circular dependencies among
488 ;; modules (see <https://bugs.gnu.org/31392>).
489 (native-search-paths
490 (list (search-path-specification
491 (variable "C_INCLUDE_PATH")
492 (files '("include")))
493 (search-path-specification
494 (variable "CPLUS_INCLUDE_PATH")
495 (files '("include")))
496 (search-path-specification
497 (variable "LIBRARY_PATH")
498 (files '("lib" "lib64")))))
499
8fdde581
DM
500 (synopsis "Compiler for the Rust progamming language")
501 (description "Rust is a systems programming language that provides memory
502safety and thread safety guarantees.")
503 (home-page "https://www.rust-lang.org")
504 ;; Dual licensed.
505 (license (list license:asl2.0 license:expat))))
506
614cfd5c
DM
507(define-public rust-1.20
508 (let ((base-rust
509 (rust-bootstrapped-package rust-1.19 "1.20.0"
510 "0542y4rnzlsrricai130mqyxl8r6rd991frb4qsnwb27yigqg91a")))
511 (package
512 (inherit base-rust)
513 (outputs '("out" "doc" "cargo"))
514 (arguments
515 (substitute-keyword-arguments (package-arguments rust-1.19)
516 ((#:phases phases)
517 `(modify-phases ,phases
1bfaae25
DM
518 (add-after 'patch-tests 'patch-cargo-tests
519 (lambda _
520 (substitute* "src/tools/cargo/tests/build.rs"
521 (("/usr/bin/env") (which "env"))
522 ;; Guix llvm is compiled without asmjs-unknown-emscripten.
523 (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs"))
524 (substitute* "src/tools/cargo/tests/death.rs"
525 ;; This is stuck when built in container.
526 (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone"))
527 ;; Prints test output in the wrong order when built on
528 ;; i686-linux.
529 (substitute* "src/tools/cargo/tests/test.rs"
530 (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env"))
531 #t))
532 (add-after 'patch-cargo-tests 'ignore-glibc-2.27-incompatible-test
533 ;; https://github.com/rust-lang/rust/issues/47863
534 (lambda _
535 (substitute* "src/test/run-pass/out-of-stack.rs"
536 (("// ignore-android") "// ignore-test\n// ignore-android"))
537 #t))
614cfd5c
DM
538 (replace 'configure
539 (lambda* (#:key inputs outputs #:allow-other-keys)
540 (let* ((out (assoc-ref outputs "out"))
541 (doc (assoc-ref outputs "doc"))
542 (gcc (assoc-ref inputs "gcc"))
543 (gdb (assoc-ref inputs "gdb"))
544 (binutils (assoc-ref inputs "binutils"))
545 (python (assoc-ref inputs "python-2"))
546 (rustc (assoc-ref inputs "rustc-bootstrap"))
547 (cargo (assoc-ref inputs "cargo-bootstrap"))
548 (llvm (assoc-ref inputs "llvm"))
549 (jemalloc (assoc-ref inputs "jemalloc")))
550 (call-with-output-file "config.toml"
551 (lambda (port)
552 (display (string-append "
553[llvm]
554[build]
555cargo = \"" cargo "/bin/cargo" "\"
556rustc = \"" rustc "/bin/rustc" "\"
557docs = true
558python = \"" python "/bin/python2" "\"
559gdb = \"" gdb "/bin/gdb" "\"
560vendor = true
561submodules = false
562[install]
563prefix = \"" out "\"
564docdir = \"" doc "/share/doc/rust" "\"
565sysconfdir = \"etc\"
614cfd5c
DM
566[rust]
567default-linker = \"" gcc "/bin/gcc" "\"
614cfd5c
DM
568channel = \"stable\"
569rpath = true
570" ;; There are 2 failed codegen tests:
571;; codegen/mainsubprogram.rs and codegen/mainsubprogramstart.rs
572;; These tests require a patched LLVM
573"codegen-tests = false
574[target." ,(nix-system->gnu-triplet-for-rust) "]
575llvm-config = \"" llvm "/bin/llvm-config" "\"
576cc = \"" gcc "/bin/gcc" "\"
577cxx = \"" gcc "/bin/g++" "\"
91294b53 578ar = \"" binutils "/bin/ar" "\"
614cfd5c
DM
579jemalloc = \"" jemalloc "/lib/libjemalloc_pic.a" "\"
580[dist]
581") port)))
582 #t)))
583 (add-after 'configure 'provide-cc
584 (lambda* (#:key inputs #:allow-other-keys)
585 (symlink (string-append (assoc-ref inputs "gcc") "/bin/gcc")
586 "/tmp/cc")
587 (setenv "PATH" (string-append "/tmp:" (getenv "PATH")))
588 #t))
589 (add-after 'provide-cc 'configure-archiver
590 (lambda* (#:key inputs #:allow-other-keys)
591 (substitute* "src/build_helper/lib.rs"
592 ;; Make sure "ar" is always used as the archiver.
593 (("\"musl\"") "\"\"")
594 ;; Then substitute "ar" by our name.
595 (("\"ar\"") (string-append "\""
596 (assoc-ref inputs "binutils")
597 "/bin/ar\"")))
598 #t))
599 (delete 'patch-cargo-tomls)
600 (add-before 'build 'reset-timestamps-after-changes
601 (lambda* _
614cfd5c
DM
602 (for-each
603 (lambda (filename)
e0b07ccc
DM
604 ;; Rust 1.20.0 treats timestamp 0 as "file doesn't exist".
605 ;; Therefore, use timestamp 1.
606 (utime filename 1 1 1 1))
614cfd5c
DM
607 (find-files "." #:directories? #t))
608 #t))
609 (replace 'build
610 (lambda* _
611 (invoke "./x.py" "build")
612 (invoke "./x.py" "build" "src/tools/cargo")))
613 (replace 'check
614 (lambda* _
615 ;; Disable parallel execution to prevent EAGAIN errors when
616 ;; running tests.
617 (invoke "./x.py" "-j1" "test" "-vv")
618 (invoke "./x.py" "-j1" "test" "src/tools/cargo")
619 #t))
620 (replace 'install
621 (lambda* (#:key outputs #:allow-other-keys)
622 (invoke "./x.py" "install")
623 (substitute* "config.toml"
624 ;; replace prefix to specific output
625 (("prefix = \"[^\"]*\"")
626 (string-append "prefix = \"" (assoc-ref outputs "cargo") "\"")))
627 (invoke "./x.py" "install" "cargo")))
628 (add-after 'install 'wrap-rustc
629 (lambda* (#:key inputs outputs #:allow-other-keys)
630 (let ((out (assoc-ref outputs "out"))
631 (libc (assoc-ref inputs "libc"))
632 (ld-wrapper (assoc-ref inputs "ld-wrapper")))
633 ;; Let gcc find ld and libc startup files.
634 (wrap-program (string-append out "/bin/rustc")
635 `("PATH" ":" prefix (,(string-append ld-wrapper "/bin")))
636 `("LIBRARY_PATH" ":" suffix (,(string-append libc "/lib"))))
637 #t))))))))))
638
05ebff92 639(define-public rust-1.21
7bf169f7
DM
640 (let ((base-rust (rust-bootstrapped-package rust-1.20 "1.21.0"
641 "1yj8lnxybjrybp00fqhxw8fpr641dh8wcn9mk44xjnsb4i1c21qp")))
642 (package
643 (inherit base-rust)
644 (arguments
645 (substitute-keyword-arguments (package-arguments base-rust)
646 ((#:phases phases)
647 `(modify-phases ,phases
648 (add-after 'configure 'remove-ar
649 (lambda* (#:key inputs #:allow-other-keys)
650 ;; Remove because toml complains about "unknown field".
651 (substitute* "config.toml"
652 (("^ar =.*") "\n"))
653 #t)))))))))
05ebff92 654
1ab3e1dd
DM
655(define-public rust-1.22
656 (rust-bootstrapped-package rust-1.21 "1.22.1"
657 "1lrzzp0nh7s61wgfs2h6ilaqi6iq89f1pd1yaf65l87bssyl4ylb"))
658
8fdde581
DM
659(define-public rust-1.23
660 (package
a75b8c08 661 (inherit rust-1.22)
8fdde581
DM
662 (name "rust")
663 (version "1.23.0")
664 (source (rust-source version "14fb8vhjzsxlbi6yrn1r6fl5dlbdd1m92dn5zj5gmzfwf4w9ar3l"))
e027a494 665 ;; Use rust-bootstrap@1.22 package to build rust 1.23
3159ef7c 666 (native-inputs
e027a494
NM
667 (alist-replace "cargo-bootstrap" (list rust-bootstrap "cargo")
668 (alist-replace "rustc-bootstrap" (list rust-bootstrap)
a75b8c08 669 (package-native-inputs rust-1.22))))
8fdde581 670 (arguments
a75b8c08 671 (substitute-keyword-arguments (package-arguments rust-1.22)
8fdde581
DM
672 ((#:phases phases)
673 `(modify-phases ,phases
333c0ca9 674 (delete 'configure-archiver)
a75b8c08 675 (delete 'remove-ar)
67ca98ec
EF
676 (add-after 'unpack 'dont-build-native
677 (lambda _
678 ;; XXX: Revisit this when we use gcc 6.
679 (substitute* "src/binaryen/CMakeLists.txt"
680 (("ADD_COMPILE_FLAG\\(\\\"-march=native\\\"\\)") ""))
333c0ca9 681 #t))))))))
b5a09649 682
fe61c88a 683(define-public rust-1.24
ca523cc5
DM
684 (let ((base-rust
685 (rust-bootstrapped-package rust-1.23 "1.24.1"
686 "1vv10x2h9kq7fxh2v01damdq8pvlp5acyh1kzcda9sfjx12kv99y")))
f342bb58
NM
687 (package
688 (inherit base-rust)
f342bb58
NM
689 (arguments
690 (substitute-keyword-arguments (package-arguments base-rust)
ca523cc5
DM
691 ((#:phases phases)
692 `(modify-phases ,phases
b47b2d32
NM
693 (delete 'use-readelf-for-tests)
694 (replace 'patch-aarch64-test
695 (lambda* _
696 (substitute* "src/librustc_metadata/dynamic_lib.rs"
697 ;; This test is known to fail on aarch64 and powerpc64le:
698 ;; https://github.com/rust-lang/rust/issues/45410
699 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
e0b07ccc 700 #t)))))))))
fe61c88a 701
e027a494
NM
702;;; Rust 1.25 release support work with llvm 6--but build with llvm 6 is
703;;; not determenistic due to <https://github.com/rust-lang/rust/issues/50556>.
704;;; Keep using llvm 3.9.1 until builds become determenistic
b47b2d32
NM
705(define-public rust-1.25
706 (let ((base-rust
707 (rust-bootstrapped-package rust-1.24 "1.25.0"
6fe73b48
DM
708 "0baxjr99311lvwdq0s38bipbnj72pn6fgbk6lcq7j555xq53mxpf"
709 #:patches '("rust-1.25-accept-more-detailed-gdb-lines.patch"))))
fe61c88a
NM
710 (package
711 (inherit base-rust)
fe61c88a
NM
712 (arguments
713 (substitute-keyword-arguments (package-arguments base-rust)
714 ((#:phases phases)
715 `(modify-phases ,phases
716 (add-after 'patch-cargo-tests 'patch-cargo-index-update
080e11b4 717 (lambda _
fe61c88a
NM
718 (substitute* "src/tools/cargo/tests/generate-lockfile.rs"
719 ;; This test wants to update the crate index.
080e11b4
EF
720 (("fn no_index_update") "#[ignore]\nfn no_index_update"))
721 #t))
080e11b4
EF
722 (replace 'patch-aarch64-test
723 (lambda _
724 (substitute* "src/librustc_metadata/dynamic_lib.rs"
725 ;; This test is known to fail on aarch64 and powerpc64le:
726 ;; https://github.com/rust-lang/rust/issues/45410
727 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
728 ;; This test fails on aarch64 with llvm@6.0:
729 ;; https://github.com/rust-lang/rust/issues/49807
730 ;; other possible solution:
731 ;; https://github.com/rust-lang/rust/pull/47688
732 (delete-file "src/test/debuginfo/by-value-self-argument-in-trait-impl.rs")
733 #t))
b47b2d32
NM
734 (delete 'ignore-glibc-2.27-incompatible-test))))))))
735
f510a2b9 736(define-public rust-1.26
b47b2d32
NM
737 (let ((base-rust
738 (rust-bootstrapped-package rust-1.25 "1.26.2"
6fe73b48
DM
739 "0047ais0fvmqvngqkdsxgrzhb0kljg8wy85b01kbbjc88hqcz7pv"
740 #:patches '("rust-coresimd-doctest.patch"
741 "rust-1.25-accept-more-detailed-gdb-lines.patch"))))
b47b2d32
NM
742 (package
743 (inherit base-rust)
744 (arguments
745 (substitute-keyword-arguments (package-arguments base-rust)
746 ((#:phases phases)
747 `(modify-phases ,phases
748 ;; binaryen was replaced with LLD project from LLVM
749 (delete 'dont-build-native)
750 (replace 'remove-unsupported-tests
751 (lambda* _
752 ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH.
753 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html>
754 (delete-file-recursively "src/test/run-make-fulldeps/linker-output-non-utf8")
755 #t))
756 (replace 'patch-cargo-tests
757 (lambda* _
758 (substitute* "src/tools/cargo/tests/testsuite/build.rs"
759 (("/usr/bin/env") (which "env"))
760 ;; Guix llvm is compiled without asmjs-unknown-emscripten.
761 (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs"))
762 (substitute* "src/tools/cargo/tests/testsuite/death.rs"
763 ;; This is stuck when built in container.
764 (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone"))
765 ;; Prints test output in the wrong order when built on
766 ;; i686-linux.
767 (substitute* "src/tools/cargo/tests/testsuite/test.rs"
768 (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env"))
769 #t))
770 (add-after 'patch-cargo-tests 'disable-cargo-test-for-nightly-channel
771 (lambda* _
772 ;; This test failed to work on "nightly" channel builds
773 ;; https://github.com/rust-lang/cargo/issues/5648
774 (substitute* "src/tools/cargo/tests/testsuite/resolve.rs"
775 (("fn test_resolving_minimum_version_with_transitive_deps")
776 "#[ignore]\nfn test_resolving_minimum_version_with_transitive_deps"))
777 #t))
778 (replace 'patch-cargo-index-update
779 (lambda* _
780 (substitute* "src/tools/cargo/tests/testsuite/generate_lockfile.rs"
781 ;; This test wants to update the crate index.
782 (("fn no_index_update") "#[ignore]\nfn no_index_update"))
783 #t)))))))))
f510a2b9 784
2e2b8635 785(define-public rust-1.27
f510a2b9 786 (let ((base-rust
317b139c
DM
787 (rust-bootstrapped-package rust-1.26 "1.27.2"
788 "0pg1s37bhx9zqbynxyydq5j6q7kij9vxkcv8maz0m25prm88r0cs"
f510a2b9
NM
789 #:patches
790 '("rust-coresimd-doctest.patch"
6fe73b48 791 "rust-bootstrap-stage0-test.patch"
e027a494
NM
792 "rust-1.25-accept-more-detailed-gdb-lines.patch"
793 "rust-mdbook-support-reproducible-builds-by-forcing-window.search.patch"))))
f510a2b9
NM
794 (package
795 (inherit base-rust)
796 (arguments
797 (substitute-keyword-arguments (package-arguments base-rust)
798 ((#:phases phases)
799 `(modify-phases ,phases
800 (add-before 'install 'mkdir-prefix-paths
801 (lambda* (#:key outputs #:allow-other-keys)
802 ;; As result of https://github.com/rust-lang/rust/issues/36989
803 ;; `prefix' directory should exist before `install' call
804 (mkdir-p (assoc-ref outputs "out"))
805 (mkdir-p (assoc-ref outputs "cargo"))
e027a494
NM
806 #t))
807 (add-after 'patch-cargo-tests 'disable-thinlto-test
808 (lambda* _
809 ;; thinlto required llvm 6.0 for work
810 (substitute* "src/tools/cargo/tests/testsuite/path.rs"
811 (("fn thin_lto_works") "#[ignore]\nfn thin_lto_works"))
f510a2b9 812 #t)))))))))
2e2b8635
NM
813
814(define-public rust
815 (let ((base-rust
816 (rust-bootstrapped-package rust-1.27 "1.28.0"
817 "11k4rn77bca2rikykkk9fmprrgjswd4x4kaq7fia08vgkir82nhx"
818 #:patches
819 '("rust-coresimd-doctest.patch"
820 "rust-bootstrap-stage0-test.patch"
821 "rust-1.25-accept-more-detailed-gdb-lines.patch"
822 "rust-mdbook-support-reproducible-builds-by-forcing-window.search.patch"))))
823 (package
824 (inherit base-rust)
825 (inputs
826 ;; Use LLVM 6.0
827 (alist-replace "llvm" (list llvm)
828 (package-inputs base-rust)))
829 (arguments
830 (substitute-keyword-arguments (package-arguments base-rust)
831 ((#:phases phases)
832 `(modify-phases ,phases
833 (add-after 'configure 'enable-codegen-tests
834 ;; Codegen tests should pass with llvm 6, so enable them.
835 (lambda* _
836 (substitute* "config.toml"
837 (("codegen-tests = false") ""))
838 #t))
839 (add-after 'patch-tests 'disable-amd64-avx-test
840 ;; That test would fail on x86_64 machines without avx.
841 (lambda* _
842 (substitute* "src/test/run-pass/issue-44056.rs"
843 (("only-x86_64") "ignore-test"))
844 #t))
845 ;; The thinlto test should pass with llvm 6.
846 (delete 'disable-thinlto-test))))))))