meowy-webring/.guix/modules/rust.scm

302 lines
15 KiB
Scheme

(define-module (rust)
#:use-module (guix)
#:use-module (guix build-system cargo)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (gnu packages)
#:use-module (gnu packages crates-io)
#:use-module (gnu packages gdb)
#:use-module (gnu packages linux)
#:use-module (gnu packages rust)
#:use-module (srfi srfi-1))
(define rust-1.68
(@@ (gnu packages rust) rust-1.68))
(define rust-bootstrapped-package
(@@ (gnu packages rust) rust-bootstrapped-package))
(define %cargo-reference-hash
(@@ (gnu packages rust) %cargo-reference-hash))
(define rust-1.69
(let ((base-rust
(rust-bootstrapped-package
rust-1.68 "1.69.0" "03zn7kx5bi5mdfsqfccj4h8gd6abm7spj0kjsfxwlv5dcwc9f1gv")))
(package
(inherit base-rust)
(source
(origin
(inherit (package-source base-rust))
(snippet
'(begin
(for-each delete-file-recursively
'("src/llvm-project"
"vendor/tikv-jemalloc-sys/jemalloc"))
;; Also remove the bundled (mostly Windows) libraries.
(for-each delete-file
(find-files "vendor" ".*\\.(a|dll|exe|lib)$")))))))))
(define rust-1.70
(let ((base-rust
(rust-bootstrapped-package
rust-1.69 "1.70.0" "0z6j7d0ni0rmfznv0w3mrf882m11kyh51g2bxkj40l3s1c0axgxj")))
(package
(inherit base-rust)
(source
(origin
(inherit (package-source base-rust))
;; Rust 1.70 uses the rustix library which on Linux, it defaults to
;; using outline ASM which without the cc cargo feature enabled, it
;; will expect a precompiled binary library. This patch will enable the cargo
;; cc feature flag inside the fd-lock vendored Cargo.toml file, which is the
;; crate that uses rustix.
(patches (list ".guix/modules/patches/rust-1.70-fix-rustix-build.patch"))
(patch-flags '("-p1"))))
(arguments
(substitute-keyword-arguments (package-arguments base-rust)
((#:phases phases)
`(modify-phases ,phases
(replace 'build
(lambda* (#:key parallel-build? #:allow-other-keys)
(let ((job-spec (string-append
"-j" (if parallel-build?
(number->string (parallel-job-count))
"1"))))
(invoke "./x.py" job-spec "build" "--stage=1"
"library/std"
"src/tools/cargo")))))))))))
(define rust-1.71
(let ((base-rust
(rust-bootstrapped-package
rust-1.70 "1.71.0" "15jc0d13cmrh2xvpkyyvsbwgn3w4klqiwf2wlgzfp22mvjmy8rx6")))
(package
(inherit base-rust)
(arguments
(substitute-keyword-arguments (package-arguments base-rust)
((#:validate-runpath? _ #t)
#f)
((#:phases phases)
`(modify-phases ,phases
(replace 'patch-cargo-checksums
(lambda _
(substitute* '("Cargo.lock"
"src/bootstrap/Cargo.lock"
"src/tools/rust-analyzer/Cargo.lock"
"src/tools/cargo/Cargo.lock")
(("(checksum = )\".*\"" all name)
(string-append name "\"" ,%cargo-reference-hash "\"")))
(generate-all-checksums "vendor"))))))))))
;;; Function to make creating a list to ignore tests a bit easier.
(define (make-ignore-test-list strs)
(map (lambda (str)
(let ((ignore-string (format #f "#[ignore]\n~a" str)))
`((,str) ,ignore-string)))
strs))
;;; Note: Only the latest versions of Rust are supported and tested. The
;;; intermediate rusts are built for bootstrapping purposes and should not
;;; be relied upon. This is to ease maintenance and reduce the time
;;; required to build the full Rust bootstrap chain.
;;;
;;; Here we take the latest included Rust, make it public, and re-enable tests
;;; and extra components such as rustfmt.
(define-public backported-rust
(let ((base-rust rust-1.71))
(package
(inherit base-rust)
(outputs (cons "rustfmt" (package-outputs base-rust)))
(arguments
(substitute-keyword-arguments (package-arguments base-rust)
((#:tests? _ #f)
(not (%current-target-system)))
((#:phases phases)
`(modify-phases ,phases
(add-after 'unpack 'relax-gdb-auto-load-safe-path
;; Allow GDB to load binaries from any location, otherwise the
;; gdbinfo tests fail. This is only useful when testing with a
;; GDB version newer than 8.2.
(lambda _
(setenv "HOME" (getcwd))
(with-output-to-file (string-append (getenv "HOME") "/.gdbinit")
(lambda _
(format #t "set auto-load safe-path /~%")))
;; Do not launch gdb with '-nx' which causes it to not execute
;; any init file.
(substitute* "src/tools/compiletest/src/runtest.rs"
(("\"-nx\".as_ref\\(\\), ")
""))))
(add-after 'unpack 'patch-cargo-env-shebang
(lambda _
(substitute* '("src/tools/cargo/tests/testsuite/build.rs"
"src/tools/cargo/tests/testsuite/fix.rs")
;; The cargo *_wrapper tests set RUSTC.*WRAPPER environment
;; variable which points to /usr/bin/env. Since it's not a
;; shebang, it needs to be manually patched.
(("/usr/bin/env")
(which "env")))))
(add-after 'unpack 'disable-tests-requiring-git
(lambda _
(substitute* "src/tools/cargo/tests/testsuite/git.rs"
,@(make-ignore-test-list '("fn fetch_downloads_with_git2_first_then_with_gitoxide_and_vice_versa"
"fn git_fetch_cli_env_clean"
"fn git_with_cli_force"
"fn use_the_cli")))
;; Gitoxide tests seem to require the internet to run
;; and Guix build containers don't have the internet.
(substitute* "src/tools/cargo/tests/testsuite/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_clones_shallow_two_revs_same_deps"
"fn gitoxide_git_dependencies_switch_from_branch_to_rev"
"fn gitoxide_shallow_clone_followed_by_non_shallow_update"
"fn shallow_deps_work_with_revisions_and_branches_mixed_on_same_dependency")))
(substitute* "src/tools/cargo/tests/testsuite/offline.rs"
,@(make-ignore-test-list '("fn gitoxide_cargo_compile_offline_with_cached_git_dep_shallow_dep")))
(substitute* "src/tools/cargo/tests/testsuite/patch.rs"
,@(make-ignore-test-list '("fn gitoxide_clones_shallow_old_git_patch")))))
(add-after 'unpack 'disable-tests-requiring-mercurial
(lambda _
(substitute*
"src/tools/cargo/tests/testsuite/init/mercurial_autodetect/mod.rs"
,@(make-ignore-test-list '("fn case")))
(substitute*
"src/tools/cargo/tests/testsuite/init/simple_hg/mod.rs"
,@(make-ignore-test-list '("fn case")))
(substitute*
"src/tools/cargo/tests/testsuite/init/simple_hg_ignore_exists/mod.rs"
,@(make-ignore-test-list '("fn case")))
(substitute*
"src/tools/cargo/tests/testsuite/new.rs"
,@(make-ignore-test-list '("fn simple_hg")))))
(add-after 'unpack 'disable-tests-broken-on-aarch64
(lambda _
(with-directory-excursion "src/tools/cargo/tests/testsuite/"
(substitute* "build_script_extra_link_arg.rs"
(("^fn build_script_extra_link_arg_bin_single" m)
(string-append "#[ignore]\n" m)))
(substitute* "build_script.rs"
(("^fn env_test" m)
(string-append "#[ignore]\n" m)))
(substitute* "collisions.rs"
(("^fn collision_doc_profile_split" m)
(string-append "#[ignore]\n" m)))
(substitute* "concurrent.rs"
(("^fn no_deadlock_with_git_dependencies" m)
(string-append "#[ignore]\n" m)))
(substitute* "features2.rs"
(("^fn dep_with_optional_host_deps_activated" m)
(string-append "#[ignore]\n" m))))))
(add-after 'unpack 'patch-command-exec-tests
;; This test suite includes some tests that the stdlib's
;; `Command` execution properly handles in situations where
;; the environment or PATH variable are empty, but this fails
;; since we don't have `echo` available at its usual FHS
;; location.
(lambda _
(substitute* (match (find-files "." "^command-exec.rs$")
((file) file))
(("Command::new\\(\"echo\"\\)")
(format #f "Command::new(~s)" (which "echo"))))))
(add-after 'unpack 'patch-command-uid-gid-test
(lambda _
(substitute* (match (find-files "." "^command-uid-gid.rs$")
((file) file))
(("/bin/sh")
(which "sh")))))
(add-after 'unpack 'skip-shebang-tests
;; This test make sure that the parser behaves properly when a
;; source file starts with a shebang. Unfortunately, the
;; patch-shebangs phase changes the meaning of these edge-cases.
;; We skip the test since it's drastically unlikely Guix's
;; packaging will introduce a bug here.
(lambda _
(delete-file "tests/ui/parser/shebang/sneaky-attrib.rs")))
(add-after 'unpack 'patch-process-tests
(lambda* (#:key inputs #:allow-other-keys)
(let ((bash (assoc-ref inputs "bash")))
(substitute* "library/std/src/process/tests.rs"
(("\"/bin/sh\"")
(string-append "\"" bash "/bin/sh\"")))
;; The three tests which are known to fail upstream on QEMU
;; emulation on aarch64 and riscv64 also fail on x86_64 in Guix's
;; build system. Skip them on all builds.
(substitute* "library/std/src/sys/unix/process/process_common/tests.rs"
(("target_arch = \"arm\",") "target_os = \"linux\",")))))
(add-after 'unpack 'disable-interrupt-tests
(lambda _
;; This test hangs in the build container; disable it.
(substitute* (match (find-files "." "^freshness.rs$")
((file) file))
(("fn linking_interrupted")
"#[ignore]\nfn linking_interrupted"))
;; Likewise for the ctrl_c_kills_everyone test.
(substitute* (match (find-files "." "^death.rs$")
((file) file))
(("fn ctrl_c_kills_everyone")
"#[ignore]\nfn ctrl_c_kills_everyone"))))
(add-after 'unpack 'adjust-rpath-values
;; This adds %output:out to rpath, allowing us to install utilities in
;; different outputs while reusing the shared libraries.
(lambda* (#:key outputs #:allow-other-keys)
(let ((out (assoc-ref outputs "out")))
(substitute* "src/bootstrap/builder.rs"
((" = rpath.*" all)
(string-append all
" "
"rustflags.arg(\"-Clink-args=-Wl,-rpath="
out "/lib\");\n"))))))
(add-after 'configure 'add-gdb-to-config
(lambda* (#:key inputs #:allow-other-keys)
(let ((gdb (assoc-ref inputs "gdb")))
(substitute* "config.toml"
(("^python =.*" all)
(string-append all
"gdb = \"" gdb "/bin/gdb\"\n"))))))
(replace 'build
;; Phase overridden to also build rustfmt.
(lambda* (#:key parallel-build? #:allow-other-keys)
(let ((job-spec (string-append
"-j" (if parallel-build?
(number->string (parallel-job-count))
"1"))))
(invoke "./x.py" job-spec "build"
"library/std" ;rustc
"src/tools/cargo"
"src/tools/rustfmt"))))
(replace 'check
;; Phase overridden to also test rustfmt.
(lambda* (#:key tests? parallel-build? #:allow-other-keys)
(when tests?
(let ((job-spec (string-append
"-j" (if parallel-build?
(number->string (parallel-job-count))
"1"))))
(invoke "./x.py" job-spec "test" "-vv"
"library/std"
"src/tools/cargo"
"src/tools/rustfmt")))))
(replace 'install
;; Phase overridden to also install rustfmt.
(lambda* (#:key outputs #:allow-other-keys)
(invoke "./x.py" "install")
(substitute* "config.toml"
;; Adjust the prefix to the 'cargo' output.
(("prefix = \"[^\"]*\"")
(format #f "prefix = ~s" (assoc-ref outputs "cargo"))))
(invoke "./x.py" "install" "cargo")
(substitute* "config.toml"
;; Adjust the prefix to the 'rustfmt' output.
(("prefix = \"[^\"]*\"")
(format #f "prefix = ~s" (assoc-ref outputs "rustfmt"))))
(invoke "./x.py" "install" "rustfmt")))))))
;; Add test inputs.
(native-inputs (cons* `("gdb" ,gdb/pinned)
`("procps" ,procps)
(package-native-inputs base-rust))))))