Hi.,

these day I had spent some more hours struggling with rust ans cargo, trying to get "pre-built" crates.

Summery; Cargo is cruft, no solution found yet.

I tried reusing a crate from the very same place it was built (see enclosed script). Anyhow, this does not work since cargo uses a different "metadata" value, even if noting changed. Based in the verbose output (cargo build -v …) I assume that some parameters of the "destination" build get included into this value.

This meets another observation; when building the sequoia suite, several crates are build several times - even if all builds are performed in the same environment.

Rust's build system is such a cruft - I really would like to throw it where it belongs: into the trash.

--
Regards
Hartmut Goebel

| Hartmut Goebel          | h.goe...@crazy-compilers.com               |
| www.crazy-compilers.com | compilers which you thought are impossible |

(use-modules
 (guix download)
 (guix packages)
 (guix build-system cargo)
 (gnu packages crates-io)
 (srfi srfi-1)
 (srfi srfi-26)
 (gnu packages crates-graphics)
 (gnu packages rust-apps))

(define-public rust-pretty-assertions-0.5
  (package
    (inherit rust-pretty-assertions-0.6)
    (name "rust-pretty-assertions")
    (version "0.5.1")
    (source
     (origin
       (method url-fetch)
       (uri (crate-uri "pretty_assertions" version))
       (file-name
        (string-append name "-" version ".tar.gz"))
       (sha256
          (base32 "1ins6swkpxmrh8q5h96h8nv0497d3dclsiyx2lyvqi6py0q980is"))))
    (build-system cargo-build-system)
    (arguments
     `(#:tests? #f
       #:cargo-inputs
       (("rust-ansi-term" ,rust-ansi-term-0.11)
        ("rust-difference" ,rust-difference-2))))))

;; /gnu/store/wknzymkfbfjbxwfd3djrn4hk9zdfgs56-rust-xmlparser-0.13.3 -- original
;; 
;; libxmlparser-f82b201ea4144ed3.rlib

(define-public myrust-xmlparser
  (package
    (inherit rust-xmlparser-0.13)
    (outputs '("out" "rlib"))
    (arguments
     `(#:skip-build? #f
       #:tests? #f
       #:cargo-build-flags (list "--release" "-vv")
       #:phases
       (modify-phases %standard-phases
         (add-after 'install 'install-rlib
           (lambda* (#:key outputs #:allow-other-keys)
             (let* ((rout (assoc-ref outputs "rlib"))
                    (dest (string-append rout "/rlib")))
               ;;(mkdir dest)
               ;;(for-each (cut install-file <> (string-append rout "/rlib"))
               (for-each (lambda (fn)
                           (install-file fn (string-append rout "/rlib")))
                         (find-files "target/release/deps" "\\.(rlib|rmeta)$"))
               )))
          ;; (add-after 'install 'fail
          ;;   (lambda _ #f))
    )))))

(define-public myrust-roxmltree
  (package
    (inherit rust-roxmltree-0.14)
    ;;(outputs '("out" "crate"))
    (inputs
     `(("rust-xmlparser" ,myrust-xmlparser "rlib")))
    (arguments
     `(#:skip-build? #f
       #:tests? #f
       ;;#:vendor-dir "/tmp/src"
       #:cargo-build-flags (list "--release" "-vv")
       #:cargo-inputs
       (("rust-xmlparser:src" ,rust-xmlparser-0.13)
        ("rust-pretty-assertions" ,rust-pretty-assertions-0.5))
       #:phases
       (modify-phases %standard-phases
         (add-after 'patch-cargo-checksums 'bring-in-rlib
           (lambda* (#:key inputs #:allow-other-keys)
             (let* ((rin (assoc-ref inputs "rust-xmlparser"))
                    (src (assoc-ref inputs "rust-xmlparser"))
                    (rlib (string-append rin "/rlib")))
               (mkdir "/tmp/guix-build-rust-xmlparser-0.13.3.drv-0/")
               (copy-recursively
               "guix-vendor/rust-xmlparser-0.13.3.tar.gz"
               "/tmp/guix-build-rust-xmlparser-0.13.3.drv-0/xmlparser-0.13.3")
               (rename-file
                "guix-vendor/rust-xmlparser-0.13.3.tar.gz"
                "../rust-xmlparser-0.13.3.tar.gz")
               (symlink
                "/tmp/guix-build-rust-xmlparser-0.13.3.drv-0/xmlparser-0.13.3"
                "guix-vendor/rust-xmlparser-0.13.3")
;;                (let ((port (open-file ".cargo/config" "w" #:encoding "utf-8")))
;;                  (display "
;; #paths = [\"/tmp/guix-build-rust-xmlparser-0.13.3.drv-0/xmlparser-0.13.3\"]

;; [source.crates-io]
;; replace-with = 'vendored-sources'

;; #[patch.crates-io]
;; #xmlparser = { path = '/tmp/guix-build-rust-xmlparser-0.13.3.drv-0/xmlparser-0.13.3' }

;; [source.vendored-sources]
;; directory = '" port)
;;                  (display (string-append (getcwd) "/guix-vendor") port)
;;                  (display "'
;; " port)
;;     (close-port port))
               ;; (substitute* ".cargo/config"
               ;;   (("\\.vendored-sources\\]" _)
               ;;    (string-append _ "\n[paths]"))
               (for-each (lambda (fn)
                           (install-file fn "target/release/deps"))
                         (pk (find-files rlib "\\.(rlib|rmeta)$")))
               #t
               )))
         (add-before 'install 'fail
           (lambda _ #f)))
    ))))


;;myrust-xmlparser
myrust-roxmltree

Reply via email to