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