[bug#75325,rust-team,2/2] build-system: cargo: add-dependencies: Silence warning.

Message ID 2929f9484a26fba24961dfd7fecd4180a7964775.1735932581.git.herman@rimm.ee
State New
Headers
Series Add add-dependencies procedure. |

Commit Message

Herman Rimm Jan. 3, 2025, 7:40 p.m. UTC
  * guix/build-system/cargo.scm (add-dependencies): Silence warning.

Change-Id: I8691766fc19073719e75c05eb5bfbce45ffc9b80
---
 guix/build-system/cargo.scm | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
  

Patch

diff --git a/guix/build-system/cargo.scm b/guix/build-system/cargo.scm
index b22b9247a1c..877ebaec135 100644
--- a/guix/build-system/cargo.scm
+++ b/guix/build-system/cargo.scm
@@ -34,6 +34,7 @@  (define-module (guix build-system cargo)
   #:use-module (guix platform)
   #:use-module (guix build-system)
   #:use-module (guix build-system gnu)
+  #:use-module (ice-9 format)
   #:use-module (ice-9 match)
   #:use-module (ice-9 vlist)
   #:use-module (srfi srfi-1)
@@ -51,13 +52,20 @@  (define-module (guix build-system cargo)
 (define* (add-dependencies dependencies)
   "DEPENDENCIES is a list of (crate version features).  It is formatted
 and appendended to Cargo.toml."
-  #~(let ((port (open-file "Cargo.toml" "a")))
-      (format port "
+  (let ((dependencies
+         (map (match-lambda
+                ((crate version ()) (list crate version #f))
+                ((crate version (? pair? features))
+                 (list crate version (format #f "~{~s~^,~}" features)))
+                (dep dep))
+              dependencies)))
+    #~(let ((port (open-file "Cargo.toml" "a")))
+        (format port "
 ~:{[dev-dependencies.~a]
 version = ~s
-~@[features = [~{~s~^,~}]~]~%~}"
-              '#$dependencies)
-      (close port)))
+~@[features = [~a]~]~%~}"
+                '#$dependencies)
+        (close port))))
 
 (define %crate-base-url
   (make-parameter "https://crates.io"))