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> |
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 | ||
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")) |
ecee2147 | 195 | (arguments |
d53fb678 | 196 | `(#:imported-modules ,%cargo-build-system-modules ;for `generate-checksums' |
3159ef7c | 197 | #:modules ((guix build utils) (ice-9 match) (guix build gnu-build-system)) |
d53fb678 | 198 | #:phases |
ecee2147 | 199 | (modify-phases %standard-phases |
ecee2147 | 200 | (add-after 'unpack 'set-env |
1bb23335 NM |
201 | (lambda* (#:key inputs #:allow-other-keys) |
202 | ;; Disable test for cross compilation support. | |
203 | (setenv "CFG_DISABLE_CROSS_TESTS" "1") | |
ecee2147 | 204 | (setenv "SHELL" (which "sh")) |
326249ba | 205 | (setenv "CONFIG_SHELL" (which "sh")) |
1bb23335 | 206 | (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc")) |
d53fb678 NM |
207 | ;; guix llvm-3.9.1 package installs only shared libraries |
208 | (setenv "LLVM_LINK_SHARED" "1") | |
326249ba | 209 | #t)) |
3159ef7c DM |
210 | (add-after 'unpack 'patch-cargo-tomls |
211 | (lambda* (#:key inputs outputs #:allow-other-keys) | |
212 | (substitute* "src/librustc_errors/Cargo.toml" | |
213 | (("[[]dependencies[]]") " | |
214 | [dependencies] | |
215 | term = \"0.4.4\" | |
216 | ")) | |
217 | (substitute* "src/librustc/Cargo.toml" | |
218 | (("[[]dependencies[]]") " | |
219 | [dependencies] | |
220 | getopts = { path = \"../libgetopts\" } | |
221 | ")) | |
222 | (substitute* "src/librustdoc/Cargo.toml" | |
223 | (("[[]dependencies[]]") " | |
224 | [dependencies] | |
225 | test = { path = \"../libtest\" } | |
226 | ")) | |
227 | #t)) | |
84aac61c DM |
228 | (add-after 'unpack 'patch-tests |
229 | (lambda* (#:key inputs #:allow-other-keys) | |
9b7a9580 | 230 | (let ((bash (assoc-ref inputs "bash"))) |
9b7a9580 | 231 | (substitute* "src/libstd/process.rs" |
5f3d46ce DM |
232 | ;; The newline is intentional. |
233 | ;; There's a line length "tidy" check in Rust which would | |
234 | ;; fail otherwise. | |
d53fb678 NM |
235 | (("\"/bin/sh\"") (string-append "\n\"" bash "/bin/sh\""))) |
236 | (substitute* "src/libstd/net/tcp.rs" | |
237 | ;; There is no network in build environment | |
238 | (("fn connect_timeout_unroutable") | |
239 | "#[ignore]\nfn connect_timeout_unroutable")) | |
240 | ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00222.html> | |
5f3d46ce | 241 | (substitute* "src/libstd/sys/unix/process/process_common.rs" |
237587f1 DM |
242 | (("fn test_process_mask") "#[allow(unused_attributes)] |
243 | #[ignore] | |
af4ea9c5 | 244 | fn test_process_mask")) |
9b7a9580 | 245 | #t))) |
b47b2d32 NM |
246 | (add-after 'patch-tests 'patch-aarch64-test |
247 | (lambda* _ | |
248 | (substitute* "src/librustc_back/dynamic_lib.rs" | |
249 | ;; This test is known to fail on aarch64 and powerpc64le: | |
250 | ;; https://github.com/rust-lang/rust/issues/45410 | |
251 | (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine")) | |
252 | #t)) | |
253 | (add-after 'patch-tests 'use-readelf-for-tests | |
254 | (lambda* _ | |
255 | ;; nm doesn't recognize the file format because of the | |
256 | ;; nonstandard sections used by the Rust compiler, but readelf | |
257 | ;; ignores them. | |
258 | (substitute* "src/test/run-make/atomic-lock-free/Makefile" | |
259 | (("\tnm ") | |
260 | "\treadelf -c ")) | |
261 | #t)) | |
262 | (add-after 'patch-tests 'remove-unsupported-tests | |
263 | (lambda* _ | |
264 | ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH. | |
265 | ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html> | |
266 | (delete-file-recursively "src/test/run-make/linker-output-non-utf8") | |
267 | #t)) | |
d53fb678 | 268 | (add-after 'patch-source-shebangs 'patch-cargo-checksums |
f342bb58 | 269 | (lambda* _ |
d53fb678 NM |
270 | (substitute* "src/Cargo.lock" |
271 | (("(\"checksum .* = )\".*\"" all name) | |
272 | (string-append name "\"" ,%cargo-reference-hash "\""))) | |
273 | (for-each | |
274 | (lambda (filename) | |
275 | (use-modules (guix build cargo-build-system)) | |
276 | (delete-file filename) | |
277 | (let* ((dir (dirname filename))) | |
278 | (display (string-append | |
279 | "patch-cargo-checksums: generate-checksums for " | |
280 | dir "\n")) | |
281 | (generate-checksums dir ,%cargo-reference-project-file))) | |
282 | (find-files "src/vendor" ".cargo-checksum.json")) | |
283 | #t)) | |
3159ef7c | 284 | ;; This phase is overridden by newer versions. |
ecee2147 | 285 | (replace 'configure |
8fdde581 | 286 | (const #t)) |
3159ef7c DM |
287 | ;; This phase is overridden by newer versions. |
288 | (replace 'build | |
289 | (lambda* (#:key inputs outputs #:allow-other-keys) | |
290 | (let ((rustc-bootstrap (assoc-ref inputs "rustc-bootstrap"))) | |
291 | (setenv "CFG_COMPILER_HOST_TRIPLE" | |
292 | ,(nix-system->gnu-triplet (%current-system))) | |
293 | (setenv "CFG_RELEASE" "") | |
294 | (setenv "CFG_RELEASE_CHANNEL" "stable") | |
295 | (setenv "CFG_LIBDIR_RELATIVE" "lib") | |
296 | (setenv "CFG_VERSION" "1.19.0-stable-mrustc") | |
297 | ; bad: (setenv "CFG_PREFIX" "mrustc") ; FIXME output path. | |
298 | (mkdir-p "output") | |
299 | (invoke (string-append rustc-bootstrap "/tools/bin/minicargo") | |
300 | "src/rustc" "--vendor-dir" "src/vendor" | |
301 | "--output-dir" "output/rustc-build" | |
302 | "-L" (string-append rustc-bootstrap "/lib/mrust") | |
303 | "-j" "1") | |
3159ef7c DM |
304 | (setenv "CFG_COMPILER_HOST_TRIPLE" #f) |
305 | (setenv "CFG_RELEASE" #f) | |
306 | (setenv "CFG_RELEASE_CHANNEL" #f) | |
307 | (setenv "CFG_VERSION" #f) | |
308 | (setenv "CFG_PREFIX" #f) | |
309 | (setenv "CFG_LIBDIR_RELATIVE" #f) | |
310 | (invoke (string-append rustc-bootstrap "/tools/bin/minicargo") | |
311 | "src/tools/cargo" "--vendor-dir" "src/vendor" | |
312 | "--output-dir" "output/cargo-build" | |
313 | "-L" "output/" | |
314 | "-L" (string-append rustc-bootstrap "/lib/mrust") | |
315 | "-j" "1") | |
316 | ;; Now use the newly-built rustc to build the libraries. | |
317 | ;; One day that could be replaced by: | |
318 | ;; (invoke "output/cargo-build/cargo" "build" | |
319 | ;; "--manifest-path" "src/bootstrap/Cargo.toml" | |
320 | ;; "--verbose") ; "--locked" "--frozen" | |
321 | ;; but right now, Cargo has problems with libstd's circular | |
322 | ;; dependencies. | |
323 | (mkdir-p "output/target-libs") | |
0bcd1bc7 | 324 | (for-each (match-lambda |
3159ef7c DM |
325 | ((name . flags) |
326 | (write name) | |
327 | (newline) | |
328 | (apply invoke | |
329 | "output/rustc-build/rustc" | |
330 | "-C" (string-append "linker=" | |
331 | (getenv "CC")) | |
6c1a6584 DM |
332 | ;; Required for libterm. |
333 | "-Z" "force-unstable-if-unmarked" | |
3159ef7c DM |
334 | "-L" "output/target-libs" |
335 | (string-append "src/" name "/lib.rs") | |
336 | "-o" | |
337 | (string-append "output/target-libs/" | |
338 | (car (string-split name #\/)) | |
339 | ".rlib") | |
340 | flags))) | |
341 | '(("libcore") | |
342 | ("libstd_unicode") | |
343 | ("liballoc") | |
344 | ("libcollections") | |
345 | ("librand") | |
346 | ("liblibc/src" "--cfg" "stdbuild") | |
347 | ("libunwind" "-l" "gcc_s") | |
348 | ("libcompiler_builtins") | |
349 | ("liballoc_system") | |
350 | ("libpanic_unwind") | |
351 | ;; Uses "cc" to link. | |
352 | ("libstd" "-l" "dl" "-l" "rt" "-l" "pthread") | |
6c1a6584 DM |
353 | ("libarena") |
354 | ||
355 | ;; Test dependencies: | |
356 | ||
357 | ("libgetopts") | |
358 | ("libterm") | |
359 | ("libtest"))) | |
3159ef7c DM |
360 | #t))) |
361 | ;; This phase is overridden by newer versions. | |
8fdde581 DM |
362 | (replace 'check |
363 | (const #t)) | |
3159ef7c | 364 | ;; This phase is overridden by newer versions. |
8fdde581 | 365 | (replace 'install |
3159ef7c DM |
366 | (lambda* (#:key inputs outputs #:allow-other-keys) |
367 | (let* ((out (assoc-ref outputs "out")) | |
368 | (target-system ,(or (%current-target-system) | |
369 | (nix-system->gnu-triplet | |
370 | (%current-system)))) | |
371 | (out-libs (string-append out "/lib/rustlib/" | |
372 | target-system "/lib"))) | |
373 | ;(setenv "CFG_PREFIX" out) | |
374 | (mkdir-p out-libs) | |
375 | (copy-recursively "output/target-libs" out-libs) | |
376 | (install-file "output/rustc-build/rustc" | |
377 | (string-append out "/bin")) | |
5a3fcf5b DM |
378 | (install-file "output/rustc-build/rustdoc" |
379 | (string-append out "/bin")) | |
3159ef7c DM |
380 | (install-file "output/cargo-build/cargo" |
381 | (string-append (assoc-ref outputs "cargo") | |
382 | "/bin"))) | |
383 | #t))))) | |
8fdde581 DM |
384 | (build-system gnu-build-system) |
385 | (native-inputs | |
386 | `(("bison" ,bison) ; For the tests | |
387 | ("cmake" ,cmake) | |
388 | ("flex" ,flex) ; For the tests | |
389 | ("gdb" ,gdb) ; For the tests | |
390 | ("git" ,git) | |
391 | ("procps" ,procps) ; For the tests | |
392 | ("python-2" ,python-2) | |
3159ef7c DM |
393 | ("rustc-bootstrap" ,mrustc) |
394 | ("cargo-bootstrap" ,mrustc "cargo") | |
8fdde581 DM |
395 | ("pkg-config" ,pkg-config) ; For "cargo" |
396 | ("which" ,which))) | |
397 | (inputs | |
398 | `(("jemalloc" ,jemalloc-4.5.0) | |
399 | ("llvm" ,llvm-3.9.1) | |
400 | ("openssl" ,openssl) | |
e027a494 NM |
401 | ("libssh2" ,libssh2) ; For "cargo" |
402 | ("libcurl" ,curl))) ; For "cargo" | |
afc2bf53 | 403 | |
8fdde581 | 404 | ;; rustc invokes gcc, so we need to set its search paths accordingly. |
afc2bf53 LC |
405 | ;; Note: duplicate its value here to cope with circular dependencies among |
406 | ;; modules (see <https://bugs.gnu.org/31392>). | |
407 | (native-search-paths | |
408 | (list (search-path-specification | |
409 | (variable "C_INCLUDE_PATH") | |
410 | (files '("include"))) | |
411 | (search-path-specification | |
412 | (variable "CPLUS_INCLUDE_PATH") | |
413 | (files '("include"))) | |
414 | (search-path-specification | |
415 | (variable "LIBRARY_PATH") | |
416 | (files '("lib" "lib64"))))) | |
417 | ||
8fdde581 DM |
418 | (synopsis "Compiler for the Rust progamming language") |
419 | (description "Rust is a systems programming language that provides memory | |
420 | safety and thread safety guarantees.") | |
421 | (home-page "https://www.rust-lang.org") | |
422 | ;; Dual licensed. | |
423 | (license (list license:asl2.0 license:expat)))) | |
424 | ||
614cfd5c DM |
425 | (define-public rust-1.20 |
426 | (let ((base-rust | |
427 | (rust-bootstrapped-package rust-1.19 "1.20.0" | |
428 | "0542y4rnzlsrricai130mqyxl8r6rd991frb4qsnwb27yigqg91a"))) | |
429 | (package | |
430 | (inherit base-rust) | |
431 | (outputs '("out" "doc" "cargo")) | |
432 | (arguments | |
433 | (substitute-keyword-arguments (package-arguments rust-1.19) | |
434 | ((#:phases phases) | |
435 | `(modify-phases ,phases | |
1bfaae25 DM |
436 | (add-after 'patch-tests 'patch-cargo-tests |
437 | (lambda _ | |
438 | (substitute* "src/tools/cargo/tests/build.rs" | |
439 | (("/usr/bin/env") (which "env")) | |
440 | ;; Guix llvm is compiled without asmjs-unknown-emscripten. | |
441 | (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs")) | |
442 | (substitute* "src/tools/cargo/tests/death.rs" | |
443 | ;; This is stuck when built in container. | |
444 | (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone")) | |
445 | ;; Prints test output in the wrong order when built on | |
446 | ;; i686-linux. | |
447 | (substitute* "src/tools/cargo/tests/test.rs" | |
448 | (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env")) | |
449 | #t)) | |
450 | (add-after 'patch-cargo-tests 'ignore-glibc-2.27-incompatible-test | |
451 | ;; https://github.com/rust-lang/rust/issues/47863 | |
452 | (lambda _ | |
453 | (substitute* "src/test/run-pass/out-of-stack.rs" | |
454 | (("// ignore-android") "// ignore-test\n// ignore-android")) | |
455 | #t)) | |
614cfd5c DM |
456 | (replace 'configure |
457 | (lambda* (#:key inputs outputs #:allow-other-keys) | |
458 | (let* ((out (assoc-ref outputs "out")) | |
459 | (doc (assoc-ref outputs "doc")) | |
460 | (gcc (assoc-ref inputs "gcc")) | |
461 | (gdb (assoc-ref inputs "gdb")) | |
462 | (binutils (assoc-ref inputs "binutils")) | |
463 | (python (assoc-ref inputs "python-2")) | |
464 | (rustc (assoc-ref inputs "rustc-bootstrap")) | |
465 | (cargo (assoc-ref inputs "cargo-bootstrap")) | |
466 | (llvm (assoc-ref inputs "llvm")) | |
467 | (jemalloc (assoc-ref inputs "jemalloc"))) | |
468 | (call-with-output-file "config.toml" | |
469 | (lambda (port) | |
470 | (display (string-append " | |
471 | [llvm] | |
472 | [build] | |
473 | cargo = \"" cargo "/bin/cargo" "\" | |
474 | rustc = \"" rustc "/bin/rustc" "\" | |
475 | docs = true | |
476 | python = \"" python "/bin/python2" "\" | |
477 | gdb = \"" gdb "/bin/gdb" "\" | |
478 | vendor = true | |
479 | submodules = false | |
480 | [install] | |
481 | prefix = \"" out "\" | |
482 | docdir = \"" doc "/share/doc/rust" "\" | |
483 | sysconfdir = \"etc\" | |
614cfd5c DM |
484 | [rust] |
485 | default-linker = \"" gcc "/bin/gcc" "\" | |
614cfd5c DM |
486 | channel = \"stable\" |
487 | rpath = true | |
488 | " ;; There are 2 failed codegen tests: | |
489 | ;; codegen/mainsubprogram.rs and codegen/mainsubprogramstart.rs | |
490 | ;; These tests require a patched LLVM | |
491 | "codegen-tests = false | |
492 | [target." ,(nix-system->gnu-triplet-for-rust) "] | |
493 | llvm-config = \"" llvm "/bin/llvm-config" "\" | |
494 | cc = \"" gcc "/bin/gcc" "\" | |
495 | cxx = \"" gcc "/bin/g++" "\" | |
91294b53 | 496 | ar = \"" binutils "/bin/ar" "\" |
614cfd5c DM |
497 | jemalloc = \"" jemalloc "/lib/libjemalloc_pic.a" "\" |
498 | [dist] | |
499 | ") port))) | |
500 | #t))) | |
501 | (add-after 'configure 'provide-cc | |
502 | (lambda* (#:key inputs #:allow-other-keys) | |
503 | (symlink (string-append (assoc-ref inputs "gcc") "/bin/gcc") | |
504 | "/tmp/cc") | |
505 | (setenv "PATH" (string-append "/tmp:" (getenv "PATH"))) | |
506 | #t)) | |
507 | (add-after 'provide-cc 'configure-archiver | |
508 | (lambda* (#:key inputs #:allow-other-keys) | |
509 | (substitute* "src/build_helper/lib.rs" | |
510 | ;; Make sure "ar" is always used as the archiver. | |
511 | (("\"musl\"") "\"\"") | |
512 | ;; Then substitute "ar" by our name. | |
513 | (("\"ar\"") (string-append "\"" | |
514 | (assoc-ref inputs "binutils") | |
515 | "/bin/ar\""))) | |
516 | #t)) | |
517 | (delete 'patch-cargo-tomls) | |
518 | (add-before 'build 'reset-timestamps-after-changes | |
519 | (lambda* _ | |
614cfd5c DM |
520 | (for-each |
521 | (lambda (filename) | |
e0b07ccc DM |
522 | ;; Rust 1.20.0 treats timestamp 0 as "file doesn't exist". |
523 | ;; Therefore, use timestamp 1. | |
524 | (utime filename 1 1 1 1)) | |
614cfd5c DM |
525 | (find-files "." #:directories? #t)) |
526 | #t)) | |
527 | (replace 'build | |
528 | (lambda* _ | |
529 | (invoke "./x.py" "build") | |
530 | (invoke "./x.py" "build" "src/tools/cargo"))) | |
531 | (replace 'check | |
532 | (lambda* _ | |
533 | ;; Disable parallel execution to prevent EAGAIN errors when | |
534 | ;; running tests. | |
535 | (invoke "./x.py" "-j1" "test" "-vv") | |
536 | (invoke "./x.py" "-j1" "test" "src/tools/cargo") | |
537 | #t)) | |
538 | (replace 'install | |
539 | (lambda* (#:key outputs #:allow-other-keys) | |
540 | (invoke "./x.py" "install") | |
541 | (substitute* "config.toml" | |
542 | ;; replace prefix to specific output | |
543 | (("prefix = \"[^\"]*\"") | |
544 | (string-append "prefix = \"" (assoc-ref outputs "cargo") "\""))) | |
545 | (invoke "./x.py" "install" "cargo"))) | |
546 | (add-after 'install 'wrap-rustc | |
547 | (lambda* (#:key inputs outputs #:allow-other-keys) | |
548 | (let ((out (assoc-ref outputs "out")) | |
549 | (libc (assoc-ref inputs "libc")) | |
550 | (ld-wrapper (assoc-ref inputs "ld-wrapper"))) | |
551 | ;; Let gcc find ld and libc startup files. | |
552 | (wrap-program (string-append out "/bin/rustc") | |
553 | `("PATH" ":" prefix (,(string-append ld-wrapper "/bin"))) | |
554 | `("LIBRARY_PATH" ":" suffix (,(string-append libc "/lib")))) | |
555 | #t)))))))))) | |
556 | ||
05ebff92 | 557 | (define-public rust-1.21 |
7bf169f7 DM |
558 | (let ((base-rust (rust-bootstrapped-package rust-1.20 "1.21.0" |
559 | "1yj8lnxybjrybp00fqhxw8fpr641dh8wcn9mk44xjnsb4i1c21qp"))) | |
560 | (package | |
561 | (inherit base-rust) | |
562 | (arguments | |
563 | (substitute-keyword-arguments (package-arguments base-rust) | |
564 | ((#:phases phases) | |
565 | `(modify-phases ,phases | |
566 | (add-after 'configure 'remove-ar | |
567 | (lambda* (#:key inputs #:allow-other-keys) | |
568 | ;; Remove because toml complains about "unknown field". | |
569 | (substitute* "config.toml" | |
570 | (("^ar =.*") "\n")) | |
571 | #t))))))))) | |
05ebff92 | 572 | |
1ab3e1dd DM |
573 | (define-public rust-1.22 |
574 | (rust-bootstrapped-package rust-1.21 "1.22.1" | |
575 | "1lrzzp0nh7s61wgfs2h6ilaqi6iq89f1pd1yaf65l87bssyl4ylb")) | |
576 | ||
8fdde581 | 577 | (define-public rust-1.23 |
44d530ef DM |
578 | (let ((base-rust (rust-bootstrapped-package rust-1.22 "1.23.0" |
579 | "14fb8vhjzsxlbi6yrn1r6fl5dlbdd1m92dn5zj5gmzfwf4w9ar3l"))) | |
580 | (package | |
581 | (inherit base-rust) | |
582 | (arguments | |
583 | (substitute-keyword-arguments (package-arguments base-rust) | |
584 | ((#:phases phases) | |
585 | `(modify-phases ,phases | |
586 | (delete 'configure-archiver) | |
587 | (delete 'remove-ar) | |
588 | (add-after 'unpack 'dont-build-native | |
589 | (lambda _ | |
590 | ;; XXX: Revisit this when we use gcc 6. | |
591 | (substitute* "src/binaryen/CMakeLists.txt" | |
592 | (("ADD_COMPILE_FLAG\\(\\\"-march=native\\\"\\)") "")) | |
593 | #t))))))))) | |
b5a09649 | 594 | |
fe61c88a | 595 | (define-public rust-1.24 |
ca523cc5 DM |
596 | (let ((base-rust |
597 | (rust-bootstrapped-package rust-1.23 "1.24.1" | |
598 | "1vv10x2h9kq7fxh2v01damdq8pvlp5acyh1kzcda9sfjx12kv99y"))) | |
f342bb58 NM |
599 | (package |
600 | (inherit base-rust) | |
f342bb58 NM |
601 | (arguments |
602 | (substitute-keyword-arguments (package-arguments base-rust) | |
ca523cc5 DM |
603 | ((#:phases phases) |
604 | `(modify-phases ,phases | |
b47b2d32 NM |
605 | (delete 'use-readelf-for-tests) |
606 | (replace 'patch-aarch64-test | |
607 | (lambda* _ | |
608 | (substitute* "src/librustc_metadata/dynamic_lib.rs" | |
609 | ;; This test is known to fail on aarch64 and powerpc64le: | |
610 | ;; https://github.com/rust-lang/rust/issues/45410 | |
611 | (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine")) | |
e0b07ccc | 612 | #t))))))))) |
fe61c88a | 613 | |
e027a494 NM |
614 | ;;; Rust 1.25 release support work with llvm 6--but build with llvm 6 is |
615 | ;;; not determenistic due to <https://github.com/rust-lang/rust/issues/50556>. | |
616 | ;;; Keep using llvm 3.9.1 until builds become determenistic | |
b47b2d32 NM |
617 | (define-public rust-1.25 |
618 | (let ((base-rust | |
619 | (rust-bootstrapped-package rust-1.24 "1.25.0" | |
6fe73b48 DM |
620 | "0baxjr99311lvwdq0s38bipbnj72pn6fgbk6lcq7j555xq53mxpf" |
621 | #:patches '("rust-1.25-accept-more-detailed-gdb-lines.patch")))) | |
fe61c88a NM |
622 | (package |
623 | (inherit base-rust) | |
fe61c88a NM |
624 | (arguments |
625 | (substitute-keyword-arguments (package-arguments base-rust) | |
626 | ((#:phases phases) | |
627 | `(modify-phases ,phases | |
628 | (add-after 'patch-cargo-tests 'patch-cargo-index-update | |
080e11b4 | 629 | (lambda _ |
fe61c88a NM |
630 | (substitute* "src/tools/cargo/tests/generate-lockfile.rs" |
631 | ;; This test wants to update the crate index. | |
080e11b4 EF |
632 | (("fn no_index_update") "#[ignore]\nfn no_index_update")) |
633 | #t)) | |
080e11b4 EF |
634 | (replace 'patch-aarch64-test |
635 | (lambda _ | |
636 | (substitute* "src/librustc_metadata/dynamic_lib.rs" | |
637 | ;; This test is known to fail on aarch64 and powerpc64le: | |
638 | ;; https://github.com/rust-lang/rust/issues/45410 | |
639 | (("fn test_loading_cosine") "#[ignore]\nfn test_loading_cosine")) | |
640 | ;; This test fails on aarch64 with llvm@6.0: | |
641 | ;; https://github.com/rust-lang/rust/issues/49807 | |
642 | ;; other possible solution: | |
643 | ;; https://github.com/rust-lang/rust/pull/47688 | |
644 | (delete-file "src/test/debuginfo/by-value-self-argument-in-trait-impl.rs") | |
645 | #t)) | |
b47b2d32 NM |
646 | (delete 'ignore-glibc-2.27-incompatible-test)))))))) |
647 | ||
f510a2b9 | 648 | (define-public rust-1.26 |
b47b2d32 NM |
649 | (let ((base-rust |
650 | (rust-bootstrapped-package rust-1.25 "1.26.2" | |
6fe73b48 DM |
651 | "0047ais0fvmqvngqkdsxgrzhb0kljg8wy85b01kbbjc88hqcz7pv" |
652 | #:patches '("rust-coresimd-doctest.patch" | |
653 | "rust-1.25-accept-more-detailed-gdb-lines.patch")))) | |
b47b2d32 NM |
654 | (package |
655 | (inherit base-rust) | |
656 | (arguments | |
657 | (substitute-keyword-arguments (package-arguments base-rust) | |
658 | ((#:phases phases) | |
659 | `(modify-phases ,phases | |
660 | ;; binaryen was replaced with LLD project from LLVM | |
661 | (delete 'dont-build-native) | |
662 | (replace 'remove-unsupported-tests | |
663 | (lambda* _ | |
664 | ;; Our ld-wrapper cannot process non-UTF8 bytes in LIBRARY_PATH. | |
665 | ;; <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00193.html> | |
666 | (delete-file-recursively "src/test/run-make-fulldeps/linker-output-non-utf8") | |
667 | #t)) | |
668 | (replace 'patch-cargo-tests | |
669 | (lambda* _ | |
670 | (substitute* "src/tools/cargo/tests/testsuite/build.rs" | |
671 | (("/usr/bin/env") (which "env")) | |
672 | ;; Guix llvm is compiled without asmjs-unknown-emscripten. | |
673 | (("fn wasm32_final_outputs") "#[ignore]\nfn wasm32_final_outputs")) | |
674 | (substitute* "src/tools/cargo/tests/testsuite/death.rs" | |
675 | ;; This is stuck when built in container. | |
676 | (("fn ctrl_c_kills_everyone") "#[ignore]\nfn ctrl_c_kills_everyone")) | |
677 | ;; Prints test output in the wrong order when built on | |
678 | ;; i686-linux. | |
679 | (substitute* "src/tools/cargo/tests/testsuite/test.rs" | |
680 | (("fn cargo_test_env") "#[ignore]\nfn cargo_test_env")) | |
681 | #t)) | |
682 | (add-after 'patch-cargo-tests 'disable-cargo-test-for-nightly-channel | |
683 | (lambda* _ | |
684 | ;; This test failed to work on "nightly" channel builds | |
685 | ;; https://github.com/rust-lang/cargo/issues/5648 | |
686 | (substitute* "src/tools/cargo/tests/testsuite/resolve.rs" | |
687 | (("fn test_resolving_minimum_version_with_transitive_deps") | |
688 | "#[ignore]\nfn test_resolving_minimum_version_with_transitive_deps")) | |
689 | #t)) | |
690 | (replace 'patch-cargo-index-update | |
691 | (lambda* _ | |
692 | (substitute* "src/tools/cargo/tests/testsuite/generate_lockfile.rs" | |
693 | ;; This test wants to update the crate index. | |
694 | (("fn no_index_update") "#[ignore]\nfn no_index_update")) | |
695 | #t))))))))) | |
f510a2b9 | 696 | |
2e2b8635 | 697 | (define-public rust-1.27 |
f510a2b9 | 698 | (let ((base-rust |
317b139c DM |
699 | (rust-bootstrapped-package rust-1.26 "1.27.2" |
700 | "0pg1s37bhx9zqbynxyydq5j6q7kij9vxkcv8maz0m25prm88r0cs" | |
f510a2b9 NM |
701 | #:patches |
702 | '("rust-coresimd-doctest.patch" | |
6fe73b48 | 703 | "rust-bootstrap-stage0-test.patch" |
e027a494 NM |
704 | "rust-1.25-accept-more-detailed-gdb-lines.patch" |
705 | "rust-mdbook-support-reproducible-builds-by-forcing-window.search.patch")))) | |
f510a2b9 NM |
706 | (package |
707 | (inherit base-rust) | |
708 | (arguments | |
709 | (substitute-keyword-arguments (package-arguments base-rust) | |
710 | ((#:phases phases) | |
711 | `(modify-phases ,phases | |
712 | (add-before 'install 'mkdir-prefix-paths | |
713 | (lambda* (#:key outputs #:allow-other-keys) | |
714 | ;; As result of https://github.com/rust-lang/rust/issues/36989 | |
715 | ;; `prefix' directory should exist before `install' call | |
716 | (mkdir-p (assoc-ref outputs "out")) | |
717 | (mkdir-p (assoc-ref outputs "cargo")) | |
e027a494 NM |
718 | #t)) |
719 | (add-after 'patch-cargo-tests 'disable-thinlto-test | |
720 | (lambda* _ | |
721 | ;; thinlto required llvm 6.0 for work | |
722 | (substitute* "src/tools/cargo/tests/testsuite/path.rs" | |
723 | (("fn thin_lto_works") "#[ignore]\nfn thin_lto_works")) | |
f510a2b9 | 724 | #t))))))))) |
2e2b8635 NM |
725 | |
726 | (define-public rust | |
727 | (let ((base-rust | |
728 | (rust-bootstrapped-package rust-1.27 "1.28.0" | |
729 | "11k4rn77bca2rikykkk9fmprrgjswd4x4kaq7fia08vgkir82nhx" | |
730 | #:patches | |
731 | '("rust-coresimd-doctest.patch" | |
732 | "rust-bootstrap-stage0-test.patch" | |
733 | "rust-1.25-accept-more-detailed-gdb-lines.patch" | |
734 | "rust-mdbook-support-reproducible-builds-by-forcing-window.search.patch")))) | |
735 | (package | |
736 | (inherit base-rust) | |
737 | (inputs | |
738 | ;; Use LLVM 6.0 | |
739 | (alist-replace "llvm" (list llvm) | |
740 | (package-inputs base-rust))) | |
741 | (arguments | |
742 | (substitute-keyword-arguments (package-arguments base-rust) | |
743 | ((#:phases phases) | |
744 | `(modify-phases ,phases | |
745 | (add-after 'configure 'enable-codegen-tests | |
746 | ;; Codegen tests should pass with llvm 6, so enable them. | |
747 | (lambda* _ | |
748 | (substitute* "config.toml" | |
749 | (("codegen-tests = false") "")) | |
750 | #t)) | |
751 | (add-after 'patch-tests 'disable-amd64-avx-test | |
752 | ;; That test would fail on x86_64 machines without avx. | |
753 | (lambda* _ | |
754 | (substitute* "src/test/run-pass/issue-44056.rs" | |
755 | (("only-x86_64") "ignore-test")) | |
756 | #t)) | |
757 | ;; The thinlto test should pass with llvm 6. | |
758 | (delete 'disable-thinlto-test)))))))) |