gnu: rust@1.19: Don't make public.
[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")))
129 ;; Install rustc/rustdoc
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)))
f342bb58
NM
135 ;; Instal cargo
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))
146 ;; Rust requires a C toolchain for linking. The prebuilt
147 ;; binaries expect a compiler called cc. Thus symlink gcc
148 ;; to cc.
149 (symlink (string-append gcc "/bin/gcc")
150 (string-append out "/bin/cc"))
151 #t))))))
423f9e44 152 (home-page "https://www.rust-lang.org")
f342bb58
NM
153 (synopsis "Prebuilt rust compiler and cargo package manager")
154 (description "This package provides a pre-built @command{rustc} compiler
b3884bbf 155and a pre-built @command{cargo} package manager, which can
f342bb58 156in turn be used to build the final Rust.")
423f9e44
DC
157 (license license:asl2.0)))
158
d53fb678 159\f
b47b2d32 160(define* (rust-source version hash #:key (patches '()))
f342bb58
NM
161 (origin
162 (method url-fetch)
163 (uri (string-append "https://static.rust-lang.org/dist/"
164 "rustc-" version "-src.tar.gz"))
165 (sha256 (base32 hash))
166 (modules '((guix build utils)))
b47b2d32
NM
167 (snippet '(begin (delete-file-recursively "src/llvm") #t))
168 (patches (map search-patch patches))))
f342bb58 169
4f963b6f 170(define rust-1.19
ecee2147 171 (package
f342bb58 172 (name "rust")
8fdde581
DM
173 (version "1.19.0")
174 (source (rust-source version "0l8c14qsf42rmkqy92ahij4vf356dbyspxcips1aswpvad81y8qm"))
175 (outputs '("out" "cargo"))
ecee2147 176 (arguments
d53fb678
NM
177 `(#:imported-modules ,%cargo-build-system-modules ;for `generate-checksums'
178 #:phases
ecee2147 179 (modify-phases %standard-phases
ecee2147 180 (add-after 'unpack 'set-env
1bb23335
NM
181 (lambda* (#:key inputs #:allow-other-keys)
182 ;; Disable test for cross compilation support.
183 (setenv "CFG_DISABLE_CROSS_TESTS" "1")
ecee2147 184 (setenv "SHELL" (which "sh"))
326249ba 185 (setenv "CONFIG_SHELL" (which "sh"))
1bb23335 186 (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
d53fb678
NM
187 ;; guix llvm-3.9.1 package installs only shared libraries
188 (setenv "LLVM_LINK_SHARED" "1")
326249ba 189 #t))
84aac61c
DM
190 (add-after 'unpack 'patch-tests
191 (lambda* (#:key inputs #:allow-other-keys)
9b7a9580 192 (let ((bash (assoc-ref inputs "bash")))
9b7a9580 193 (substitute* "src/libstd/process.rs"
5f3d46ce
DM
194 ;; The newline is intentional.
195 ;; There's a line length "tidy" check in Rust which would
196 ;; fail otherwise.
d53fb678
NM
197 (("\"/bin/sh\"") (string-append "\n\"" bash "/bin/sh\"")))
198 (substitute* "src/libstd/net/tcp.rs"
199 ;; There is no network in build environment
200 (("fn connect_timeout_unroutable")
201 "#[ignore]\nfn connect_timeout_unroutable"))
202 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00222.html>
5f3d46ce 203 (substitute* "src/libstd/sys/unix/process/process_common.rs"
237587f1
DM
204 (("fn test_process_mask") "#[allow(unused_attributes)]
205 #[ignore]
af4ea9c5 206 fn test_process_mask"))
9b7a9580 207 #t)))
b47b2d32
NM
208 (add-after 'patch-tests 'patch-aarch64-test
209 (lambda* _
210 (substitute* "src/librustc_back/dynamic_lib.rs"
211 ;; This test is known to fail on aarch64 and powerpc64le:
212 ;; https://github.com/rust-lang/rust/issues/45410
213 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
214 #t))
215 (add-after 'patch-tests 'use-readelf-for-tests
216 (lambda* _
217 ;; nm doesn't recognize the file format because of the
218 ;; nonstandard sections used by the Rust compiler, but readelf
219 ;; ignores them.
220 (substitute* "src/test/run-make/atomic-lock-free/Makefile"
221 (("\tnm ")
222 "\treadelf -c "))
223 #t))
224 (add-after 'patch-tests 'remove-unsupported-tests
225 (lambda* _
226 ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH.
227 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html>
228 (delete-file-recursively "src/test/run-make/linker-output-non-utf8")
229 #t))
d53fb678 230 (add-after 'patch-source-shebangs 'patch-cargo-checksums
f342bb58 231 (lambda* _
d53fb678
NM
232 (substitute* "src/Cargo.lock"
233 (("(\"checksum .* = )\".*\"" all name)
234 (string-append name "\"" ,%cargo-reference-hash "\"")))
235 (for-each
236 (lambda (filename)
237 (use-modules (guix build cargo-build-system))
238 (delete-file filename)
239 (let* ((dir (dirname filename)))
240 (display (string-append
241 "patch-cargo-checksums: generate-checksums for "
242 dir "\n"))
243 (generate-checksums dir ,%cargo-reference-project-file)))
244 (find-files "src/vendor" ".cargo-checksum.json"))
245 #t))
ecee2147 246 (replace 'configure
8fdde581
DM
247 (const #t))
248 (replace 'check
249 (const #t))
250 (replace 'install
251 (const #t)))))
252 (build-system gnu-build-system)
253 (native-inputs
254 `(("bison" ,bison) ; For the tests
255 ("cmake" ,cmake)
256 ("flex" ,flex) ; For the tests
257 ("gdb" ,gdb) ; For the tests
258 ("git" ,git)
259 ("procps" ,procps) ; For the tests
260 ("python-2" ,python-2)
261 ("rustc-bootstrap" ,rust-bootstrap)
262 ("cargo-bootstrap" ,rust-bootstrap "cargo")
263 ("pkg-config" ,pkg-config) ; For "cargo"
264 ("which" ,which)))
265 (inputs
266 `(("jemalloc" ,jemalloc-4.5.0)
267 ("llvm" ,llvm-3.9.1)
268 ("openssl" ,openssl)
269 ("libcurl" ,curl))) ; For "cargo"
afc2bf53 270
8fdde581 271 ;; rustc invokes gcc, so we need to set its search paths accordingly.
afc2bf53
LC
272 ;; Note: duplicate its value here to cope with circular dependencies among
273 ;; modules (see <https://bugs.gnu.org/31392>).
274 (native-search-paths
275 (list (search-path-specification
276 (variable "C_INCLUDE_PATH")
277 (files '("include")))
278 (search-path-specification
279 (variable "CPLUS_INCLUDE_PATH")
280 (files '("include")))
281 (search-path-specification
282 (variable "LIBRARY_PATH")
283 (files '("lib" "lib64")))))
284
8fdde581
DM
285 (synopsis "Compiler for the Rust progamming language")
286 (description "Rust is a systems programming language that provides memory
287safety and thread safety guarantees.")
288 (home-page "https://www.rust-lang.org")
289 ;; Dual licensed.
290 (license (list license:asl2.0 license:expat))))
291
b47b2d32
NM
292(define* (rust-bootstrapped-package base-rust version checksum
293 #:key (patches '()))
294 "Bootstrap rust VERSION with source checksum CHECKSUM patched with PATCHES using BASE-RUST."
ca523cc5
DM
295 (package
296 (inherit base-rust)
297 (version version)
298 (source
b47b2d32 299 (rust-source version checksum #:patches patches))
ca523cc5
DM
300 (native-inputs
301 (alist-replace "cargo-bootstrap" (list base-rust "cargo")
302 (alist-replace "rustc-bootstrap" (list base-rust)
303 (package-native-inputs base-rust))))))
304
a92bf11c 305(define-public mrustc
c75c9b05
DM
306 (let ((commit "b5b70897015ee70d62ddda9711c256ca7c720e0f")
307 (revision "3")
a92bf11c
DM
308 (rustc-version "1.19.0"))
309 (package
310 (name "mrustc")
311 (version (git-version "0.0.0" revision commit))
312 (source (origin
313 (method git-fetch)
314 (uri (git-reference
315 (url "https://github.com/thepowersgang/mrustc.git")
316 (commit commit)))
317 (file-name (git-file-name name version))
318 (sha256
319 (base32
c75c9b05 320 "1d6jr6agiy598ab8lax0h9dfn9n67wg906y1f46l1c27sz3w82lb"))))
a92bf11c
DM
321 (outputs '("out" "cargo"))
322 (build-system gnu-build-system)
323 (inputs
324 `(("llvm" ,llvm-3.9.1)))
325 (native-inputs
326 `(("bison" ,bison)
327 ("flex" ,flex)
328 ;; Required for the libstd sources.
329 ("rustc"
330 ,(rust-source "1.19.0" "0l8c14qsf42rmkqy92ahij4vf356dbyspxcips1aswpvad81y8qm"))))
331 (arguments
332 `(#:tests? #f
333 #:make-flags (list (string-append "LLVM_CONFIG="
334 (assoc-ref %build-inputs "llvm")
335 "/bin/llvm-config"))
336 #:phases
337 (modify-phases %standard-phases
338 (add-after 'unpack 'unpack-target-compiler
339 (lambda* (#:key inputs outputs #:allow-other-keys)
340 (substitute* "minicargo.mk"
341 ;; Don't try to build LLVM.
342 (("^[$][(]LLVM_CONFIG[)]:") "xxx:")
343 ;; Build for the correct target architecture.
344 (("^RUSTC_TARGET := x86_64-unknown-linux-gnu")
345 (string-append "RUSTC_TARGET := "
346 ,(or (%current-target-system)
2c790226 347 (nix-system->gnu-triplet-for-rust)))))
a92bf11c
DM
348 (invoke "tar" "xf" (assoc-ref inputs "rustc"))
349 (chdir "rustc-1.19.0-src")
350 (invoke "patch" "-p0" "../rust_src.patch")
351 (chdir "..")
352 #t))
39b40f16
DM
353 (replace 'configure
354 (lambda* (#:key inputs #:allow-other-keys)
355 (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
356 #t))
a92bf11c
DM
357 (add-after 'build 'build-minicargo
358 (lambda _
359 (for-each (lambda (target)
360 (invoke "make" "-f" "minicargo.mk" target))
361 '("output/libstd.hir" "output/libpanic_unwind.hir"
362 "output/libproc_macro.hir" "output/libtest.hir"))
363 ;; Technically the above already does it - but we want to be clear.
364 (invoke "make" "-C" "tools/minicargo")))
365 (replace 'install
366 (lambda* (#:key inputs outputs #:allow-other-keys)
367 (let* ((out (assoc-ref outputs "out"))
368 (bin (string-append out "/bin"))
369 (tools-bin (string-append out "/tools/bin"))
370 (cargo-out (assoc-ref outputs "cargo"))
371 (cargo-bin (string-append cargo-out "/bin"))
372 (lib (string-append out "/lib"))
373 (lib/rust (string-append lib "/mrust"))
374 (gcc (assoc-ref inputs "gcc")))
375 ;; These files are not reproducible.
376 (for-each delete-file (find-files "output" "\\.txt$"))
377 (mkdir-p lib)
378 (copy-recursively "output" lib/rust)
379 (mkdir-p bin)
380 (mkdir-p tools-bin)
381 (install-file "bin/mrustc" bin)
382 ;; minicargo uses relative paths to resolve mrustc.
383 (install-file "tools/bin/minicargo" tools-bin)
384 (install-file "tools/bin/minicargo" cargo-bin)
385 #t))))))
386 (synopsis "Compiler for the Rust progamming language")
387 (description "Rust is a systems programming language that provides memory
388safety and thread safety guarantees.")
389 (home-page "https://github.com/thepowersgang/mrustc")
390 ;; Dual licensed.
391 (license (list license:asl2.0 license:expat)))))
392
8fdde581
DM
393(define-public rust-1.23
394 (package
395 (inherit rust-1.19)
396 (name "rust")
397 (version "1.23.0")
398 (source (rust-source version "14fb8vhjzsxlbi6yrn1r6fl5dlbdd1m92dn5zj5gmzfwf4w9ar3l"))
399 (outputs '("out" "doc" "cargo"))
400 (arguments
401 (substitute-keyword-arguments (package-arguments rust-1.19)
402 ((#:phases phases)
403 `(modify-phases ,phases
67ca98ec
EF
404 (add-after 'unpack 'dont-build-native
405 (lambda _
406 ;; XXX: Revisit this when we use gcc 6.
407 (substitute* "src/binaryen/CMakeLists.txt"
408 (("ADD_COMPILE_FLAG\\(\\\"-march=native\\\"\\)") ""))
409 #t))
1bb23335
NM
410 (add-after 'patch-tests 'patch-cargo-tests
411 (lambda _
412 (substitute* "src/tools/cargo/tests/build.rs"
413 (("/usr/bin/env") (which "env"))
414 ;; Guix llvm is compiled without asmjs-unknown-emscripten.
415 (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs"))
416 (substitute* "src/tools/cargo/tests/death.rs"
417 ;; This is stuck when built in container.
418 (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone"))
514026d7
RT
419 ;; Prints test output in the wrong order when built on
420 ;; i686-linux.
421 (substitute* "src/tools/cargo/tests/test.rs"
422 (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env"))
1bb23335 423 #t))
b47b2d32
NM
424 (add-after 'patch-cargo-tests 'ignore-glibc-2.27-incompatible-test
425 ;; https://github.com/rust-lang/rust/issues/47863
426 (lambda _
427 (substitute* "src/test/run-pass/out-of-stack.rs"
428 (("// ignore-android") "// ignore-test\n// ignore-android"))))
429 (add-after 'ignore-glibc-2.27-incompatible-test 'fix-mtime-bug
8fdde581
DM
430 (lambda* _
431 (substitute* "src/build_helper/lib.rs"
432 ;; Bug in Rust code.
433 ;; Current implementation assume that if dst not exist then it's mtime
434 ;; is 0, but in same time "src" have 0 mtime in guix build!
435 (("let threshold = mtime\\(dst\\);")
436 "if !dst.exists() {\nreturn false\n}\n let threshold = mtime(dst);"))
437 #t))
438 (replace 'configure
439 (lambda* (#:key inputs outputs #:allow-other-keys)
440 (let* ((out (assoc-ref outputs "out"))
441 (doc (assoc-ref outputs "doc"))
442 (gcc (assoc-ref inputs "gcc"))
443 (gdb (assoc-ref inputs "gdb"))
444 (binutils (assoc-ref inputs "binutils"))
445 (python (assoc-ref inputs "python-2"))
446 (rustc (assoc-ref inputs "rustc-bootstrap"))
447 (cargo (assoc-ref inputs "cargo-bootstrap"))
448 (llvm (assoc-ref inputs "llvm"))
449 (jemalloc (assoc-ref inputs "jemalloc")))
450 (call-with-output-file "config.toml"
451 (lambda (port)
452 (display (string-append "
d53fb678
NM
453[llvm]
454[build]
455cargo = \"" cargo "/bin/cargo" "\"
456rustc = \"" rustc "/bin/rustc" "\"
f342bb58 457docs = true
d53fb678
NM
458python = \"" python "/bin/python2" "\"
459gdb = \"" gdb "/bin/gdb" "\"
460vendor = true
461submodules = false
462[install]
463prefix = \"" out "\"
f342bb58
NM
464docdir = \"" doc "/share/doc/rust" "\"
465sysconfdir = \"etc\"
466localstatedir = \"var/lib\"
d53fb678
NM
467[rust]
468default-linker = \"" gcc "/bin/gcc" "\"
d53fb678
NM
469channel = \"stable\"
470rpath = true
b47b2d32
NM
471" ;; There are 2 failed codegen tests:
472 ;; codegen/mainsubprogram.rs and codegen/mainsubprogramstart.rs
473 ;; These tests require a patched LLVM
474"codegen-tests = false
2c790226 475[target." ,(nix-system->gnu-triplet-for-rust) "]
d53fb678
NM
476llvm-config = \"" llvm "/bin/llvm-config" "\"
477cc = \"" gcc "/bin/gcc" "\"
478cxx = \"" gcc "/bin/g++" "\"
f342bb58 479ar = \"" binutils "/bin/ar" "\"
d53fb678
NM
480jemalloc = \"" jemalloc "/lib/libjemalloc_pic.a" "\"
481[dist]
482") port)))
483 #t)))
484 (add-before 'build 'reset-timestamps-after-changes
f342bb58 485 (lambda* _
d53fb678
NM
486 (define ref (stat "README.md"))
487 (for-each
488 (lambda (filename)
489 (set-file-time filename ref))
490 (find-files "." #:directories? #t))
491 #t))
492 (replace 'build
f342bb58
NM
493 (lambda* _
494 (invoke "./x.py" "build")
495 (invoke "./x.py" "build" "src/tools/cargo")))
d53fb678 496 (replace 'check
f342bb58 497 (lambda* _
514026d7
RT
498 ;; Disable parallel execution to prevent EAGAIN errors when
499 ;; running tests.
500 (invoke "./x.py" "-j1" "test")
501 (invoke "./x.py" "-j1" "test" "src/tools/cargo")))
d53fb678 502 (replace 'install
f342bb58
NM
503 (lambda* (#:key outputs #:allow-other-keys)
504 (invoke "./x.py" "install")
505 (substitute* "config.toml"
506 ;; replace prefix to specific output
507 (("prefix = \"[^\"]*\"")
508 (string-append "prefix = \"" (assoc-ref outputs "cargo") "\"")))
509 (invoke "./x.py" "install" "cargo")
510 #t))
5d18d776
DC
511 (add-after 'install 'wrap-rustc
512 (lambda* (#:key inputs outputs #:allow-other-keys)
513 (let ((out (assoc-ref outputs "out"))
514 (libc (assoc-ref inputs "libc"))
515 (ld-wrapper (assoc-ref inputs "ld-wrapper")))
516 ;; Let gcc find ld and libc startup files.
517 (wrap-program (string-append out "/bin/rustc")
518 `("PATH" ":" prefix (,(string-append ld-wrapper "/bin")))
326249ba 519 `("LIBRARY_PATH" ":" suffix (,(string-append libc "/lib"))))
8fdde581 520 #t)))))))))
b5a09649 521
fe61c88a 522(define-public rust-1.24
ca523cc5
DM
523 (let ((base-rust
524 (rust-bootstrapped-package rust-1.23 "1.24.1"
525 "1vv10x2h9kq7fxh2v01damdq8pvlp5acyh1kzcda9sfjx12kv99y")))
f342bb58
NM
526 (package
527 (inherit base-rust)
f342bb58
NM
528 (arguments
529 (substitute-keyword-arguments (package-arguments base-rust)
ca523cc5
DM
530 ((#:phases phases)
531 `(modify-phases ,phases
b47b2d32
NM
532 (delete 'use-readelf-for-tests)
533 (replace 'patch-aarch64-test
534 (lambda* _
535 (substitute* "src/librustc_metadata/dynamic_lib.rs"
536 ;; This test is known to fail on aarch64 and powerpc64le:
537 ;; https://github.com/rust-lang/rust/issues/45410
538 (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine"))
539 #t))
ca523cc5 540 (delete 'fix-mtime-bug))))))))
fe61c88a 541
b47b2d32
NM
542(define-public rust-1.25
543 (let ((base-rust
544 (rust-bootstrapped-package rust-1.24 "1.25.0"
545 "0baxjr99311lvwdq0s38bipbnj72pn6fgbk6lcq7j555xq53mxpf")))
fe61c88a
NM
546 (package
547 (inherit base-rust)
b47b2d32
NM
548 (inputs
549 ;; Use LLVM 6.0
550 (alist-replace "llvm" (list llvm)
551 (package-inputs base-rust)))
fe61c88a
NM
552 (arguments
553 (substitute-keyword-arguments (package-arguments base-rust)
554 ((#:phases phases)
555 `(modify-phases ,phases
556 (add-after 'patch-cargo-tests 'patch-cargo-index-update
557 (lambda* _
558 (substitute* "src/tools/cargo/tests/generate-lockfile.rs"
559 ;; This test wants to update the crate index.
b47b2d32
NM
560 (("fn no_index_update") "#[ignore]\nfn no_index_update"))))
561 (add-after 'configure 'enable-codegen-tests
562 (lambda* _
563 (substitute* "config.toml"
564 (("codegen-tests = false") ""))))
565 (delete 'ignore-glibc-2.27-incompatible-test))))))))
566
f510a2b9 567(define-public rust-1.26
b47b2d32
NM
568 (let ((base-rust
569 (rust-bootstrapped-package rust-1.25 "1.26.2"
570 "0047ais0fvmqvngqkdsxgrzhb0kljg8wy85b01kbbjc88hqcz7pv"
571 #:patches '("rust-coresimd-doctest.patch"))))
572 (package
573 (inherit base-rust)
574 (arguments
575 (substitute-keyword-arguments (package-arguments base-rust)
576 ((#:phases phases)
577 `(modify-phases ,phases
578 ;; binaryen was replaced with LLD project from LLVM
579 (delete 'dont-build-native)
580 (replace 'remove-unsupported-tests
581 (lambda* _
582 ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH.
583 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html>
584 (delete-file-recursively "src/test/run-make-fulldeps/linker-output-non-utf8")
585 #t))
586 (replace 'patch-cargo-tests
587 (lambda* _
588 (substitute* "src/tools/cargo/tests/testsuite/build.rs"
589 (("/usr/bin/env") (which "env"))
590 ;; Guix llvm is compiled without asmjs-unknown-emscripten.
591 (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs"))
592 (substitute* "src/tools/cargo/tests/testsuite/death.rs"
593 ;; This is stuck when built in container.
594 (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone"))
595 ;; Prints test output in the wrong order when built on
596 ;; i686-linux.
597 (substitute* "src/tools/cargo/tests/testsuite/test.rs"
598 (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env"))
599 #t))
600 (add-after 'patch-cargo-tests 'disable-cargo-test-for-nightly-channel
601 (lambda* _
602 ;; This test failed to work on "nightly" channel builds
603 ;; https://github.com/rust-lang/cargo/issues/5648
604 (substitute* "src/tools/cargo/tests/testsuite/resolve.rs"
605 (("fn test_resolving_minimum_version_with_transitive_deps")
606 "#[ignore]\nfn test_resolving_minimum_version_with_transitive_deps"))
607 #t))
608 (replace 'patch-cargo-index-update
609 (lambda* _
610 (substitute* "src/tools/cargo/tests/testsuite/generate_lockfile.rs"
611 ;; This test wants to update the crate index.
612 (("fn no_index_update") "#[ignore]\nfn no_index_update"))
613 #t)))))))))
f510a2b9
NM
614
615(define-public rust
616 (let ((base-rust
617 (rust-bootstrapped-package rust-1.26 "1.27.0"
618 "089d7rhw55zpvnw71dj8vil6qrylvl4xjr4m8bywjj83d4zq1f9c"
619 #:patches
620 '("rust-coresimd-doctest.patch"
621 "rust-bootstrap-stage0-test.patch"))))
622 (package
623 (inherit base-rust)
624 (arguments
625 (substitute-keyword-arguments (package-arguments base-rust)
626 ((#:phases phases)
627 `(modify-phases ,phases
628 (add-before 'install 'mkdir-prefix-paths
629 (lambda* (#:key outputs #:allow-other-keys)
630 ;; As result of https://github.com/rust-lang/rust/issues/36989
631 ;; `prefix' directory should exist before `install' call
632 (mkdir-p (assoc-ref outputs "out"))
633 (mkdir-p (assoc-ref outputs "cargo"))
634 #t)))))))))