Attached are two patches. The first one searches through the listed
dependencies and removes the ones that are marked as optional. This
(potentially) decreases the size of each crate and the number of
dependencies.

Before:
(package
  (name "rust-serde")
  (version "1.0.103")
  (source
    (origin
      (method url-fetch)
      (uri (crate-uri "serde" version))
      (file-name
        (string-append name "-" version ".tar.gz"))
      (sha256
        (base32
          "00ip3xy09nk6c2b47ky1m5379yjmwk6n3sr2vmblp478p1xgj5qj"))))
  (build-system cargo-build-system)
  (arguments
    `(#:cargo-inputs
      (("rust-serde-derive" ,rust-serde-derive))
      #:cargo-development-inputs
      (("rust-serde-derive" ,rust-serde-derive))))
  (home-page "https://serde.rs";)
  (synopsis
    "A generic serialization/deserialization framework")
  (description
    "This package provides a generic serialization/deserialization framework")
  (license (list license:expat license:asl2.0)))

After:
<--snip..>
(arguments
 `(#:cargo-development-inputs
 (("rust-serde-derive" ,rust-serde-derive))))
<--snip-->

The second patch takes the version information from the dependencies and
adds it to the cargo-inputs and cargo-development-inputs, matching how
we now have the crates packaged:

Before:
(package
  (name "rust-serde-derive")
  (version "1.0.103")
  (source
    (origin
      (method url-fetch)
      (uri (crate-uri "serde-derive" version))
      (file-name
        (string-append name "-" version ".tar.gz"))
      (sha256
        (base32
          "1l2icqq548dmq5bn278zb2vj725znj4h4ms89w3b0r1fkbpzmim8"))))
  (build-system cargo-build-system)
  (arguments
    `(#:cargo-inputs
      (("rust-proc-macro2" ,rust-proc-macro2)
       ("rust-quote" ,rust-quote)
       ("rust-syn" ,rust-syn))
      #:cargo-development-inputs
      (("rust-serde" ,rust-serde))))
  (home-page "https://serde.rs";)
  (synopsis
    "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]")
  (description
    "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]")
  (license (list license:expat license:asl2.0)))

After:
<--snip-->
(arguments
 `(#:cargo-inputs
   (("rust-proc-macro2-1.0" ,rust-proc-macro2-1.0)
    ("rust-quote-1.0" ,rust-quote-1.0)
    ("rust-syn-1.0" ,rust-syn-1.0))
   #:cargo-development-inputs
   (("rust-serde-1.0" ,rust-serde-1.0))))
<--snip-->

Unfortunately, this also breaks the recursive crate importer. I'm going
to continue working on it, but I could use some help getting the
recursive aspect of it working.

-- 
Efraim Flashner   <efr...@flashner.co.il>   אפרים פלשנר
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
From ef54ba410edd25fcda7f0dc326346a7e4b366d0e Mon Sep 17 00:00:00 2001
From: Efraim Flashner <efr...@flashner.co.il>
Date: Mon, 25 Nov 2019 17:58:05 +0200
Subject: [PATCH 1/3] import: crate: Don't include optional dependencies.

* guix/import/crate.scm (define-json-mapping): Match 'optional' keyword.
(crate->guix-package): Remove optional dependencies from listed
dependencies.
---
 guix/import/crate.scm | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/guix/import/crate.scm b/guix/import/crate.scm
index 8dc014d232..9eca176b08 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2016 David Craven <da...@craven.ch>
 ;;; Copyright © 2019 Ludovic Courtès <l...@gnu.org>
 ;;; Copyright © 2019 Martin Becze <mjbe...@riseup.net>
+;;; Copyright © 2019 Efraim Flashner <efr...@flashner.co.il>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -87,6 +88,7 @@
   (id            crate-dependency-id "crate_id")  ;string
   (kind          crate-dependency-kind "kind"     ;'normal | 'dev
                  string->symbol)
+  (optional      crate-dependency-optional "optional") ; 'true | 'false
   (requirement   crate-dependency-requirement "req")) ;string
 
 (define (lookup-crate name)
@@ -197,6 +199,9 @@ latest version of CRATE-NAME."
   (define (normal-dependency? dependency)
     (eq? (crate-dependency-kind dependency) 'normal))
 
+  (define (optional-dependency? dependency)
+    (eq? (crate-dependency-optional dependency) #t))
+
   (define crate
     (lookup-crate crate-name))
 
@@ -211,7 +216,8 @@ latest version of CRATE-NAME."
           (crate-versions crate)))
 
   (and crate version*
-       (let* ((dependencies   (crate-version-dependencies version*))
+       (let* ((all-deps       (crate-version-dependencies version*))
+              (dependencies   (remove optional-dependency? all-deps))
               (dep-crates     (filter normal-dependency? dependencies))
               (dev-dep-crates (remove normal-dependency? dependencies))
               (cargo-inputs   (sort (map crate-dependency-id dep-crates)
-- 
2.24.0

From c9c78e0f1e6a88d53770ae94ada473cd9851552d Mon Sep 17 00:00:00 2001
From: Efraim Flashner <efr...@flashner.co.il>
Date: Tue, 26 Nov 2019 11:46:34 +0200
Subject: [PATCH 3/3] import: crate: Honor versioned dependencies when
 importing crates.

* guix/import.crate.scm (crate-name->package-name+version,
cleaned-version, crate-name+version): New variables.
(crate->guix-package): Use crate-name+version for cargo-inputs and
cargo-development-inputs.
---
 guix/import/crate.scm | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/guix/import/crate.scm b/guix/import/crate.scm
index 9eca176b08..7be622cf24 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -220,10 +220,10 @@ latest version of CRATE-NAME."
               (dependencies   (remove optional-dependency? all-deps))
               (dep-crates     (filter normal-dependency? dependencies))
               (dev-dep-crates (remove normal-dependency? dependencies))
-              (cargo-inputs   (sort (map crate-dependency-id dep-crates)
+              (cargo-inputs   (sort (map crate-name+version dep-crates)
                                     string-ci<?))
               (cargo-development-inputs
-               (sort (map crate-dependency-id dev-dep-crates)
+               (sort (map crate-name+version dev-dep-crates)
                      string-ci<?)))
          (values
           (make-crate-sexp #:name crate-name
@@ -258,6 +258,28 @@ latest version of CRATE-NAME."
 (define (crate-name->package-name name)
   (string-append "rust-" (string-join (string-split name #\_) "-")))
 
+(define (crate-name+version->package-name+version name version)
+  (string-append "rust-" (string-join (string-split name #\_) "-")
+                 "-" (version-major+minor version)))
+
+(define (cleaned-version version)
+  (match (string-ref version 0)
+    ((or #\^ #\=)
+     (cleaned-version (substring version 1)))
+    (#\  ; an actual space
+     (cleaned-version (substring version 1)))
+    (char-set-contains? char-set:digit
+     (if (string-contains version ".")
+         (version-major+minor version)
+         version))
+    (_
+      (cleaned-version (substring version 1)))
+    ))
+
+(define (crate-name+version crate)
+  (string-append (crate-dependency-id crate) "-"
+                 (cleaned-version (crate-dependency-requirement crate))))
+
 
 ;;;
 ;;; Updater
-- 
2.24.0

Attachment: signature.asc
Description: PGP signature

Reply via email to