unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] WIP patches for the rust importer
@ 2019-11-26 12:04 Efraim Flashner
  2019-11-27 20:06 ` mjbecze
  0 siblings, 1 reply; 15+ messages in thread
From: Efraim Flashner @ 2019-11-26 12:04 UTC (permalink / raw)
  To: guix-devel


[-- Attachment #1.1: Type: text/plain, Size: 2830 bytes --]

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   <efraim@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

[-- Attachment #1.2: 0001-import-crate-Don-t-include-optional-dependencies.patch --]
[-- Type: text/plain, Size: 2169 bytes --]

From ef54ba410edd25fcda7f0dc326346a7e4b366d0e Mon Sep 17 00:00:00 2001
From: Efraim Flashner <efraim@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 <david@craven.ch>
 ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2019 Martin Becze <mjbecze@riseup.net>
+;;; Copyright © 2019 Efraim Flashner <efraim@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


[-- Attachment #1.3: 0003-import-crate-Honor-versioned-dependencies-when-impor.patch --]
[-- Type: text/plain, Size: 2474 bytes --]

From c9c78e0f1e6a88d53770ae94ada473cd9851552d Mon Sep 17 00:00:00 2001
From: Efraim Flashner <efraim@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))))
+
 \f
 ;;;
 ;;; Updater
-- 
2.24.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2019-12-04 22:08 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-26 12:04 [PATCH] WIP patches for the rust importer Efraim Flashner
2019-11-27 20:06 ` mjbecze
2019-11-27 20:58   ` Efraim Flashner
2019-11-28  0:36     ` mjbecze
2019-11-28 12:22       ` Efraim Flashner
2019-11-29 12:59         ` Martin Becze
2019-12-01  8:54           ` Efraim Flashner
2019-12-02  2:32             ` Martin Becze
2019-11-29 15:59         ` Martin Becze
2019-12-01  8:59           ` Efraim Flashner
2019-12-02  3:17             ` Martin Becze
2019-12-02  4:01               ` Ivan Petkov
2019-12-02 23:10                 ` Martin Becze
2019-12-04  2:40                   ` Ivan Petkov
2019-12-04 22:08                     ` Martin Becze

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).