gnu: python-pandas: Fix build on 32-bit.
[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>
b9542563 4;;; Copyright © 2016 ng0 <ng0@libertad.pw>
fa73a7c1 5;;; Copyright © 2017 Ben Woodcroft <donttrustben@gmail.com>
423f9e44
DC
6;;;
7;;; This file is part of GNU Guix.
8;;;
9;;; GNU Guix is free software; you can redistribute it and/or modify it
10;;; under the terms of the GNU General Public License as published by
11;;; the Free Software Foundation; either version 3 of the License, or (at
12;;; your option) any later version.
13;;;
14;;; GNU Guix is distributed in the hope that it will be useful, but
15;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;;; GNU General Public License for more details.
18;;;
19;;; You should have received a copy of the GNU General Public License
20;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21
22(define-module (gnu packages rust)
23 #:use-module (gnu packages base)
24 #:use-module (gnu packages bootstrap)
ecee2147 25 #:use-module (gnu packages cmake)
423f9e44 26 #:use-module (gnu packages compression)
b5a09649 27 #:use-module (gnu packages curl)
423f9e44
DC
28 #:use-module (gnu packages elf)
29 #:use-module (gnu packages gcc)
ecee2147
DC
30 #:use-module (gnu packages jemalloc)
31 #:use-module (gnu packages llvm)
b5a09649 32 #:use-module (gnu packages pkg-config)
ecee2147 33 #:use-module (gnu packages python)
b5a09649
DC
34 #:use-module (gnu packages ssh)
35 #:use-module (gnu packages tls)
ecee2147 36 #:use-module (gnu packages version-control)
b5a09649 37 #:use-module (guix build-system cargo)
423f9e44
DC
38 #:use-module (guix build-system gnu)
39 #:use-module (guix build-system trivial)
40 #:use-module (guix download)
41 #:use-module ((guix licenses) #:prefix license:)
42 #:use-module (guix packages)
43 #:use-module (ice-9 match)
44 #:use-module (srfi srfi-26))
45
46;; Should be one less than the current released version.
b9542563 47(define %rust-bootstrap-binaries-version "1.13.0")
423f9e44
DC
48
49(define %rust-bootstrap-binaries
50 (origin
51 (method url-fetch)
52 (uri (string-append
53 "https://static.rust-lang.org/dist/"
54 "rust-" %rust-bootstrap-binaries-version
55 "-i686-unknown-linux-gnu.tar.gz"))
56 (sha256
57 (base32
b9542563 58 "0fcl7xgm2m21sjv1f27i3v692aa91lk8r867hl8d6l377w8k95r3"))))
423f9e44
DC
59
60(define (increment-rust-version rust-version major patch)
61 (match (string-split rust-version #\.)
62 (("1" minor _)
63 (string-append (number->string major) "."
64 (number->string (+ (string->number minor) 1)) "."
65 (number->string patch)))))
66
67(define* (cargo-version rustc-version #:optional (patch 0))
68 ;; Computes the cargo version that matches the rustc version.
69 ;; https://github.com/rust-lang/cargo#Releases
70 (increment-rust-version rustc-version 0 patch))
71
72(define* (rustc-version bootstrap-version #:optional (patch 0))
73 ;; Computes the rustc version that can be compiled from a given
74 ;; other rustc version. The patch argument is for selecting
75 ;; a stability or security fix. 1.11.0 -> 1.12.1 -> 1.13.0
76 (increment-rust-version bootstrap-version 1 patch))
77
78(define rustc-bootstrap
79 (package
80 (name "rustc-bootstrap")
81 (version %rust-bootstrap-binaries-version)
82 (source %rust-bootstrap-binaries)
83 (build-system gnu-build-system)
84 (native-inputs
85 `(("patchelf" ,patchelf)))
86 (inputs
87 `(("gcc:lib" ,(canonical-package gcc) "lib")
88 ("zlib" ,zlib)))
89 (arguments
90 `(#:tests? #f
91 #:strip-binaries? #f
92 #:system "i686-linux"
93 #:phases
94 (modify-phases %standard-phases
95 (delete 'configure)
96 (delete 'build)
97 (replace 'install
98 (lambda* (#:key inputs outputs #:allow-other-keys)
99 (let* ((out (assoc-ref outputs "out"))
100 (gcc:lib (assoc-ref inputs "gcc:lib"))
101 (libc (assoc-ref inputs "libc"))
102 (zlib (assoc-ref inputs "zlib"))
103 (ld-so (string-append libc
104 ,(glibc-dynamic-linker "i686-linux")))
105 (rpath (string-append out "/lib:" zlib "/lib:"
106 libc "/lib:" gcc:lib "/lib"))
107 (rustc (string-append out "/bin/rustc"))
108 (rustdoc (string-append out "/bin/rustdoc")))
109 (system* "bash" "install.sh"
110 (string-append "--prefix=" out)
111 (string-append "--components=rustc,"
112 "rust-std-i686-unknown-linux-gnu"))
113 (for-each (lambda (file)
114 (system* "patchelf" "--set-rpath" rpath file))
115 (cons* rustc rustdoc (find-files out "\\.so$")))
116 (for-each (lambda (file)
117 (system* "patchelf" "--set-interpreter" ld-so file))
118 (list rustc rustdoc))))))))
119 (supported-systems '("i686-linux" "x86_64-linux"))
120 (home-page "https://www.rust-lang.org")
121 (synopsis "Prebuilt rust compiler")
122 (description "This package provides a pre-built @command{rustc} compiler,
123which can in turn be used to build the final Rust compiler.")
124 (license license:asl2.0)))
125
3b7ccbe9 126(define cargo-bootstrap
423f9e44
DC
127 (package
128 (name "cargo-bootstrap")
129 (version (cargo-version %rust-bootstrap-binaries-version))
130 (source %rust-bootstrap-binaries)
131 (build-system gnu-build-system)
132 (native-inputs
133 `(("patchelf" ,patchelf)))
134 (inputs
135 `(("gcc:lib" ,(canonical-package gcc) "lib")))
136 (arguments
137 `(#:tests? #f
138 #:strip-binaries? #f
139 #:system "i686-linux"
140 #:phases
141 (modify-phases %standard-phases
142 (delete 'configure)
143 (delete 'build)
144 (replace 'install
145 (lambda* (#:key inputs outputs #:allow-other-keys)
146 (let* ((out (assoc-ref outputs "out"))
147 (gcc:lib (assoc-ref inputs "gcc:lib"))
148 (libc (assoc-ref inputs "libc"))
149 (ld-so (string-append libc
150 ,(glibc-dynamic-linker "i686-linux")))
151 (rpath (string-append out "/lib:" libc "/lib:"
152 gcc:lib "/lib"))
153 (cargo (string-append out "/bin/cargo")))
154 (system* "bash" "install.sh"
155 (string-append "--prefix=" out)
156 "--components=cargo")
157 (system* "patchelf"
158 "--set-interpreter" ld-so
159 "--set-rpath" rpath
160 cargo)))))))
161 (supported-systems '("i686-linux" "x86_64-linux"))
162 (home-page "https://www.rust-lang.org")
163 (synopsis "Prebuilt cargo package manager")
164 (description "This package provides a pre-built @command{cargo} package
165manager, which is required to build itself.")
166 (license license:asl2.0)))
167
168(define rust-bootstrap
169 (package
170 (name "rust-bootstrap")
171 (version %rust-bootstrap-binaries-version)
172 (source #f)
173 (build-system trivial-build-system)
174 (propagated-inputs
175 `(("rustc-bootstrap" ,rustc-bootstrap)
176 ("cargo-bootstrap" ,cargo-bootstrap)
177 ("gcc" ,(canonical-package gcc))))
178 (arguments
179 `(#:modules ((guix build utils))
180 #:builder
181 (begin
182 (use-modules (guix build utils))
183 (let ((out (assoc-ref %outputs "out"))
184 (gcc (assoc-ref %build-inputs "gcc")))
185 (mkdir-p (string-append out "/bin"))
186 ;; Rust requires a C toolchain for linking. The prebuilt
187 ;; binaries expect a compiler called cc. Thus symlink gcc
188 ;; to cc.
189 (symlink (string-append gcc "/bin/gcc")
190 (string-append out "/bin/cc"))))))
191 (home-page "https://www.rust-lang.org")
192 (synopsis "Rust bootstrapping meta package")
193 (description "Meta package for a rust environment. Provides pre-compiled
194rustc-bootstrap and cargo-bootstrap packages.")
195 (license license:asl2.0)))
ecee2147
DC
196
197(define-public rustc
198 (package
199 (name "rustc")
200 (version (rustc-version %rust-bootstrap-binaries-version))
201 (source (origin
202 (method url-fetch)
203 (uri (string-append
204 "https://static.rust-lang.org/dist/"
205 "rustc-" version "-src.tar.gz"))
206 (sha256
207 (base32
b9542563 208 "0srvmhhdbbcl21nzg9m9zni7k10h88lsy8k1ljz03g8mx79fv467"))))
ecee2147
DC
209 (build-system gnu-build-system)
210 (native-inputs
211 `(("cmake" ,cmake)
212 ("git" ,git)
213 ("python-2" ,python-2)
214 ("rust-bootstrap" ,rust-bootstrap)
215 ("which" ,which)))
216 (inputs
217 `(("jemalloc" ,jemalloc)
218 ("llvm" ,llvm)))
219 (arguments
220 ;; FIXME: Test failure with llvm 3.8; Update llvm.
221 ;; https://github.com/rust-lang/rust/issues/36835
222 `(#:tests? #f
223 #:phases
224 (modify-phases %standard-phases
225 (add-after 'unpack 'patch-configure
226 (lambda _
227 ;; Detect target CPU correctly.
228 (substitute* "configure"
229 (("/usr/bin/env") (which "env")))
230 ;; Avoid curl as a build dependency.
231 (substitute* "configure"
232 (("probe_need CFG_CURL curl") ""))))
233 (add-after 'unpack 'set-env
234 (lambda _
235 (setenv "SHELL" (which "sh"))
236 (setenv "CONFIG_SHELL" (which "sh"))))
237 (add-after 'unpack 'patch-lockfile-test
238 (lambda _
239 (substitute* "src/tools/tidy/src/main.rs"
240 (("^.*cargo.*::check.*$") ""))))
241 (replace 'configure
242 (lambda* (#:key inputs outputs #:allow-other-keys)
243 (let* ((out (assoc-ref outputs "out"))
244 (gcc (assoc-ref inputs "gcc"))
5d18d776 245 (binutils (assoc-ref inputs "binutils"))
ecee2147
DC
246 (python (assoc-ref inputs "python-2"))
247 (rustc (assoc-ref inputs "rustc-bootstrap"))
248 (llvm (assoc-ref inputs "llvm"))
249 (jemalloc (assoc-ref inputs "jemalloc"))
250 (flags (list
251 (string-append "--prefix=" out)
252 (string-append "--datadir=" out "/share")
253 (string-append "--infodir=" out "/share/info")
254 (string-append "--default-linker=" gcc "/bin/gcc")
5d18d776 255 (string-append "--default-ar=" binutils "/bin/ar")
ecee2147
DC
256 (string-append "--python=" python "/bin/python2")
257 (string-append "--local-rust-root=" rustc)
258 (string-append "--llvm-root=" llvm)
259 (string-append "--jemalloc-root=" jemalloc "/lib")
260 "--release-channel=stable"
261 "--enable-rpath"
262 "--enable-local-rust"
263 ;;"--enable-rustbuild"
264 "--disable-manage-submodules")))
265 ;; Rust uses a custom configure script (no autoconf).
5d18d776
DC
266 (zero? (apply system* "./configure" flags)))))
267 (add-after 'install 'wrap-rustc
268 (lambda* (#:key inputs outputs #:allow-other-keys)
269 (let ((out (assoc-ref outputs "out"))
270 (libc (assoc-ref inputs "libc"))
271 (ld-wrapper (assoc-ref inputs "ld-wrapper")))
272 ;; Let gcc find ld and libc startup files.
273 (wrap-program (string-append out "/bin/rustc")
274 `("PATH" ":" prefix (,(string-append ld-wrapper "/bin")))
275 `("LIBRARY_PATH" ":" suffix (,(string-append libc "/lib"))))))))))
fa73a7c1
BW
276 ;; rustc invokes gcc, so we need to set its search paths accordingly.
277 (native-search-paths (package-native-search-paths gcc))
ecee2147
DC
278 (synopsis "Compiler for the Rust progamming language")
279 (description "Rust is a systems programming language that provides memory
280safety and thread safety guarantees.")
281 (home-page "https://www.rust-lang.org")
282 ;; Dual licensed.
283 (license (list license:asl2.0 license:expat))))
b5a09649
DC
284
285(define-public cargo
286 (package
287 (name "cargo")
288 (version (cargo-version (rustc-version %rust-bootstrap-binaries-version)))
289 (source (origin
290 (method url-fetch)
291 ;; Use a cargo tarball with vendored dependencies and a cargo
292 ;; config file.
293 (uri (string-append
294 "https://github.com/dvc94ch/cargo"
295 "/archive/" version "-cargo-vendor.tar.gz"))
296 (file-name (string-append name "-" version ".tar.gz"))
297 (sha256
298 (base32
299 "0hpix5hwz10pm1wh65gimhsy9nxjvy7yikgbpw8afwglqr3bl856"))))
300 (build-system cargo-build-system)
301 (propagated-inputs
302 `(("cmake" ,cmake)
303 ("pkg-config" ,pkg-config)))
304 (inputs
305 `(("curl" ,curl)
306 ("libgit2" ,libgit2)
307 ("libssh2" ,libssh2)
308 ("openssl" ,openssl)
309 ("python-2" ,python-2)
310 ("zlib" ,zlib)))
311 (arguments
312 `(#:cargo ,cargo-bootstrap
313 #:tests? #f ; FIXME
314 #:phases
315 (modify-phases %standard-phases
316 ;; Avoid cargo complaining about missmatched checksums.
317 (delete 'patch-source-shebangs)
318 (delete 'patch-generated-file-shebangs)
319 (delete 'patch-usr-bin-file)
320 ;; Set CARGO_HOME to use the vendored dependencies.
321 (add-after 'unpack 'set-cargo-home
322 (lambda* (#:key inputs #:allow-other-keys)
323 (let* ((gcc (assoc-ref inputs "gcc"))
324 (cc (string-append gcc "/bin/gcc")))
325 (setenv "CARGO_HOME" (string-append (getcwd) "/cargohome"))
326 (setenv "CMAKE_C_COMPILER" cc)
327 (setenv "CC" cc))
328 #t)))))
329 (home-page "https://github.com/rust-lang/cargo")
330 (synopsis "Build tool and package manager for Rust")
331 (description "Cargo is a tool that allows Rust projects to declare their
332dependencies and ensures a reproducible build.")
333 ;; Cargo is dual licensed Apache and MIT. Also contains
334 ;; code from openssl which is GPL2 with linking exception.
335 (license (list license:asl2.0 license:expat license:gpl2))))