gnu: make-rust-sysroot/implementation: Use gexps.

* gnu/packages/rust.scm (make-rust-sysroot/implementation): Use gexps.

Change-Id: Ie35ca201c2a55f00023dad02a0d1121b6f298812
This commit is contained in:
Maxim Cournoyer 2024-01-25 09:45:42 -05:00 committed by Ludovic Courtès
parent e5ee9403af
commit f719373583
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -1351,84 +1351,84 @@ (define make-rust-sysroot/implementation
(outputs '("out")) (outputs '("out"))
(arguments (arguments
(substitute-keyword-arguments (package-arguments base-rust) (substitute-keyword-arguments (package-arguments base-rust)
((#:tests? _ #f) #f) ; This package for cross-building. ((#:tests? _ #f) #f) ; This package for cross-building.
((#:phases phases) ((#:phases phases)
`(modify-phases ,phases #~(modify-phases #$phases
(add-after 'unpack 'unbundle-xz (add-after 'unpack 'unbundle-xz
(lambda _ (lambda _
(delete-file-recursively "vendor/lzma-sys/xz-5.2") (delete-file-recursively "vendor/lzma-sys/xz-5.2")
;; Remove the option of using the static library. ;; Remove the option of using the static library.
;; This is necessary for building the sysroot. ;; This is necessary for building the sysroot.
(substitute* "vendor/lzma-sys/build.rs" (substitute* "vendor/lzma-sys/build.rs"
(("!want_static && ") "")))) (("!want_static && ") ""))))
,@(if (target-mingw? target) #$@(if (target-mingw? target)
`((add-after 'set-env 'patch-for-mingw `((add-after 'set-env 'patch-for-mingw
(lambda* (#:key inputs #:allow-other-keys) (lambda* (#:key inputs #:allow-other-keys)
(setenv "LIBRARY_PATH" (setenv "LIBRARY_PATH"
(string-join (string-join
(delete (delete
(string-append (string-append
(or (assoc-ref inputs "mingw-w64-i686-winpthreads") (or (assoc-ref inputs "mingw-w64-i686-winpthreads")
(assoc-ref inputs "mingw-w64-x86_64-winpthreads")) (assoc-ref inputs "mingw-w64-x86_64-winpthreads"))
"/lib") "/lib")
(string-split (getenv "LIBRARY_PATH") #\:)) (string-split (getenv "LIBRARY_PATH") #\:))
":")) ":"))
(setenv "CPLUS_INCLUDE_PATH" (setenv "CPLUS_INCLUDE_PATH"
(string-join (string-join
(delete (delete
(string-append (string-append
(or (assoc-ref inputs "mingw-w64-i686-winpthreads") (or (assoc-ref inputs "mingw-w64-i686-winpthreads")
(assoc-ref inputs "mingw-w64-x86_64-winpthreads")) (assoc-ref inputs "mingw-w64-x86_64-winpthreads"))
"/include") "/include")
(string-split (getenv "CPLUS_INCLUDE_PATH") #\:)) (string-split (getenv "CPLUS_INCLUDE_PATH") #\:))
":")) ":"))
;; When building a rust-sysroot this crate is only used for ;; When building a rust-sysroot this crate is only used for
;; the rust-installer. ;; the rust-installer.
(substitute* "vendor/num_cpus/src/linux.rs" (substitute* "vendor/num_cpus/src/linux.rs"
(("\\.ceil\\(\\)") "")) (("\\.ceil\\(\\)") ""))
;; gcc doesn't recognize this flag. ;; gcc doesn't recognize this flag.
(substitute* (substitute*
"compiler/rustc_target/src/spec/base/windows_gnullvm.rs" "compiler/rustc_target/src/spec/base/windows_gnullvm.rs"
((", \"--unwindlib=none\"") ""))))) ((", \"--unwindlib=none\"") "")))))
`()) `())
(replace 'set-env (replace 'set-env
(lambda* (#:key inputs #:allow-other-keys) (lambda* (#:key inputs #:allow-other-keys)
(setenv "SHELL" (which "sh")) (setenv "SHELL" (which "sh"))
(setenv "CONFIG_SHELL" (which "sh")) (setenv "CONFIG_SHELL" (which "sh"))
(setenv "CC" (which "gcc")) (setenv "CC" (which "gcc"))
;; The Guix LLVM package installs only shared libraries. ;; The Guix LLVM package installs only shared libraries.
(setenv "LLVM_LINK_SHARED" "1") (setenv "LLVM_LINK_SHARED" "1")
(setenv "CROSS_LIBRARY_PATH" (getenv "LIBRARY_PATH")) (setenv "CROSS_LIBRARY_PATH" (getenv "LIBRARY_PATH"))
(setenv "CROSS_CPLUS_INCLUDE_PATH" (getenv "CPLUS_INCLUDE_PATH")) (setenv "CROSS_CPLUS_INCLUDE_PATH" (getenv "CPLUS_INCLUDE_PATH"))
(when (assoc-ref inputs (string-append "glibc-cross-" ,target)) (when (assoc-ref inputs (string-append "glibc-cross-" #$target))
(setenv "LIBRARY_PATH" (setenv "LIBRARY_PATH"
(string-join (string-join
(delete (delete
(string-append (string-append
(assoc-ref inputs (assoc-ref inputs
(string-append "glibc-cross-" ,target)) (string-append "glibc-cross-" #$target))
"/lib") "/lib")
(string-split (getenv "LIBRARY_PATH") #\:)) (string-split (getenv "LIBRARY_PATH") #\:))
":")) ":"))
(setenv "CPLUS_INCLUDE_PATH" (setenv "CPLUS_INCLUDE_PATH"
(string-join (string-join
(delete (delete
(string-append (string-append
(assoc-ref inputs (assoc-ref inputs
(string-append "glibc-cross-" ,target)) (string-append "glibc-cross-" #$target))
"/include") "/include")
(string-split (getenv "CPLUS_INCLUDE_PATH") #\:)) (string-split (getenv "CPLUS_INCLUDE_PATH") #\:))
":"))))) ":")))))
(replace 'configure (replace 'configure
(lambda* (#:key inputs outputs #:allow-other-keys) (lambda* (#:key inputs outputs #:allow-other-keys)
(let* ((out (assoc-ref outputs "out")) (let* ((out (assoc-ref outputs "out"))
(target-cc (target-cc
(search-input-file (search-input-file
inputs (string-append "/bin/" ,(cc-for-target target))))) inputs (string-append "/bin/" #$(cc-for-target target)))))
(call-with-output-file "config.toml" (call-with-output-file "config.toml"
(lambda (port) (lambda (port)
(display (string-append " (display (string-append "
[llvm] [llvm]
[build] [build]
cargo = \"" (search-input-file inputs "/bin/cargo") "\" cargo = \"" (search-input-file inputs "/bin/cargo") "\"
@ -1437,7 +1437,7 @@ (define make-rust-sysroot/implementation
python = \"" (which "python") "\" python = \"" (which "python") "\"
vendor = true vendor = true
submodules = false submodules = false
target = [\"" ,(platform-rust-target (lookup-platform-by-target target)) "\"] target = [\"" #$(platform-rust-target (lookup-platform-by-target target)) "\"]
[install] [install]
prefix = \"" out "\" prefix = \"" out "\"
sysconfdir = \"etc\" sysconfdir = \"etc\"
@ -1446,65 +1446,64 @@ (define make-rust-sysroot/implementation
jemalloc = false jemalloc = false
default-linker = \"" target-cc "\" default-linker = \"" target-cc "\"
channel = \"stable\" channel = \"stable\"
[target." ,(platform-rust-target (lookup-platform-by-system (%current-system))) "] [target." #$(platform-rust-target (lookup-platform-by-system (%current-system))) "]
# These are all native tools # These are all native tools
llvm-config = \"" (search-input-file inputs "/bin/llvm-config") "\" llvm-config = \"" (search-input-file inputs "/bin/llvm-config") "\"
linker = \"" (which "gcc") "\" linker = \"" (which "gcc") "\"
cc = \"" (which "gcc") "\" cc = \"" (which "gcc") "\"
cxx = \"" (which "g++") "\" cxx = \"" (which "g++") "\"
ar = \"" (which "ar") "\" ar = \"" (which "ar") "\"
[target." ,(platform-rust-target (lookup-platform-by-target target)) "] [target." #$(platform-rust-target (lookup-platform-by-target target)) "]
llvm-config = \"" (search-input-file inputs "/bin/llvm-config") "\" llvm-config = \"" (search-input-file inputs "/bin/llvm-config") "\"
linker = \"" target-cc "\" linker = \"" target-cc "\"
cc = \"" target-cc "\" cc = \"" target-cc "\"
cxx = \"" (search-input-file inputs (string-append "/bin/" ,(cxx-for-target target))) "\" cxx = \"" (search-input-file inputs (string-append "/bin/" #$(cxx-for-target target))) "\"
ar = \"" (search-input-file inputs (string-append "/bin/" ,(ar-for-target target))) "\" ar = \"" (search-input-file inputs (string-append "/bin/" #$(ar-for-target target))) "\"
[dist] [dist]
") port)))))) ") port))))))
(replace 'build (replace 'build
;; Phase overridden to build the necessary directories. ;; Phase overridden to build the necessary directories.
(lambda* (#:key parallel-build? #:allow-other-keys) (lambda* (#:key parallel-build? #:allow-other-keys)
(let ((job-spec (string-append (let ((job-spec (string-append
"-j" (if parallel-build? "-j" (if parallel-build?
(number->string (parallel-job-count)) (number->string (parallel-job-count))
"1")))) "1"))))
;; This works for us with the --sysroot flag ;; This works for us with the --sysroot flag
;; and then we can build ONLY library/std ;; and then we can build ONLY library/std
(invoke "./x.py" job-spec "build" "library/std")))) (invoke "./x.py" job-spec "build" "library/std"))))
(replace 'install (replace 'install
(lambda _ (lambda _
(invoke "./x.py" "install" "library/std"))) (invoke "./x.py" "install" "library/std")))
(delete 'install-rust-src) (delete 'install-rust-src)
(delete 'wrap-rust-analyzer) (delete 'wrap-rust-analyzer)
(delete 'wrap-rustc))))) (delete 'wrap-rustc)))))
(inputs (inputs
(modify-inputs (package-inputs base-rust) (modify-inputs (package-inputs base-rust)
(prepend xz))) ; for lzma-sys (prepend xz))) ; for lzma-sys
(propagated-inputs (propagated-inputs
(if (target-mingw? target) (if (target-mingw? target)
(modify-inputs (package-propagated-inputs base-rust) (modify-inputs (package-propagated-inputs base-rust)
(prepend (prepend
(if (string=? "i686-w64-mingw32" target) (if (string=? "i686-w64-mingw32" target)
mingw-w64-i686-winpthreads mingw-w64-i686-winpthreads
mingw-w64-x86_64-winpthreads))) mingw-w64-x86_64-winpthreads)))
(package-propagated-inputs base-rust))) (package-propagated-inputs base-rust)))
(native-inputs (native-inputs
(if (target-mingw? target) (if (target-mingw? target)
(modify-inputs (package-native-inputs base-rust) (modify-inputs (package-native-inputs base-rust)
(prepend (cross-gcc target (prepend (cross-gcc target
#:libc (cross-libc target)) #:libc (cross-libc target))
(cross-binutils target) (cross-binutils target)
(if (string=? "i686-w64-mingw32" target) (if (string=? "i686-w64-mingw32" target)
mingw-w64-i686-winpthreads mingw-w64-i686-winpthreads
mingw-w64-x86_64-winpthreads))) mingw-w64-x86_64-winpthreads)))
(modify-inputs (package-native-inputs base-rust) (modify-inputs (package-native-inputs base-rust)
(prepend (cross-gcc target (prepend (cross-gcc target
#:libc (cross-libc target)) #:libc (cross-libc target))
(cross-libc target) (cross-libc target)
(cross-binutils target))))) (cross-binutils target)))))
(properties (properties
`((hidden? . #t) `((hidden? . #t) ,(package-properties base-rust))))))
,(package-properties base-rust))))))
(define-public rust-analyzer (define-public rust-analyzer
(package (package