summaryrefslogtreecommitdiff
path: root/gnu/packages/rust.scm
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/packages/rust.scm')
-rw-r--r--gnu/packages/rust.scm189
1 files changed, 184 insertions, 5 deletions
diff --git a/gnu/packages/rust.scm b/gnu/packages/rust.scm
index 67ce9c57d6c..8dd3f2eb0ac 100644
--- a/gnu/packages/rust.scm
+++ b/gnu/packages/rust.scm
@@ -157,9 +157,9 @@
157 ;; Don't use the vendored openssl sources. 157 ;; Don't use the vendored openssl sources.
158 (("--features vendored-openssl") ""))))))) 158 (("--features vendored-openssl") "")))))))
159 159
160;;; Rust 1.54 is special in that it is built with mrustc, which shortens the 160;;; The rust-bootstrap packages are special in that they are built with mrustc,
161;;; bootstrap path. 161;;; which shortens the bootstrap path.
162(define-public rust-bootstrap 162(define-public rust-bootstrap-1.54
163 (package 163 (package
164 (name "rust") 164 (name "rust")
165 (version "1.54.0") 165 (version "1.54.0")
@@ -341,6 +341,185 @@ safety and thread safety guarantees.")
341 ;; Dual licensed. 341 ;; Dual licensed.
342 (license (list license:asl2.0 license:expat)))) 342 (license (list license:asl2.0 license:expat))))
343 343
344(define-public rust-bootstrap-1.74
345 (package
346 (name "rust")
347 (version "1.74.0")
348 (source
349 (origin
350 (method url-fetch)
351 (uri (rust-uri version))
352 (sha256 (base32 "0j8hrwjjjjf7spy0hy7gami96swhfzr6kandfzzdri91qd5mhaw8"))
353 (modules '((guix build utils)))
354 (snippet
355 '(begin
356 (for-each delete-file-recursively
357 '("src/llvm-project"
358 "vendor/openssl-src/openssl"
359 "vendor/tikv-jemalloc-sys/jemalloc"))
360 ;; Remove vendored dynamically linked libraries.
361 ;; find . -not -type d -executable -exec file {} \+ | grep ELF
362 ;; Also remove the bundled (mostly Windows) libraries.
363 (for-each delete-file
364 (find-files "vendor" "\\.(a|dll|exe|lib)$"))
365 ;; Adjust vendored dependency to explicitly use rustix with libc backend.
366 (substitute* "vendor/tempfile/Cargo.toml"
367 (("features = \\[\"fs\"" all)
368 (string-append all ", \"use-libc\"")))))
369 ;; Rust 1.70 adds the rustix library which depends on the vendored
370 ;; fd-lock crate. The fd-lock crate uses Outline assembly which expects
371 ;; a precompiled static library. Enabling the "cc" feature tells the
372 ;; build.rs script to compile the assembly files instead of searching
373 ;; for a precompiled library.
374 (patches (search-patches "rust-1.70-fix-rustix-build.patch"))))
375 (outputs '("out" "cargo"))
376 (properties '((hidden? . #t)
377 (timeout . 129600) ;36 hours
378 (max-silent-time . 18000))) ;5 hours (for riscv64)
379 (build-system gnu-build-system)
380 (inputs
381 (list bash-minimal
382 llvm-17
383 openssl
384 zlib))
385 (native-inputs
386 (list pkg-config %mrustc-source))
387 (arguments
388 (list
389 #:imported-modules %cargo-utils-modules ;for `generate-all-checksums'
390 #:modules '((guix build cargo-utils)
391 (guix build utils)
392 (guix build gnu-build-system))
393 #:test-target "test"
394 ;; Rust's own .so library files are not found in any RUNPATH, but
395 ;; that doesn't seem to cause issues.
396 #:validate-runpath? #f
397 #:make-flags
398 #~(let ((source #$(package-source this-package)))
399 (list (string-append "RUSTC_TARGET="
400 #$(platform-rust-target
401 (lookup-platform-by-target-or-system
402 (or (%current-target-system)
403 (%current-system)))))
404 (string-append "RUSTC_VERSION=" #$version)
405 (string-append "MRUSTC_TARGET_VER="
406 #$(version-major+minor version))
407 (string-append "RUSTC_SRC_TARBALL=" source)
408 "OUTDIR_SUF=")) ;do not add version suffix to output dir
409 #:phases
410 #~(modify-phases %standard-phases
411 (replace 'unpack
412 (lambda* (#:key source inputs #:allow-other-keys)
413 ((assoc-ref %standard-phases 'unpack)
414 #:source #$(this-package-native-input
415 (origin-file-name %mrustc-source)))))
416 (add-after 'unpack 'patch-makefiles
417 ;; This disables building the (unbundled) LLVM.
418 (lambda* (#:key inputs #:allow-other-keys)
419 (substitute* '("minicargo.mk"
420 "run_rustc/Makefile")
421 ;; Use the system-provided LLVM.
422 (("LLVM_CONFIG [:|?]= .*")
423 (string-append "LLVM_CONFIG := "
424 (search-input-file inputs "/bin/llvm-config") "\n")))
425 (substitute* "Makefile"
426 ;; Patch date and git obtained version information.
427 ((" -D VERSION_GIT_FULLHASH=.*")
428 (string-append
429 " -D VERSION_GIT_FULLHASH=\\\"" #$%mrustc-commit "\\\""
430 " -D VERSION_GIT_BRANCH=\\\"master\\\""
431 " -D VERSION_GIT_SHORTHASH=\\\""
432 #$(string-take %mrustc-commit 7) "\\\""
433 " -D VERSION_BUILDTIME="
434 "\"\\\"Thu, 01 Jan 1970 00:00:01 +0000\\\"\""
435 " -D VERSION_GIT_ISDIRTY=0\n")))
436 (substitute* '("run_rustc/Makefile"
437 "run_rustc/rustc_proxy.sh")
438 ;; Patch the shebang of a generated wrapper for rustc
439 (("#!/bin/sh")
440 (string-append "#!" (which "sh"))))))
441 (add-before 'configure 'configure-cargo-home
442 (lambda _
443 (let ((cargo-home (string-append (getcwd) "/.cargo")))
444 (mkdir-p cargo-home)
445 (setenv "CARGO_HOME" cargo-home))))
446 (replace 'configure
447 (lambda _
448 (setenv "CC" "gcc")
449 (setenv "CXX" "g++")
450 ;; The Guix LLVM package installs only shared libraries.
451 (setenv "LLVM_LINK_SHARED" "1")
452 ;; rustc still insists on having 'cc' on PATH in some places
453 ;; (e.g. when building the 'test' library crate).
454 (mkdir-p "/tmp/bin")
455 (symlink (which "gcc") "/tmp/bin/cc")
456 (setenv "PATH" (string-append "/tmp/bin:" (getenv "PATH")))))
457 (delete 'patch-generated-file-shebangs)
458 (replace 'build
459 (lambda* (#:key make-flags parallel-build? #:allow-other-keys)
460 (let ((job-count (if parallel-build?
461 (parallel-job-count)
462 1)))
463 ;; Adapted from:
464 ;; https://github.com/dtolnay/bootstrap/blob/master/build-1.54.0.sh.
465 ;; Use PARLEVEL since both minicargo and mrustc use it
466 ;; to set the level of parallelism.
467 (setenv "PARLEVEL" (number->string job-count))
468 (display "Building mrustc...\n")
469 (apply invoke "make" make-flags)
470
471 ;; This doesn't seem to build anything, but it
472 ;; sets additional minicargo flags.
473 (display "Building RUSTCSRC...\n")
474 (apply invoke "make" "RUSTCSRC" make-flags)
475
476 ;; This probably doesn't need to be called explicitly.
477 (display "Building LIBS...\n")
478 (apply invoke "make" "-f" "minicargo.mk" "LIBS" make-flags)
479
480 (display "Building rustc...\n")
481 (apply invoke "make" "-f" "minicargo.mk" "output/rustc"
482 make-flags)
483
484 (display "Building cargo...\n")
485 (apply invoke "make" "-f" "minicargo.mk" "output/cargo"
486 make-flags)
487
488 ;; This one isn't listed in the build script.
489 (display "Rebuilding stdlib with rustc...\n")
490 (apply invoke "make" "-C" "run_rustc" make-flags))))
491 (replace 'install
492 (lambda* (#:key inputs outputs #:allow-other-keys)
493 (let* ((out (assoc-ref outputs "out"))
494 (cargo (assoc-ref outputs "cargo"))
495 (bin (string-append out "/bin"))
496 (rustc (string-append bin "/rustc"))
497 (cargo-bin (string-append cargo "/bin"))
498 (lib (string-append out "/lib"))
499 (system-lib-prefix
500 (string-append lib "/rustlib/"
501 #$(platform-rust-target
502 (lookup-platform-by-target-or-system
503 (or (%current-target-system)
504 (%current-system)))) "/lib")))
505 (mkdir-p (dirname rustc))
506 (copy-file "run_rustc/output/prefix/bin/rustc_binary" rustc)
507 (wrap-program rustc
508 `("LD_LIBRARY_PATH" = (,system-lib-prefix)))
509 (mkdir-p lib)
510 (copy-recursively "run_rustc/output/prefix/lib" lib)
511 (install-file "run_rustc/output/prefix/bin/cargo" cargo-bin)))))))
512 (synopsis "Compiler for the Rust programming language")
513 (description "Rust is a systems programming language that provides memory
514safety and thread safety guarantees.")
515 (home-page "https://github.com/thepowersgang/mrustc")
516
517 ;; List of systems where rust-bootstrap is explicitly known to build:
518 (supported-systems '("x86_64-linux"))
519
520 ;; Dual licensed.
521 (license (list license:asl2.0 license:expat))))
522
344(define-public rust-1.55 523(define-public rust-1.55
345 (package 524 (package
346 (name "rust") 525 (name "rust")
@@ -490,8 +669,8 @@ ar = \"" binutils "/bin/ar" "\"
490 (native-inputs 669 (native-inputs
491 `(("pkg-config" ,pkg-config) 670 `(("pkg-config" ,pkg-config)
492 ("python" ,python-minimal-wrapper) 671 ("python" ,python-minimal-wrapper)
493 ("rustc-bootstrap" ,rust-bootstrap) 672 ("rustc-bootstrap" ,rust-bootstrap-1.54)
494 ("cargo-bootstrap" ,rust-bootstrap "cargo"))) 673 ("cargo-bootstrap" ,rust-bootstrap-1.54 "cargo")))
495 (inputs 674 (inputs
496 `(("bash" ,bash-minimal) 675 `(("bash" ,bash-minimal)
497 ("llvm" ,llvm-13) 676 ("llvm" ,llvm-13)