gnu: cargo: Simplify unpacking.
Fixes <http://bugs.gnu.org/26166>. * gnu/packages/rust.scm (cargo) [arguments]<:modules>: Add (srfi srfi-1). [arguments]<:phases>: Adapt 'unpack-submodule-sources' phase to more clearly seperate the tasks it does. Add helper procedures 'unpack', 'touch', 'install-rust-library'. [arguments]<:phases>: Rename 'set-cargo-home' to 'set-environment-up' and make it use official cargo directories. [arguments]<:phases>: Remove 'configure' phase.
This commit is contained in:
		
							parent
							
								
									002c3e6dd6
								
							
						
					
					
						commit
						f0eb0a4bb1
					
				
					 1 changed files with 35 additions and 21 deletions
				
			
		| 
						 | 
					@ -301,6 +301,8 @@ safety and thread safety guarantees.")
 | 
				
			||||||
    ;; Dual licensed.
 | 
					    ;; Dual licensed.
 | 
				
			||||||
    (license (list license:asl2.0 license:expat))))
 | 
					    (license (list license:asl2.0 license:expat))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					;; This tries very hard not to get into a cyclic dependency like this:
 | 
				
			||||||
 | 
					;;   cargo <- cargo-build-system <- cargo.
 | 
				
			||||||
