Subject: [PATCH rust-team 01/46] build-system: cargo: Add #:cargo-native-inputs argument.

From: Tomas Volf <[email-masked]>
Date: Thu, 15 Feb 2024 21:26:14 +0100

If crate A used by application B needs some package (for example protobuf in
my case) during a build, there was no way to propagate the information.  The
application B would need to explicitly add (native-inputs).  And each user of
crate A would need to do that.

I think that is not optimal, therefore this commit adds new
 #:cargo-native-inputs argument to the cargo-build-system.  It allows
propagating native dependencies to users of the crates.

* guix/build-system/cargo.scm (package-cargo-native-inputs): New procedure.
(lower): New keyword argument cargo-native-inputs.
(lower)[private-keywords]: Add #:cargo-native-inputs.
(lower)[bag]<build-inputs>: Use cargo-native-inputs.
* doc/guix.texi: Document it.

Change-Id: I39c35db4d17842cd7633cf2c1b7d90b74de07679
---
 doc/guix.texi               |  4 +++-
 guix/build-system/cargo.scm | 17 ++++++++++++++++-
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index bb0af26d93..3d43ed6dd5 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -9428,7 +9428,9 @@ Build Systems
 evaluate to a path to a gzipped tarball which includes a @code{Cargo.toml}
 file at its root, or it will be ignored.  Similarly, cargo dev-dependencies
 should be added to the package definition via the
-@code{#:cargo-development-inputs} parameter.
+@code{#:cargo-development-inputs} parameter.  Additionally, if some
+native dependencies are required during a build of a dependent package,
+you can use @code{#:cargo-native-inputs} to specify such packages.
 
 In its @code{configure} phase, this build system will make any source inputs
 specified in the @code{#:cargo-inputs} and @code{#:cargo-development-inputs}
diff --git a/guix/build-system/cargo.scm b/guix/build-system/cargo.scm
index c029cc1dda..170a1f70b6 100644
--- a/guix/build-system/cargo.scm
+++ b/guix/build-system/cargo.scm
@@ -207,6 +207,12 @@ (define (package-cargo-development-inputs p)
       cargo-development-inputs)
     (package-arguments p)))
 
+(define (package-cargo-native-inputs p)
+  (apply
+    (lambda* (#:key (cargo-native-inputs '()) #:allow-other-keys)
+      cargo-native-inputs)
+    (package-arguments p)))
+
 (define (crate-closure inputs)
   "Return the closure of INPUTS when considering the 'cargo-inputs' and
 'cargod-dev-deps' edges.  Omit duplicate inputs, except for those
@@ -308,13 +314,14 @@ (define* (lower name
                 (rust-sysroot (default-rust-sysroot target))
                 (cargo-inputs '())
                 (cargo-development-inputs '())
+                (cargo-native-inputs '())
                 #:allow-other-keys
                 #:rest arguments)
   "Return a bag for NAME."
 
   (define private-keywords
     `(#:rust #:inputs #:native-inputs #:outputs
-      #:cargo-inputs #:cargo-development-inputs
+      #:cargo-inputs #:cargo-development-inputs #:cargo-native-inputs
       #:rust-sysroot
       ,@(if target '() '(#:target))))
 
@@ -338,6 +345,14 @@ (define* (lower name
                     ,@(if target '() inputs)
                     ;,@inputs
 
+                    ,@(apply append
+                             cargo-native-inputs
+                             (map (match-lambda
+                                    ((tag pkg)
+                                     (package-cargo-native-inputs pkg)))
+                                  (crate-closure (append cargo-inputs
+                                                         cargo-development-inputs))))
+
                     ,@(if target
                         ;; Use the standard cross inputs of
                         ;; 'gnu-build-system'.
-- 
2.41.0