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