1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
| | ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016 Eric Le Bihan <eric.le.bihan.dev@free.fr>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (gnu packages rust)
#:use-module (ice-9 regex)
#:use-module ((guix licenses) #:select (asl2.0 x11-style))
#:use-module (guix packages)
#:use-module (guix download)
#:use-module (guix build-system gnu)
#:use-module (gnu packages base)
#:use-module (gnu packages bootstrap)
#:use-module (gnu packages curl)
#:use-module (gnu packages elf)
#:use-module (gnu packages gcc)
#:use-module (gnu packages jemalloc)
#:use-module (gnu packages perl)
#:use-module (gnu packages python))
(define rust-bootstrap-x86_64-1.9.0
(origin
(method url-fetch)
(uri
"https://static.rust-lang.org/dist/2016-05-24/rustc-1.9.0-x86_64-unknown-linux-gnu.tar.gz")
(sha256
(base32
"1i44rlvvn3pr81sli6bdbkzd78ar1ibybxx6mzpw6rkw4c84sw6h"))))
(define rust-bootstrap-i686-1.9.0
(origin
(method url-fetch)
(uri
"https://static.rust-lang.org/dist/2016-05-24/rustc-1.9.0-i686-unknown-linux-gnu.tar.gz")
(sha256
(base32
"0fdf5xvh3g4hdza0y80w1r9vnfczjqnbzbvs7k878yc26p4dwl99"))))
(define-public rust
(package
(name "rust")
(version "1.10.0")
(source (origin
(method url-fetch)
(uri (string-append "https://static.rust-lang.org/dist/rustc-"
version "-src.tar.gz"))
(sha256
(base32
"0sb82xb8y2pzs8l1hk91z228bambwx3dmi2kj8isin7nyjn5l0d4"))))
(build-system gnu-build-system)
(native-inputs
`(("curl" ,curl)
("gcc" ,gcc)
("gcc-lib" ,gcc "lib")
("jemalloc" ,jemalloc)
("patchelf" ,patchelf)
("perl" ,perl)
("python" ,python-2)
("rust-bootstrap"
,(if (string-match "x86_64" (or (%current-target-system) (%current-system)))
rust-bootstrap-x86_64-1.9.0
rust-bootstrap-i686-1.9.0))
("which" ,which)))
(arguments
`(#:phases
(modify-phases %standard-phases
(add-after 'unpack 'unpack-bootstrap
(lambda* (#:key inputs #:allow-other-keys)
(with-directory-excursion (getcwd)
(zero? (system*
"tar"
"--strip-components=1"
"-xzf"
(assoc-ref inputs "rust-bootstrap"))))))
(replace 'configure
(lambda* (#:key inputs outputs #:allow-other-keys)
(let ((out (assoc-ref outputs "out"))
(binutils (assoc-ref inputs "binutils"))
(gcc (assoc-ref inputs "gcc"))
(gcc-lib (assoc-ref inputs "gcc-lib"))
(jemalloc (assoc-ref inputs "jemalloc"))
(ld-so (string-append
(assoc-ref inputs "libc")
,(glibc-dynamic-linker)))
(python (assoc-ref inputs "python")))
(setenv "SHELL" (which "sh"))
(setenv "CONFIG_SHELL" (which "sh"))
;; Tell where to find libgcc_s.so
(setenv "LD_LIBRARY_PATH" (string-append gcc-lib "/lib"))
;; Remove reference to "/lib64/ld-linux-x86-64.so.2" from binary
(zero? (system*
"patchelf"
"--set-interpreter" ld-so
(string-append (getcwd) "/rustc/bin/rustc")))
(zero? (system*
"./configure"
(string-append "--prefix=" out)
(string-append "--default-linker=" gcc "/bin/gcc")
(string-append "--default-ar=" binutils "/bin/ar")
(string-append "--jemalloc-root=" jemalloc "/lib")
(string-append "--enable-rpath")
(string-append "--enable-local-rust")
(string-append "--local-rust-root=" (getcwd) "/rustc")
(string-append "--python=" python "/bin/python2")
"--disable-manage-submodules")))))
(add-before 'build 'pre-build
(lambda _
(let* ((bindir (string-append (getcwd) "/bin"))
(cc (string-append bindir "/cc")))
(mkdir bindir)
(call-with-output-file cc
(lambda (port)
(format port
"#!~a\n\nexec gcc \"$@\"\n" (which "sh"))))
(chmod cc #o755))))
(replace 'build
(lambda* (#:key outputs #:allow-other-keys)
(setenv "PATH"
(string-append (getcwd) "/bin:" (getenv "PATH")))
(mkdir (assoc-ref outputs "out"))
(zero? (system* "make")))))
#:tests? #f))
(synopsis "Compiler for the Rust progamming language")
(description
"Rust is a systems programming language that runs blazingly fast, prevents
segfaults, and guarantees thread safety.")
(home-page "https://www.rust-lang.org")
(license (list asl2.0 (x11-style "file://LICENSE-MIT")))))
|