gnu: rust: Update rust to 1.24.1.
[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>
423f9e44
DC
9;;;
10;;; This file is part of GNU Guix.
11;;;
12;;; GNU Guix is free software; you can redistribute it and/or modify it
13;;; under the terms of the GNU General Public License as published by
14;;; the Free Software Foundation; either version 3 of the License, or (at
15;;; your option) any later version.
16;;;
17;;; GNU Guix is distributed in the hope that it will be useful, but
18;;; WITHOUT ANY WARRANTY; without even the implied warranty of
19;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;;; GNU General Public License for more details.
21;;;
22;;; You should have received a copy of the GNU General Public License
23;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
24
25(define-module (gnu packages rust)
26 #:use-module (gnu packages base)
5f3d46ce 27 #:use-module (gnu packages bison)
423f9e44 28 #:use-module (gnu packages bootstrap)
ecee2147 29 #:use-module (gnu packages cmake)
423f9e44 30 #:use-module (gnu packages compression)
b5a09649 31 #:use-module (gnu packages curl)
423f9e44 32 #:use-module (gnu packages elf)
5f3d46ce 33 #:use-module (gnu packages flex)
423f9e44 34 #:use-module (gnu packages gcc)
d53fb678 35 #:use-module (gnu packages gdb)
ecee2147 36 #:use-module (gnu packages jemalloc)
5f3d46ce 37 #:use-module (gnu packages linux)
ecee2147 38 #:use-module (gnu packages llvm)
b5a09649 39 #:use-module (gnu packages pkg-config)
ecee2147 40 #:use-module (gnu packages python)
b5a09649
DC
41 #:use-module (gnu packages ssh)
42 #:use-module (gnu packages tls)
ecee2147 43 #:use-module (gnu packages version-control)
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)
49 #:use-module ((guix licenses) #:prefix license:)
50 #:use-module (guix packages)
f342bb58
NM
51 #:use-module ((guix build utils) #:select (alist-replace))
52 #:use-module (guix utils)
423f9e44
DC
53 #:use-module (ice-9 match)
54 #:use-module (srfi srfi-26))
55
d53fb678
NM
56(define %cargo-reference-project-file "/dev/null")
57(define %cargo-reference-hash
58 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
423f9e44 59
f342bb58 60(define rust-bootstrap
423f9e44 61 (package
f342bb58
NM
62 (name "rust-bootstrap")
63 (version "1.22.1")
64 (source (origin
65 (method url-fetch)
66 (uri (string-append
67 "https://static.rust-lang.org/dist/"
68 "rust-" version "-" %host-type ".tar.gz"))
69 (sha256
70 (base32
71 (match %host-type
72 ("i686-unknown-linux-gnu"
73 "15zqbx86nm13d5vq2gm69b7av4vg479f74b5by64hs3bcwwm08pr")
74 ("x86_64-unknown-linux-gnu"
75 "1yll78x6b3abnvgjf2b66gvp6mmcb9y9jdiqcwhmgc0z0i0fix4c")
76 ("armv7-unknown-linux-gnueabihf"
77 "138a8l528kzp5wyk1mgjaxs304ac5ms8vlpq0ggjaznm6bn2j7a5")
78 ("aarch64-unknown-linux-gnu"
79 "0z6m9m1rx4d96nvybbfmpscq4dv616m615ijy16d5wh2vx0p4na8")
80 ("mips64el-unknown-linux-gnuabi64"
81 "07k4pcv7jvfa48cscdj8752lby7m7xdl88v3a6na1vs675lhgja2")
82 (_ ""))))))
423f9e44
DC
83 (build-system gnu-build-system)
84 (native-inputs
85 `(("patchelf" ,patchelf)))
86 (inputs
f342bb58
NM
87 `(("gcc" ,(canonical-package gcc))
88 ("gcc:lib" ,(canonical-package gcc) "lib")
423f9e44 89 ("zlib" ,zlib)))
f342bb58 90 (outputs '("out" "cargo"))
423f9e44
DC
91 (arguments
92 `(#:tests? #f
93 #:strip-binaries? #f
423f9e44
DC
94 #:phases
95 (modify-phases %standard-phases
96 (delete 'configure)
97 (delete 'build)
98 (replace 'install
99 (lambda* (#:key inputs outputs #:allow-other-keys)
100 (let* ((out (assoc-ref outputs "out"))
f342bb58 101 (cargo-out (assoc-ref outputs "cargo"))
423f9e44
DC
102 (gcc:lib (assoc-ref inputs "gcc:lib"))
103 (libc (assoc-ref inputs "libc"))
104 (zlib (assoc-ref inputs "zlib"))
d53fb678 105 (ld-so (string-append libc ,(glibc-dynamic-linker)))
423f9e44
DC
106 (rpath (string-append out "/lib:" zlib "/lib:"
107 libc "/lib:" gcc:lib "/lib"))
f342bb58
NM
108 (cargo-rpath (string-append cargo-out "/lib:" libc "/lib:"
109 gcc:lib "/lib"))
423f9e44 110 (rustc (string-append out "/bin/rustc"))
f342bb58
NM
111 (rustdoc (string-append out "/bin/rustdoc"))
112 (cargo (string-append cargo-out "/bin/cargo"))
113 (gcc (assoc-ref inputs "gcc")))
114 ;; Install rustc/rustdoc
115 (invoke "bash" "install.sh"
423f9e44
DC
116 (string-append "--prefix=" out)
117 (string-append "--components=rustc,"
d53fb678 118 "rust-std-" %host-type))
f342bb58
NM
119 ;; Instal cargo
120 (invoke "bash" "install.sh"
121 (string-append "--prefix=" cargo-out)
122 (string-append "--components=cargo"))
423f9e44 123 (for-each (lambda (file)
f342bb58 124 (invoke "patchelf" "--set-rpath" rpath file))
423f9e44 125 (cons* rustc rustdoc (find-files out "\\.so$")))
f342bb58 126 (invoke "patchelf" "--set-rpath" cargo-rpath cargo)
423f9e44 127 (for-each (lambda (file)
f342bb58
NM
128 (invoke "patchelf" "--set-interpreter" ld-so file))
129 (list rustc rustdoc cargo))
130 ;; Rust requires a C toolchain for linking. The prebuilt
131 ;; binaries expect a compiler called cc. Thus symlink gcc
132 ;; to cc.
133 (symlink (string-append gcc "/bin/gcc")
134 (string-append out "/bin/cc"))
135 #t))))))
423f9e44 136 (home-page "https://www.rust-lang.org")
f342bb58
NM
137 (synopsis "Prebuilt rust compiler and cargo package manager")
138 (description "This package provides a pre-built @command{rustc} compiler
139and a pre-built @command{cargo} package manaer, which can
140in turn be used to build the final Rust.")
423f9e44
DC
141 (license license:asl2.0)))
142
d53fb678 143\f
f342bb58
NM
144(define (rust-source version hash)
145 (origin
146 (method url-fetch)
147 (uri (string-append "https://static.rust-lang.org/dist/"
148 "rustc-" version "-src.tar.gz"))
149 (sha256 (base32 hash))
150 (modules '((guix build utils)))
151 (snippet '(begin (delete-file-recursively "src/llvm") #t))))
152
153(define-public rust-1.23
ecee2147 154 (package
f342bb58
NM
155 (name "rust")
156 (version "1.23.0")
157 (source (rust-source version "14fb8vhjzsxlbi6yrn1r6fl5dlbdd1m92dn5zj5gmzfwf4w9ar3l"))
ecee2147
DC
158 (build-system gnu-build-system)
159 (native-inputs
5f3d46ce
DM
160 `(("bison" ,bison) ; For the tests
161 ("cmake" ,cmake)
162 ("flex" ,flex) ; For the tests
d53fb678 163 ("gdb" ,gdb) ; For the tests
ecee2147 164 ("git" ,git)
5f3d46ce 165 ("procps" ,procps) ; For the tests
ecee2147 166 ("python-2" ,python-2)
f342bb58
NM
167 ("rustc-bootstrap" ,rust-bootstrap)
168 ("cargo-bootstrap" ,rust-bootstrap "cargo")
169 ("pkg-config" ,pkg-config) ; For "cargo"
ecee2147
DC
170 ("which" ,which)))
171 (inputs
d53fb678 172 `(("jemalloc" ,jemalloc-4.5.0)
f342bb58
NM
173 ("llvm" ,llvm-3.9.1)
174 ("openssl" ,openssl)
175 ("libcurl" ,curl))) ; For "cargo"
176 (outputs '("out" "doc" "cargo"))
ecee2147 177 (arguments
d53fb678
NM
178 `(#:imported-modules ,%cargo-build-system-modules ;for `generate-checksums'
179 #:phases
ecee2147 180 (modify-phases %standard-phases
ecee2147
DC
181 (add-after 'unpack 'set-env
182 (lambda _
183 (setenv "SHELL" (which "sh"))
326249ba 184 (setenv "CONFIG_SHELL" (which "sh"))
d53fb678
NM
185 ;; guix llvm-3.9.1 package installs only shared libraries
186 (setenv "LLVM_LINK_SHARED" "1")
326249ba 187 #t))
84aac61c
DM
188 (add-after 'unpack 'patch-tests
189 (lambda* (#:key inputs #:allow-other-keys)
9b7a9580 190 (let ((bash (assoc-ref inputs "bash")))
9b7a9580 191 (substitute* "src/libstd/process.rs"
5f3d46ce
DM
192 ;; The newline is intentional.
193 ;; There's a line length "tidy" check in Rust which would
194 ;; fail otherwise.
d53fb678
NM
195 (("\"/bin/sh\"") (string-append "\n\"" bash "/bin/sh\"")))
196 (substitute* "src/libstd/net/tcp.rs"
197 ;; There is no network in build environment
198 (("fn connect_timeout_unroutable")
199 "#[ignore]\nfn connect_timeout_unroutable"))
200 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00222.html>
5f3d46ce 201 (substitute* "src/libstd/sys/unix/process/process_common.rs"
d53fb678 202 (("fn test_process_mask") "#[ignore]\nfn test_process_mask"))
5f3d46ce 203 ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH.
d53fb678 204 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html>
5f3d46ce 205 (delete-file-recursively "src/test/run-make/linker-output-non-utf8")
9b7a9580 206 #t)))
f342bb58
NM
207 (add-after 'patch-tests 'fix-mtime-bug
208 (lambda* _
209 (substitute* "src/build_helper/lib.rs"
210 ;; Bug in Rust code.
211 ;; Current implementation assume that if dst not exist then it's mtime
212 ;; is 0, but in same time "src" have 0 mtime in guix build!
213 (("let threshold = mtime\\(dst\\);")
214 "if !dst.exists() {\nreturn false\n}\n let threshold = mtime(dst);"))
215 #t))
d53fb678 216 (add-after 'patch-source-shebangs 'patch-cargo-checksums
f342bb58 217 (lambda* _
d53fb678
NM
218 (substitute* "src/Cargo.lock"
219 (("(\"checksum .* = )\".*\"" all name)
220 (string-append name "\"" ,%cargo-reference-hash "\"")))
221 (for-each
222 (lambda (filename)
223 (use-modules (guix build cargo-build-system))
224 (delete-file filename)
225 (let* ((dir (dirname filename)))
226 (display (string-append
227 "patch-cargo-checksums: generate-checksums for "
228 dir "\n"))
229 (generate-checksums dir ,%cargo-reference-project-file)))
230 (find-files "src/vendor" ".cargo-checksum.json"))
231 #t))
ecee2147
DC
232 (replace 'configure
233 (lambda* (#:key inputs outputs #:allow-other-keys)
234 (let* ((out (assoc-ref outputs "out"))
f342bb58 235 (doc (assoc-ref outputs "doc"))
ecee2147 236 (gcc (assoc-ref inputs "gcc"))
d53fb678 237 (gdb (assoc-ref inputs "gdb"))
5d18d776 238 (binutils (assoc-ref inputs "binutils"))
ecee2147
DC
239 (python (assoc-ref inputs "python-2"))
240 (rustc (assoc-ref inputs "rustc-bootstrap"))
d53fb678 241 (cargo (assoc-ref inputs "cargo-bootstrap"))
ecee2147 242 (llvm (assoc-ref inputs "llvm"))
d53fb678
NM
243 (jemalloc (assoc-ref inputs "jemalloc")))
244 (call-with-output-file "config.toml"
245 (lambda (port)
246 (display (string-append "
247[llvm]
248[build]
249cargo = \"" cargo "/bin/cargo" "\"
250rustc = \"" rustc "/bin/rustc" "\"
f342bb58 251docs = true
d53fb678
NM
252python = \"" python "/bin/python2" "\"
253gdb = \"" gdb "/bin/gdb" "\"
254vendor = true
255submodules = false
256[install]
257prefix = \"" out "\"
f342bb58
NM
258docdir = \"" doc "/share/doc/rust" "\"
259sysconfdir = \"etc\"
260localstatedir = \"var/lib\"
d53fb678
NM
261[rust]
262default-linker = \"" gcc "/bin/gcc" "\"
d53fb678
NM
263channel = \"stable\"
264rpath = true
265# There is 2 failed codegen tests:
266# codegen/mainsubprogram.rs and codegen/mainsubprogramstart.rs
267# This tests required patched LLVM
268codegen-tests = false
269[target." %host-type "]
270llvm-config = \"" llvm "/bin/llvm-config" "\"
271cc = \"" gcc "/bin/gcc" "\"
272cxx = \"" gcc "/bin/g++" "\"
f342bb58 273ar = \"" binutils "/bin/ar" "\"
d53fb678
NM
274jemalloc = \"" jemalloc "/lib/libjemalloc_pic.a" "\"
275[dist]
276") port)))
277 #t)))
278 (add-before 'build 'reset-timestamps-after-changes
f342bb58 279 (lambda* _
d53fb678
NM
280 (define ref (stat "README.md"))
281 (for-each
282 (lambda (filename)
283 (set-file-time filename ref))
284 (find-files "." #:directories? #t))
285 #t))
286 (replace 'build
f342bb58
NM
287 (lambda* _
288 (invoke "./x.py" "build")
289 (invoke "./x.py" "build" "src/tools/cargo")))
d53fb678 290 (replace 'check
f342bb58
NM
291 (lambda* _
292 (invoke "./x.py" "test")))
d53fb678 293 (replace 'install
f342bb58
NM
294 (lambda* (#:key outputs #:allow-other-keys)
295 (invoke "./x.py" "install")
296 (substitute* "config.toml"
297 ;; replace prefix to specific output
298 (("prefix = \"[^\"]*\"")
299 (string-append "prefix = \"" (assoc-ref outputs "cargo") "\"")))
300 (invoke "./x.py" "install" "cargo")
301 #t))
5d18d776
DC
302 (add-after 'install 'wrap-rustc
303 (lambda* (#:key inputs outputs #:allow-other-keys)
304 (let ((out (assoc-ref outputs "out"))
305 (libc (assoc-ref inputs "libc"))
306 (ld-wrapper (assoc-ref inputs "ld-wrapper")))
307 ;; Let gcc find ld and libc startup files.
308 (wrap-program (string-append out "/bin/rustc")
309 `("PATH" ":" prefix (,(string-append ld-wrapper "/bin")))
326249ba
DM
310 `("LIBRARY_PATH" ":" suffix (,(string-append libc "/lib"))))
311 #t))))))
fa73a7c1
BW
312 ;; rustc invokes gcc, so we need to set its search paths accordingly.
313 (native-search-paths (package-native-search-paths gcc))
ecee2147
DC
314 (synopsis "Compiler for the Rust progamming language")
315 (description "Rust is a systems programming language that provides memory
316safety and thread safety guarantees.")
317 (home-page "https://www.rust-lang.org")
318 ;; Dual licensed.
319 (license (list license:asl2.0 license:expat))))
b5a09649 320
f342bb58
NM
321(define-public rust
322 (let ((base-rust rust-1.23))
323 (package
324 (inherit base-rust)
325 (version "1.24.1")
326 (source
327 (rust-source version
328 "1vv10x2h9kq7fxh2v01damdq8pvlp5acyh1kzcda9sfjx12kv99y"))
329 (native-inputs
330 (alist-replace "cargo-bootstrap" (list base-rust "cargo")
331 (alist-replace "rustc-bootstrap" (list base-rust)
332 (package-native-inputs base-rust))))
333 (arguments
334 (substitute-keyword-arguments (package-arguments base-rust)
335 ((#:phases phases) `(modify-phases ,phases
336 (delete 'fix-mtime-bug))))))))