(define-public cargo
 | 
					(define-public cargo
 | 
				
			||||||
  (package
 | 
					  (package
 | 
				
			||||||
    (name "cargo")
 | 
					    (name "cargo")
 | 
				
			||||||
| 
						 | 
					@ -825,6 +827,11 @@ safety and thread safety guarantees.")
 | 
				
			||||||
    (arguments
 | 
					    (arguments
 | 
				
			||||||
     `(#:cargo ,cargo-bootstrap
 | 
					     `(#:cargo ,cargo-bootstrap
 | 
				
			||||||
       #:tests? #f ; FIXME
 | 
					       #:tests? #f ; FIXME
 | 
				
			||||||
 | 
					       #:modules
 | 
				
			||||||
 | 
					       ((ice-9 match)
 | 
				
			||||||
 | 
					        (srfi srfi-1) ; 'every
 | 
				
			||||||
 | 
					        (guix build utils)
 | 
				
			||||||
 | 
					        (guix build cargo-build-system))
 | 
				
			||||||
       #:phases
 | 
					       #:phases
 | 
				
			||||||
       (modify-phases %standard-phases
 | 
					       (modify-phases %standard-phases
 | 
				
			||||||
         ;; Avoid cargo complaining about missmatched checksums.
 | 
					         ;; Avoid cargo complaining about missmatched checksums.
 | 
				
			||||||
| 
						 | 
					@ -833,30 +840,36 @@ safety and thread safety guarantees.")
 | 
				
			||||||
         (delete 'patch-usr-bin-file)
 | 
					         (delete 'patch-usr-bin-file)
 | 
				
			||||||
         (add-after 'unpack 'unpack-submodule-sources
 | 
					         (add-after 'unpack 'unpack-submodule-sources
 | 
				
			||||||
           (lambda* (#:key inputs #:allow-other-keys)
 | 
					           (lambda* (#:key inputs #:allow-other-keys)
 | 
				
			||||||
             (let ((unpack (lambda (source target)
 | 
					             (define (unpack source target)
 | 
				
			||||||
               (mkdir-p target)
 | 
					               (mkdir-p target)
 | 
				
			||||||
               (with-directory-excursion target
 | 
					               (with-directory-excursion target
 | 
				
			||||||
                 (zero? (system* "tar" "xf"
 | 
					                 (zero? (system* "tar" "xf"
 | 
				
			||||||
                                 source
 | 
					                                 source
 | 
				
			||||||
                                               "--strip-components=1"))))))
 | 
					                                 "--strip-components=1"))))
 | 
				
			||||||
               (mkdir "vendor")
 | 
					             (define (touch file-name)
 | 
				
			||||||
               (for-each (lambda (p)
 | 
					               (call-with-output-file file-name (const #t)))
 | 
				
			||||||
                           (let ((name (car p)))
 | 
					             (define (install-rust-library entry)
 | 
				
			||||||
 | 
					               (match entry
 | 
				
			||||||
 | 
					                 ((name . src)
 | 
				
			||||||
                  (if (string-prefix? "rust-" name)
 | 
					                  (if (string-prefix? "rust-" name)
 | 
				
			||||||
                               (let ((rsrc (string-append "vendor/"
 | 
					                    (let* ((rust-length (string-length "rust-"))
 | 
				
			||||||
                                                           (string-drop name
 | 
					                           (rust-name (string-drop name
 | 
				
			||||||
                                                                        (string-length "rust-")))))
 | 
					                                                   rust-length))
 | 
				
			||||||
                                 (unpack (assoc-ref inputs name) rsrc)
 | 
					                           (rsrc (string-append "vendor/"
 | 
				
			||||||
                                 (system* "touch" (string-append rsrc "/.cargo-ok"))
 | 
					                                                rust-name))
 | 
				
			||||||
                                 (generate-checksums rsrc (assoc-ref inputs name)))))) inputs))))
 | 
					                           (unpack-status (unpack src rsrc)))
 | 
				
			||||||
         ;; Set CARGO_HOME to use the vendored dependencies.
 | 
					                      (touch (string-append rsrc "/.cargo-ok"))
 | 
				
			||||||
         (add-after 'unpack 'set-cargo-home
 | 
					                      (generate-checksums rsrc src)
 | 
				
			||||||
 | 
					                      unpack-status)))
 | 
				
			||||||
 | 
					                 (_ #t)))
 | 
				
			||||||
 | 
					               (mkdir "vendor")
 | 
				
			||||||
 | 
					               (every install-rust-library inputs)))
 | 
				
			||||||
 | 
					         (add-after 'unpack 'set-environment-up
 | 
				
			||||||
           (lambda* (#:key inputs #:allow-other-keys)
 | 
					           (lambda* (#:key inputs #:allow-other-keys)
 | 
				
			||||||
             (let* ((gcc (assoc-ref inputs "gcc"))
 | 
					             (let* ((gcc (assoc-ref inputs "gcc"))
 | 
				
			||||||
                    (cc (string-append gcc "/bin/gcc")))
 | 
					                    (cc (string-append gcc "/bin/gcc")))
 | 
				
			||||||
               (mkdir "cargohome")
 | 
					               (mkdir ".cargo")
 | 
				
			||||||
               (setenv "CARGO_HOME" (string-append (getcwd) "/cargohome"))
 | 
					               (call-with-output-file ".cargo/config"
 | 
				
			||||||
               (call-with-output-file "cargohome/config"
 | 
					 | 
				
			||||||
                 (lambda (p)
 | 
					                 (lambda (p)
 | 
				
			||||||
                   (format p "
 | 
					                   (format p "
 | 
				
			||||||
[source.crates-io]
 | 
					[source.crates-io]
 | 
				
			||||||
| 
						 | 
					@ -868,7 +881,8 @@ directory = 'vendor'
 | 
				
			||||||
")))
 | 
					")))
 | 
				
			||||||
               (setenv "CMAKE_C_COMPILER" cc)
 | 
					               (setenv "CMAKE_C_COMPILER" cc)
 | 
				
			||||||
               (setenv "CC" cc))
 | 
					               (setenv "CC" cc))
 | 
				
			||||||
             #t)))))
 | 
					             #t))
 | 
				
			||||||
 | 
					         (delete 'configure))))
 | 
				
			||||||
    (home-page "https://github.com/rust-lang/cargo")
 | 
					    (home-page "https://github.com/rust-lang/cargo")
 | 
				
			||||||
    (synopsis "Build tool and package manager for Rust")
 | 
					    (synopsis "Build tool and package manager for Rust")
 | 
				
			||||||
    (description "Cargo is a tool that allows Rust projects to declare their
 | 
					    (description "Cargo is a tool that allows Rust projects to declare their
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue