gnu: rust-bootstrap: Clean up comments.
[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
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
264safety and thread safety guarantees.")
265 (home-page "https://github.com/thepowersgang/mrustc")
266 ;; Dual licensed.
267 (license (list license:asl2.0 license:expat)))))
268
4f963b6f 269(define rust-1.19
ecee2147 270 (package
f342bb58 271 (name "rust")
8fdde581 272 (version "1.19.0")
3159ef7c
DM
273 (source (rust-source version "0l8c14qsf42rmkqy92ahij4vf356dbyspxcips1aswpvad81y8qm"
274 #:patches '("rust-1.19-mrustc.patch")))
8fdde581 275 (outputs '("out" "cargo"))
ecee2147 276 (arguments
d53fb678 277 `(#:imported-modules ,%cargo-build-system-modules ;for `generate-checksums'
3159ef7c 278 #:modules ((guix build utils) (ice-9 match) (guix build gnu-build-system))
d53fb678 279 #:phases
ecee2147 280 (modify-phases %standard-phases
ecee2147 281 (add-after 'unpack 'set-env
1bb23335
NM
282 (lambda* (#:key inputs #:allow-other-keys)
283 ;; Disable test for cross compilation support.
284 (setenv "CFG_DISABLE_CROSS_TESTS" "1")
ecee2147 285 (setenv "SHELL" (which "sh"))
326249ba 286 (setenv "CONFIG_SHELL" (which "sh"))
1bb23335 287 (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
d53fb678
NM
288 ;; guix llvm-3.9.1 package installs only shared libraries
289 (setenv "LLVM_LINK_SHARED" "1")
326249ba 290 #t))
3159ef7c
DM
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]
296term = \"0.4.4\"
297"))
298 (substitute* "src/librustc/Cargo.toml"
299 (("[[]dependencies[]]") "
300[dependencies]
301getopts = { path = \"../libgetopts\" }
302"))
303 (substitute* "src/librustdoc/Cargo.toml"
304 (("[[]dependencies[]]") "
305[dependencies]
306test = { path = \"../libtest\" }
307"))
308 #t))
84aac61c
DM
309 (add-after 'unpack 'patch-tests
310 (lambda* (#:key inputs #:allow-other-keys)
9b7a9580 311 (let ((bash (assoc-ref inputs "bash")))
9b7a9580 312 (substitute* "src/libstd/process.rs"
5f3d46ce
DM
313 ;; The newline is intentional.
314 ;; There's a line length "tidy" check in Rust which would
315 ;; fail otherwise.
d53fb678
NM
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>
5f3d46ce 322 (substitute* "src/libstd/sys/unix/process/process_common.rs"
237587f1
DM
323 (("fn test_process_mask") "#[allow(unused_attributes)]
324 #[ignore]
af4ea9c5 325 fn test_process_mask"))
9b7a9580 326 #t)))
b47b2d32
NM
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))
d53fb678 349 (add-after 'patch-source-shebangs 'patch-cargo-checksums
f342bb58 350 (lambda* _
d53fb678
NM
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))
3159ef7c 365 ;; This phase is overridden by newer versions.
ecee2147 366 (replace 'configure
8fdde581 367 (const #t))
3159ef7c
DM
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")
3159ef7c
DM
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")
0bcd1bc7 405 (for-each (match-lambda
3159ef7c
DM
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.
8fdde581
DM
435 (replace 'check
436 (const #t))
3159ef7c 437 ;; This phase is overridden by newer versions.
8fdde581 438 (replace 'install
3159ef7c
DM
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"))
5a3fcf5b
DM
451 (install-file "output/rustc-build/rustdoc"
452 (string-append out "/bin"))
3159ef7c
DM
453 (install-file "output/cargo-build/cargo"
454 (string-append (assoc-ref outputs "cargo")
455 "/bin")))
456 #t)))))
8fdde581
DM
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)
3159ef7c
DM
466 ("rustc-bootstrap" ,mrustc)
467 ("cargo-bootstrap" ,mrustc "cargo")
8fdde581
DM
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"
afc2bf53 475
8fdde581 476 ;; rustc invokes gcc, so we need to set its search paths accordingly.
afc2bf53
LC
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
8fdde581
DM
490 (synopsis "Compiler for the Rust progamming language")
491 (description "Rust is a systems programming language that provides memory
492safety and thread safety guarantees.")
493 (home-page "https://www.rust-lang.org")
494 ;; Dual licensed.
495 (license (list license:asl2.0 license:expat))))
496
614cfd5c
DM
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]
525cargo = \"" cargo "/bin/cargo" "\"
526rustc = \"" rustc "/bin/rustc" "\"
527docs = true
528python = \"" python "/bin/python2" "\"
529gdb = \"" gdb "/bin/gdb" "\"
530vendor = true
531submodules = false
532[install]
533prefix = \"" out "\"
534docdir = \"" doc "/share/doc/rust" "\"
535sysconfdir = \"etc\"
536localstatedir = \"var/lib\"
537[rust]
538default-linker = \"" gcc "/bin/gcc" "\"
539
540# The archiver that the finished compiler uses
541default-ar = \"" binutils "/bin/ar" "\"
542channel = \"stable\"
543rpath = true
544" ;; There are 2 failed codegen tests:
545;; codegen/mainsubprogram.rs and codegen/mainsubprogramstart.rs
546;; These tests require a patched LLVM
547"codegen-tests = false
548[target." ,(nix-system->gnu-triplet-for-rust) "]
549llvm-config = \"" llvm "/bin/llvm-config" "\"
550cc = \"" gcc "/bin/gcc" "\"
551cxx = \"" gcc "/bin/g++" "\"
552jemalloc = \"" jemalloc "/lib/libjemalloc_pic.a" "\"
553[dist]
554") port)))
555 #t)))
556 (add-after 'configure 'provide-cc
557 (lambda* (#:key inputs #:allow-other-keys)
558 (symlink (string-append (assoc-ref inputs "gcc") "/bin/gcc")
559 "/tmp/cc")
560 (setenv "PATH" (string-append "/tmp:" (getenv "PATH")))
561 #t))
562 (add-after 'provide-cc 'configure-archiver
563 (lambda* (#:key inputs #:allow-other-keys)
564 (substitute* "src/build_helper/lib.rs"
565 ;; Make sure "ar" is always used as the archiver.
566 (("\"musl\"") "\"\"")
567 ;; Then substitute "ar" by our name.
568 (("\"ar\"") (string-append "\""
569 (assoc-ref inputs "binutils")
570 "/bin/ar\"")))
571 #t))
572 (delete 'patch-cargo-tomls)
573 (add-before 'build 'reset-timestamps-after-changes
574 (lambda* _
575 (define ref (stat "README.md"))
576 (for-each
577 (lambda (filename)
578 (set-file-time filename ref))
579 (find-files "." #:directories? #t))
580 #t))
581 (replace 'build
582 (lambda* _
583 (invoke "./x.py" "build")
584 (invoke "./x.py" "build" "src/tools/cargo")))
585 (replace 'check
586 (lambda* _
587 ;; Disable parallel execution to prevent EAGAIN errors when
588 ;; running tests.
589 (invoke "./x.py" "-j1" "test" "-vv")
590 (invoke "./x.py" "-j1" "test" "src/tools/cargo")
591 #t))
592 (replace 'install
593 (lambda* (#:key outputs #:allow-other-keys)
594 (invoke "./x.py" "install")
595 (substitute* "config.toml"
596 ;; replace prefix to specific output
597 (("prefix = \"[^\"]*\"")
598 (string-append "prefix = \"" (assoc-ref outputs "cargo") "\"")))
599 (invoke "./x.py" "install" "cargo")))
600 (add-after 'install 'wrap-rustc
601 (lambda* (#:key inputs outputs #:allow-other-keys)
602 (let ((out (assoc-ref outputs "out"))
603 (libc (assoc-ref inputs "libc"))
604 (ld-wrapper (assoc-ref inputs "ld-wrapper")))
605 ;; Let gcc find ld and libc startup files.
606 (wrap-program (string-append out "/bin/rustc")
607 `("PATH" ":" prefix (,(string-append ld-wrapper "/bin")))
608 `("LIBRARY_PATH" ":" suffix (,(string-append libc "/lib"))))
609 #t))))))))))
610
8fdde581
DM
611(define-public rust-1.23
612 (package
333c0ca9 613 (inherit rust-1.20)
8fdde581
DM
614 (name "rust")
615 (version "1.23.0")
616 (source (rust-source version "14fb8vhjzsxlbi6yrn1r6fl5dlbdd1m92dn5zj5gmzfwf4w9ar3l"))
617 (outputs '("out" "doc" "cargo"))
3159ef7c
DM
618 (native-inputs
619 `(("bison" ,bison) ; For the tests
620 ("cmake" ,cmake)
621 ("flex" ,flex) ; For the tests
622 ("gdb" ,gdb) ; For the tests
623 ("git" ,git)
624 ("procps" ,procps) ; For the tests
625 ("python-2" ,python-2)
626 ("rustc-bootstrap" ,rust-bootstrap)
627 ("cargo-bootstrap" ,rust-bootstrap "cargo")
628 ("pkg-config" ,pkg-config) ; For "cargo"
629 ("which" ,which)))
8fdde581 630 (arguments
333c0ca9 631 (substitute-keyword-arguments (package-arguments rust-1.20)
8fdde581
DM
632 ((#:phases phases)
633 `(modify-phases ,phases
333c0ca9 634 (delete 'configure-archiver)
67ca98ec
EF
635 (add-after 'unpack 'dont-build-native
636 (lambda _
637 ;; XXX: Revisit this when we use gcc 6.
638 (substitute* "src/binaryen/CMakeLists.txt"
639 (("ADD_COMPILE_FLAG\\(\\\"-march=native\\\"\\)") ""))
640 #t))
1bb23335
NM
641 (add-after 'patch-tests 'patch-cargo-tests
642 (lambda _
643 (substitute* "src/tools/cargo/tests/build.rs"
644 (("/usr/bin/env") (which "env"))
645 ;; Guix llvm is compiled without asmjs-unknown-emscripten.
646 (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs"))
647 (substitute* "src/tools/cargo/tests/death.rs"
648 ;; This is stuck when built in container.
649 (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone"))
514026d7
RT
650 ;; Prints test output in the wrong order when built on
651 ;; i686-linux.
652 (substitute* "src/tools/cargo/tests/test.rs"
653 (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env"))
1bb23335 654 #t))
b47b2d32
NM
655 (add-after 'patch-cargo-tests 'ignore-glibc-2.27-incompatible-test
656 ;; https://github.com/rust-lang/rust/issues/47863
657 (lambda _
658 (substitute* "src/test/run-pass/out-of-stack.rs"
659 (("// ignore-android") "// ignore-test\n// ignore-android"))))
660 (add-after 'ignore-glibc-2.27-incompatible-test 'fix-mtime-bug
8fdde581
DM
661 (lambda* _
662 (substitute* "src/build_helper/lib.rs"
663 ;; Bug in Rust code.
664 ;; Current implementation assume that if dst not exist then it's mtime
665 ;; is 0, but in same time "src" have 0 mtime in guix build!
666 (("let threshold = mtime\\(dst\\);")
667 "if !dst.exists() {\nreturn false\n}\n let threshold = mtime(dst);"))
333c0ca9 668 #t))))))))
b5a09649 669
fe61c88a 670(define-public rust-1.24
ca523cc5
DM
671 (let ((base-rust
672 (rust-bootstrapped-package rust-1.23 "1.24.1"
673 "1vv10x2h9kq7fxh2v01damdq8pvlp5acyh1kzcda9sfjx12kv99y")))
f342bb58
NM
674 (package
675 (inherit base-rust)
f342bb58
NM
676 (arguments
677 (substitute-keyword-arguments (package-arguments base-rust)
ca523cc5
DM
678 ((#:phases phases)
679 `(modify-phases ,phases
b47b2d32
NM
680 (delete 'use-readelf-for-tests)
681 (replace 'patch-aarch64-test
682 (lambda* _
683 (substitute* "src/librustc_metadata/dynamic_lib.rs"
684 ;; This test is known to fail on aarch64 and powerpc64le:
685 ;; https://github.com/rust-lang/rust/issues/45410
686 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
687 #t))
ca523cc5 688 (delete 'fix-mtime-bug))))))))
fe61c88a 689
b47b2d32
NM
690(define-public rust-1.25
691 (let ((base-rust
692 (rust-bootstrapped-package rust-1.24 "1.25.0"
693 "0baxjr99311lvwdq0s38bipbnj72pn6fgbk6lcq7j555xq53mxpf")))
fe61c88a
NM
694 (package
695 (inherit base-rust)
b47b2d32
NM
696 (inputs
697 ;; Use LLVM 6.0
698 (alist-replace "llvm" (list llvm)
699 (package-inputs base-rust)))
fe61c88a
NM
700 (arguments
701 (substitute-keyword-arguments (package-arguments base-rust)
702 ((#:phases phases)
703 `(modify-phases ,phases
704 (add-after 'patch-cargo-tests 'patch-cargo-index-update
080e11b4 705 (lambda _
fe61c88a
NM
706 (substitute* "src/tools/cargo/tests/generate-lockfile.rs"
707 ;; This test wants to update the crate index.
080e11b4
EF
708 (("fn no_index_update") "#[ignore]\nfn no_index_update"))
709 #t))
b47b2d32 710 (add-after 'configure 'enable-codegen-tests
080e11b4 711 (lambda _
b47b2d32 712 (substitute* "config.toml"
080e11b4
EF
713 (("codegen-tests = false") ""))
714 #t))
715 (replace 'patch-aarch64-test
716 (lambda _
717 (substitute* "src/librustc_metadata/dynamic_lib.rs"
718 ;; This test is known to fail on aarch64 and powerpc64le:
719 ;; https://github.com/rust-lang/rust/issues/45410
720 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
721 ;; This test fails on aarch64 with llvm@6.0:
722 ;; https://github.com/rust-lang/rust/issues/49807
723 ;; other possible solution:
724 ;; https://github.com/rust-lang/rust/pull/47688
725 (delete-file "src/test/debuginfo/by-value-self-argument-in-trait-impl.rs")
726 #t))
b47b2d32
NM
727 (delete 'ignore-glibc-2.27-incompatible-test))))))))
728
f510a2b9 729(define-public rust-1.26
b47b2d32
NM
730 (let ((base-rust
731 (rust-bootstrapped-package rust-1.25 "1.26.2"
732 "0047ais0fvmqvngqkdsxgrzhb0kljg8wy85b01kbbjc88hqcz7pv"
733 #:patches '("rust-coresimd-doctest.patch"))))
734 (package
735 (inherit base-rust)
736 (arguments
737 (substitute-keyword-arguments (package-arguments base-rust)
738 ((#:phases phases)
739 `(modify-phases ,phases
740 ;; binaryen was replaced with LLD project from LLVM
741 (delete 'dont-build-native)
742 (replace 'remove-unsupported-tests
743 (lambda* _
744 ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH.
745 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html>
746 (delete-file-recursively "src/test/run-make-fulldeps/linker-output-non-utf8")
747 #t))
748 (replace 'patch-cargo-tests
749 (lambda* _
750 (substitute* "src/tools/cargo/tests/testsuite/build.rs"
751 (("/usr/bin/env") (which "env"))
752 ;; Guix llvm is compiled without asmjs-unknown-emscripten.
753 (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs"))
754 (substitute* "src/tools/cargo/tests/testsuite/death.rs"
755 ;; This is stuck when built in container.
756 (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone"))
757 ;; Prints test output in the wrong order when built on
758 ;; i686-linux.
759 (substitute* "src/tools/cargo/tests/testsuite/test.rs"
760 (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env"))
761 #t))
762 (add-after 'patch-cargo-tests 'disable-cargo-test-for-nightly-channel
763 (lambda* _
764 ;; This test failed to work on "nightly" channel builds
765 ;; https://github.com/rust-lang/cargo/issues/5648
766 (substitute* "src/tools/cargo/tests/testsuite/resolve.rs"
767 (("fn test_resolving_minimum_version_with_transitive_deps")
768 "#[ignore]\nfn test_resolving_minimum_version_with_transitive_deps"))
769 #t))
770 (replace 'patch-cargo-index-update
771 (lambda* _
772 (substitute* "src/tools/cargo/tests/testsuite/generate_lockfile.rs"
773 ;; This test wants to update the crate index.
774 (("fn no_index_update") "#[ignore]\nfn no_index_update"))
775 #t)))))))))
f510a2b9
NM
776
777(define-public rust
778 (let ((base-rust
779 (rust-bootstrapped-package rust-1.26 "1.27.0"
780 "089d7rhw55zpvnw71dj8vil6qrylvl4xjr4m8bywjj83d4zq1f9c"
781 #:patches
782 '("rust-coresimd-doctest.patch"
783 "rust-bootstrap-stage0-test.patch"))))
784 (package
785 (inherit base-rust)
786 (arguments
787 (substitute-keyword-arguments (package-arguments base-rust)
788 ((#:phases phases)
789 `(modify-phases ,phases
790 (add-before 'install 'mkdir-prefix-paths
791 (lambda* (#:key outputs #:allow-other-keys)
792 ;; As result of https://github.com/rust-lang/rust/issues/36989
793 ;; `prefix' directory should exist before `install' call
794 (mkdir-p (assoc-ref outputs "out"))
795 (mkdir-p (assoc-ref outputs "cargo"))
796 #t)))))))))