diff options
Diffstat (limited to 'gnu/packages/rust.scm')
-rw-r--r-- | gnu/packages/rust.scm | 326 |
1 files changed, 280 insertions, 46 deletions
diff --git a/gnu/packages/rust.scm b/gnu/packages/rust.scm index 2f1b6f90d7..104834deab 100644 --- a/gnu/packages/rust.scm +++ b/gnu/packages/rust.scm @@ -40,29 +40,36 @@ #:use-module (gnu packages bootstrap) #:use-module (gnu packages cmake) #:use-module (gnu packages compression) + #:use-module (gnu packages cross-base) #:use-module (gnu packages curl) #:use-module (gnu packages elf) #:use-module (gnu packages flex) #:use-module (gnu packages gcc) #:use-module (gnu packages gdb) #:use-module (gnu packages jemalloc) + #:use-module (gnu packages libunwind) #:use-module (gnu packages linux) #:use-module (gnu packages llvm) + #:use-module (gnu packages mingw) #:use-module (gnu packages pkg-config) #:use-module (gnu packages python) #:use-module (gnu packages ssh) #:use-module (gnu packages tls) #:use-module (gnu packages) #:use-module (guix build-system cargo) - #:use-module (guix build-system copy) #:use-module (guix build-system gnu) + #:use-module (guix build-system trivial) #:use-module (guix download) + #:use-module (guix memoization) #:use-module (guix git-download) #:use-module ((guix licenses) #:prefix license:) #:use-module (guix packages) #:use-module ((guix build utils) #:select (alist-replace)) #:use-module (guix utils) + #:use-module (guix gexp) #:use-module (ice-9 match) + #:use-module (ice-9 optargs) + #:use-module (srfi srfi-1) #:use-module (srfi srfi-26)) ;; This is the hash for the empty file, and the reason it's relevant is not @@ -103,6 +110,10 @@ ("aarch64-linux" "aarch64-unknown-linux-gnu") ("mips64el-linux" "mips64el-unknown-linux-gnuabi64") ("riscv64-linux" "riscv64gc-unknown-linux-gnu") + ("i586-gnu" "i686-unknown-hurd-gnu") + ("i686-gnu" "i686-unknown-hurd-gnu") + ("i686-mingw" "i686-pc-windows-gnu") + ("x86_64-mingw" "x86_64-pc-windows-gnu") (_ (nix-system->gnu-triplet system)))) (define* (rust-uri version #:key (dist "static")) @@ -151,7 +162,7 @@ ;;; Rust 1.54 is special in that it is built with mrustc, which shortens the ;;; bootstrap path. -(define rust-bootstrap +(define-public rust-bootstrap (package (name "rust") (version "1.54.0") @@ -176,7 +187,8 @@ (patches (search-patches "rustc-1.54.0-src.patch")) (patch-flags '("-p0")))) ;default is -p1 (outputs '("out" "cargo")) - (properties '((timeout . 72000) ;20 hours + (properties '((hidden? . #t) + (timeout . 72000) ;20 hours (max-silent-time . 18000))) ;5 hours (for armel) (build-system gnu-build-system) (inputs @@ -369,7 +381,7 @@ safety and thread safety guarantees.") ;; Dual licensed. (license (list license:asl2.0 license:expat)))) -(define rust-1.55 +(define-public rust-1.55 (package (name "rust") (version "1.55.0") @@ -397,7 +409,8 @@ safety and thread safety guarantees.") ((" target_arch = \"s390x\"," all) (string-append all "\n target_arch = \"riscv64\","))))))) (outputs '("out" "cargo")) - (properties '((timeout . 72000) ;20 hours + (properties '((hidden? . #t) + (timeout . 72000) ;20 hours (max-silent-time . 18000))) ;5 hours (for armel) (build-system gnu-build-system) (arguments @@ -554,7 +567,7 @@ safety and thread safety guarantees.") ;; Dual licensed. (license (list license:asl2.0 license:expat)))) -(define rust-1.56 +(define-public rust-1.56 (let ((base-rust (rust-bootstrapped-package rust-1.55 "1.56.1" "04cmqx7nn63hzz7z27b2b0dj2qx18rck9ifvip43s6dampx8v2f3"))) @@ -574,13 +587,13 @@ safety and thread safety guarantees.") (string-append name "\"" ,%cargo-reference-hash "\""))) (generate-all-checksums "vendor")))))))))) -(define rust-1.57 +(define-public rust-1.57 (rust-bootstrapped-package ;; Verified that it *doesn't* build with 1.55. e.g.: ;; * feature `edition2021` is required rust-1.56 "1.57.0" "06jw8ka2p3kls8p0gd4p0chhhb1ia1mlvj96zn78n7qvp71zjiim")) -(define rust-1.58 +(define-public rust-1.58 (rust-bootstrapped-package ;; Verified that it *doesn't* build with 1.56. e.g.: ;; * error: attributes starting with `rustc` are reserved for use by the @@ -590,7 +603,7 @@ safety and thread safety guarantees.") ;; `const_eval_select_ct` rust-1.57 "1.58.1" "1iq7kj16qfpkx8gvw50d8rf7glbm6s0pj2y1qkrz7mi56vfsyfd8")) -(define rust-1.59 +(define-public rust-1.59 (let ((base-rust (rust-bootstrapped-package ;; Verified that it *doesn't* build with 1.57. e.g.: @@ -619,13 +632,13 @@ safety and thread safety guarantees.") (("\\.insn i 0x0F, 0, x0, x0, 0x010") ".word 0x0100000F"))))))) (package-arguments base-rust)))))) -(define rust-1.60 +(define-public rust-1.60 (rust-bootstrapped-package ;; Verified that it *doesn't* build with 1.58. e.g.: ;; * error: unknown codegen option: `symbol-mangling-version` rust-1.59 "1.60.0" "1drqr0a26x1rb2w3kj0i6abhgbs3jx5qqkrcwbwdlx7n3inq5ji0")) -(define rust-1.61 +(define-public rust-1.61 (let ((base-rust (rust-bootstrapped-package rust-1.60 "1.61.0" "1vfs05hkf9ilk19b2vahqn8l6k17pl9nc1ky9kgspaascx8l62xd"))) @@ -647,11 +660,11 @@ safety and thread safety guarantees.") (for-each delete-file (find-files "vendor" ".*\\.(a|dll|exe|lib)$"))))))))) -(define rust-1.62 +(define-public rust-1.62 (rust-bootstrapped-package rust-1.61 "1.62.1" "0gqkg34ic77dcvsz69qbdng6g3zfhl6hnhx7ha1mjkyrzipvxb3j")) -(define rust-1.63 +(define-public rust-1.63 (rust-bootstrapped-package rust-1.62 "1.63.0" "1l4rrbzhxv88pnfq94nbyb9m6lfnjwixma3mwjkmvvs2aqlq158z")) @@ -679,7 +692,7 @@ safety and thread safety guarantees.") (string-append name "\"" ,%cargo-reference-hash "\""))) (generate-all-checksums "vendor")))))))))) -(define rust-1.65 +(define-public rust-1.65 (let ((base-rust (rust-bootstrapped-package rust-1.64 "1.65.0" "0f005kc0vl7qyy298f443i78ibz71hmmh820726bzskpyrkvna2q"))) @@ -691,11 +704,11 @@ safety and thread safety guarantees.") (patches '()) (patch-flags '("-p1"))))))) -(define rust-1.66 +(define-public rust-1.66 (rust-bootstrapped-package rust-1.65 "1.66.1" "1fjr94gsicsxd2ypz4zm8aad1zdbiccr7qjfbmq8f8f7jhx96g2v")) -(define rust-1.67 +(define-public rust-1.67 (let ((base-rust (rust-bootstrapped-package rust-1.66 "1.67.1" "0vpzv6rm3w1wbni17ryvcw83k5klhghklylfdza3nnp8blz3sj26"))) @@ -704,11 +717,11 @@ safety and thread safety guarantees.") (inputs (modify-inputs (package-inputs base-rust) (replace "llvm" llvm-15)))))) -(define rust-1.68 +(define-public rust-1.68 (rust-bootstrapped-package rust-1.67 "1.68.2" "15ifyd5jj8rd979dkakp887hgmhndr68pqaqvd2hqkfdywirqcwk")) -(define rust-1.69 +(define-public rust-1.69 (let ((base-rust (rust-bootstrapped-package rust-1.68 "1.69.0" @@ -727,7 +740,7 @@ safety and thread safety guarantees.") (for-each delete-file (find-files "vendor" "\\.(a|dll|exe|lib)$"))))))))) -(define rust-1.70 +(define-public rust-1.70 (let ((base-rust (rust-bootstrapped-package rust-1.69 "1.70.0" @@ -744,7 +757,7 @@ safety and thread safety guarantees.") ;; for a precompiled library. (patches (search-patches "rust-1.70-fix-rustix-build.patch"))))))) -(define rust-1.71 +(define-public rust-1.71 (let ((base-rust (rust-bootstrapped-package rust-1.70 "1.71.1" "0bj79syjap1kgpg9pc0r4jxc0zkxwm6phjf3digsfafms580vabg"))) @@ -763,7 +776,7 @@ safety and thread safety guarantees.") (string-append name "\"" ,%cargo-reference-hash "\""))) (generate-all-checksums "vendor")))))))))) -(define rust-1.72 +(define-public rust-1.72 (let ((base-rust (rust-bootstrapped-package rust-1.71 "1.72.1" "15gqd1jzhnc16a7gjmav4x1v83jjbzyjh1gvcdfvpkajd9gq8j3z"))) @@ -788,7 +801,7 @@ safety and thread safety guarantees.") (string-append "rustix = { version = \"=0.37.11\"," " features = [\"use-libc\"] }")))))))))) -(define rust-1.73 +(define-public rust-1.73 (let ((base-rust (rust-bootstrapped-package rust-1.72 "1.73.0" "0fmvn7vg3qg9xprgfwv10g3ygy8i4j4bkcxcr1xdy89d3xnjxmln"))) (package @@ -825,9 +838,10 @@ safety and thread safety guarantees.") ;;; Here we take the latest included Rust, make it public, and re-enable tests ;;; and extra components such as rustfmt. (define-public rust - (let ((base-rust rust-1.70)) + (let ((base-rust rust-1.73)) (package (inherit base-rust) + (properties (alist-delete 'hidden? (package-properties base-rust))) (outputs (cons* "rust-src" "tools" (package-outputs base-rust))) (arguments (substitute-keyword-arguments (package-arguments base-rust) @@ -856,11 +870,42 @@ safety and thread safety guarantees.") '("fn fetch_downloads_with_git2_first_"))))) (add-after 'unpack 'disable-tests-requiring-mercurial (lambda _ - (with-directory-excursion "src/tools/cargo/tests/testsuite/init" + (with-directory-excursion "src/tools/cargo/tests/testsuite/cargo_init" (substitute* '("mercurial_autodetect/mod.rs" "simple_hg_ignore_exists/mod.rs") ,@(make-ignore-test-list '("fn case")))))) + (add-after 'unpack 'disable-tests-using-cargo-publish + (lambda _ + (with-directory-excursion "src/tools/cargo/tests/testsuite" + (substitute* "alt_registry.rs" + ,@(make-ignore-test-list + '("fn warn_for_unused_fields"))) + (substitute* '("cargo_add/locked_unchanged/mod.rs" + "cargo_add/lockfile_updated/mod.rs" + "cargo_remove/update_lock_file/mod.rs") + ,@(make-ignore-test-list + '("fn case"))) + (substitute* "git_shallow.rs" + ,@(make-ignore-test-list + '("fn gitoxide_clones_git_dependency_with_shallow_protocol_and_git2_is_used_for_followup_fetches" + "fn gitoxide_clones_registry_with_shallow_protocol_and_aborts_and_updates_again" + "fn gitoxide_clones_registry_with_shallow_protocol_and_follow_up_fetch_maintains_shallowness" + "fn gitoxide_clones_registry_with_shallow_protocol_and_follow_up_with_git2_fetch" + "fn gitoxide_clones_registry_without_shallow_protocol_and_follow_up_fetch_uses_shallowness" + "fn gitoxide_shallow_clone_followed_by_non_shallow_update" + "fn gitoxide_clones_shallow_two_revs_same_deps" + "fn gitoxide_git_dependencies_switch_from_branch_to_rev" + "fn shallow_deps_work_with_revisions_and_branches_mixed_on_same_dependency"))) + (substitute* "install.rs" + ,@(make-ignore-test-list + '("fn failed_install_retains_temp_directory"))) + (substitute* "offline.rs" + ,@(make-ignore-test-list + '("fn gitoxide_cargo_compile_offline_with_cached_git_dep_shallow_dep"))) + (substitute* "patch.rs" + ,@(make-ignore-test-list + '("fn gitoxide_clones_shallow_old_git_patch")))))) (add-after 'unpack 'disable-tests-broken-on-aarch64 (lambda _ (with-directory-excursion "src/tools/cargo/tests/testsuite/" @@ -998,30 +1043,219 @@ safety and thread safety guarantees.") (copy-recursively "src" (string-append out dest "/src"))))) (add-after 'install-rust-src 'wrap-rust-analyzer (lambda* (#:key outputs #:allow-other-keys) - (wrap-program (string-append (assoc-ref outputs "tools") - "/bin/rust-analyzer") - `("RUST_SRC_PATH" ":" = - (,(string-append (assoc-ref outputs "rust-src") - "/lib/rustlib/src/rust/library")))))))))) + (let ((bin (string-append (assoc-ref outputs "tools") "/bin"))) + (rename-file (string-append bin "/rust-analyzer") + (string-append bin "/.rust-analyzer-real")) + (call-with-output-file (string-append bin "/rust-analyzer") + (lambda (port) + (format port "#!~a +if test -z \"${RUST_SRC_PATH}\";then export RUST_SRC_PATH=~S;fi; +exec -a \"$0\" \"~a\" \"$@\"" + (which "bash") + (string-append (assoc-ref outputs "rust-src") + "/lib/rustlib/src/rust/library") + (string-append bin "/.rust-analyzer-real")))) + (chmod (string-append bin "/rust-analyzer") #o755)))))))) ;; Add test inputs. (native-inputs (cons* `("gdb" ,gdb/pinned) `("procps" ,procps) (package-native-inputs base-rust)))))) -(define-public rust-src-1.64 - (hidden-package - (package - (inherit rust-1.64) - (name "rust-src") - (build-system copy-build-system) - (native-inputs '()) - (inputs '()) - (native-search-paths '()) - (outputs '("out")) - (arguments - `(#:install-plan - '(("library" "lib/rustlib/src/rust/library") - ("src" "lib/rustlib/src/rust/src")))) - (synopsis "Source code for the Rust standard library") - (description "This package provide source code for the Rust standard -library, only use by rust-analyzer, make rust-analyzer out of the box.")))) +(define*-public (make-rust-sysroot target) + (make-rust-sysroot/implementation target rust)) + +(define make-rust-sysroot/implementation + (mlambda (target base-rust) + (package + (inherit base-rust) + (name (string-append "rust-sysroot-for-" target)) + (outputs '("out")) + (arguments + (substitute-keyword-arguments (package-arguments base-rust) + ((#:tests? _ #f) #f) ; This package for cross-building. + ((#:phases phases) + `(modify-phases ,phases + (add-after 'unpack 'unbundle-xz + (lambda _ + (delete-file-recursively "vendor/lzma-sys/xz-5.2") + ;; Remove the option of using the static library. + ;; This is necessary for building the sysroot. + (substitute* "vendor/lzma-sys/build.rs" + (("!want_static && ") "")))) + ,@(if (target-mingw? target) + `((add-after 'set-env 'patch-for-mingw + (lambda* (#:key inputs #:allow-other-keys) + (setenv "LIBRARY_PATH" + (string-join + (delete + (string-append + (or (assoc-ref inputs "mingw-w64-i686-winpthreads") + (assoc-ref inputs "mingw-w64-x86_64-winpthreads")) + "/lib") + (string-split (getenv "LIBRARY_PATH") #\:)) + ":")) + (setenv "CPLUS_INCLUDE_PATH" + (string-join + (delete + (string-append + (or (assoc-ref inputs "mingw-w64-i686-winpthreads") + (assoc-ref inputs "mingw-w64-x86_64-winpthreads")) + "/include") + (string-split (getenv "CPLUS_INCLUDE_PATH") #\:)) + ":")) + ;; When building a rust-sysroot this crate is only used for + ;; the rust-installer. + (substitute* "vendor/num_cpus/src/linux.rs" + (("\\.ceil\\(\\)") "")) + ;; gcc doesn't recognize this flag. + (substitute* + "compiler/rustc_target/src/spec/windows_gnullvm_base.rs" + ((", \"--unwindlib=none\"") ""))))) + `()) + (replace 'set-env + (lambda* (#:key inputs #:allow-other-keys) + (setenv "SHELL" (which "sh")) + (setenv "CONFIG_SHELL" (which "sh")) + (setenv "CC" (which "gcc")) + ;; The Guix LLVM package installs only shared libraries. + (setenv "LLVM_LINK_SHARED" "1") + + (setenv "CROSS_LIBRARY_PATH" (getenv "LIBRARY_PATH")) + (setenv "CROSS_CPLUS_INCLUDE_PATH" (getenv "CPLUS_INCLUDE_PATH")) + (when (assoc-ref inputs (string-append "glibc-cross-" ,target)) + (setenv "LIBRARY_PATH" + (string-join + (delete + (string-append + (assoc-ref inputs + (string-append "glibc-cross-" ,target)) + "/lib") + (string-split (getenv "LIBRARY_PATH") #\:)) + ":")) + (setenv "CPLUS_INCLUDE_PATH" + (string-join + (delete + (string-append + (assoc-ref inputs + (string-append "glibc-cross-" ,target)) + "/include") + (string-split (getenv "CPLUS_INCLUDE_PATH") #\:)) + ":"))))) + (replace 'configure + (lambda* (#:key inputs outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (target-cc + (search-input-file + inputs (string-append "/bin/" ,(cc-for-target target))))) + (call-with-output-file "config.toml" + (lambda (port) + (display (string-append " +[llvm] +[build] +cargo = \"" (search-input-file inputs "/bin/cargo") "\" +rustc = \"" (search-input-file inputs "/bin/rustc") "\" +docs = false +python = \"" (which "python") "\" +vendor = true +submodules = false +target = [\"" ,(nix-system->gnu-triplet-for-rust (gnu-triplet->nix-system target)) "\"] +[install] +prefix = \"" out "\" +sysconfdir = \"etc\" +[rust] +debug = false +jemalloc = false +default-linker = \"" target-cc "\" +channel = \"stable\" +[target." ,(nix-system->gnu-triplet-for-rust) "] +# These are all native tools +llvm-config = \"" (search-input-file inputs "/bin/llvm-config") "\" +linker = \"" (which "gcc") "\" +cc = \"" (which "gcc") "\" +cxx = \"" (which "g++") "\" +ar = \"" (which "ar") "\" +[target." ,(nix-system->gnu-triplet-for-rust (gnu-triplet->nix-system target)) "] +llvm-config = \"" (search-input-file inputs "/bin/llvm-config") "\" +linker = \"" target-cc "\" +cc = \"" target-cc "\" +cxx = \"" (search-input-file inputs (string-append "/bin/" ,(cxx-for-target target))) "\" +ar = \"" (search-input-file inputs (string-append "/bin/" ,(ar-for-target target))) "\" +[dist] +") port)))))) + (replace 'build + ;; Phase overridden to build the necessary directories. + (lambda* (#:key parallel-build? #:allow-other-keys) + (let ((job-spec (string-append + "-j" (if parallel-build? + (number->string (parallel-job-count)) + "1")))) + ;; This works for us with the --sysroot flag + ;; and then we can build ONLY library/std + (invoke "./x.py" job-spec "build" "library/std")))) + (replace 'install + (lambda _ + (invoke "./x.py" "install" "library/std"))) + (add-after 'install 'remove-uninstall-script + (lambda* (#:key outputs #:allow-other-keys) + ;; This script has no use on Guix + ;; and it retains a reference to the host's bash. + (delete-file (string-append (assoc-ref outputs "out") + "/lib/rustlib/uninstall.sh")))) + (delete 'install-rust-src) + (delete 'wrap-rust-analyzer) + (delete 'wrap-rustc))))) + (inputs + (modify-inputs (package-inputs base-rust) + (prepend xz))) ; for lzma-sys + (propagated-inputs + (if (target-mingw? target) + (modify-inputs (package-propagated-inputs base-rust) + (prepend + (if (string=? "i686-w64-mingw32" target) + mingw-w64-i686-winpthreads + mingw-w64-x86_64-winpthreads))) + (package-propagated-inputs base-rust))) + (native-inputs + (if (target-mingw? target) + (modify-inputs (package-native-inputs base-rust) + (prepend (cross-gcc target + #:libc (cross-libc target)) + (cross-binutils target) + (if (string=? "i686-w64-mingw32" target) + mingw-w64-i686-winpthreads + mingw-w64-x86_64-winpthreads) + libunwind)) + (modify-inputs (package-native-inputs base-rust) + (prepend (cross-gcc target + #:libc (cross-libc target)) + (cross-libc target) + (cross-binutils target))))) + (properties + `((hidden? . #t) + ,(package-properties base-rust)))))) + +(define-public rust-analyzer + (package + (name "rust-analyzer") + (version (package-version rust)) + (source #f) + (build-system trivial-build-system) + (arguments + (list + #:modules '((guix build utils)) + #:builder + #~(begin + (use-modules (guix build utils)) + (let ((rust (assoc-ref %build-inputs "rust"))) + (install-file (string-append rust "/bin/rust-analyzer") + (string-append #$output "/bin")) + (copy-recursively (string-append rust "/share") + (string-append #$output "/share")))))) + (inputs + (list (list rust "tools"))) + (home-page "https://rust-analyzer.github.io/") + (synopsis "Experimental Rust compiler front-end for IDEs") + (description "Rust-analyzer is a modular compiler frontend for the Rust +language. It is a part of a larger rls-2.0 effort to create excellent IDE +support for Rust.") + (license (list license:expat license:asl2.0)))) |