guix_mirror_bot pushed a commit to branch gnome-team
in repository guix.

commit 98c33ae52a513d93921d7180d9ed5d5bf48eb4be
Author: Hilton Chain <[email protected]>
AuthorDate: Thu Feb 27 19:58:04 2025 +0800

    build-system: cargo: Support packaging Cargo workspace.
    
    * guix/build-system/cargo.scm (cargo-build, cargo-cross-build)
    [#:cargo-package-crates]: New argument.
    * guix/build/cargo-build-system.scm (package): Use it.
    * doc/guix.texi (Build Systems)[cargo-build-system]: Document it.
    
    Change-Id: I45ccd95e90827d47127015cb0bda2d41f792335b
---
 doc/guix.texi                     |  7 +++++++
 guix/build-system/cargo.scm       |  4 ++++
 guix/build/cargo-build-system.scm | 21 +++++++++++++++++++--
 3 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 10cd50b5fa..f3792b1469 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -9513,6 +9513,13 @@ to create a source crate for future use.  The 
@code{install} phase installs
 the binaries defined by the crate.  Unless @code{install-source? #f} is
 defined it will also install a source crate repository of itself and unpacked
 sources, to ease in future hacking on rust packages.
+
+This build system supports cargo workspaces.  Parameter
+@code{#:cargo-package-crates} (default: @code{''()}) allows specifying names of
+library crates to package in the @code{package} phase.  Specified crates are
+packaged from left to right, in case there's dependency among them.  For
+example, specifying @code{''("pcre2-sys" "pcre2")} will package
+@code{"pcre2-sys"} first and then @code{"pcre2"}.
 @end defvar
 
 @defvar chicken-build-system
diff --git a/guix/build-system/cargo.scm b/guix/build-system/cargo.scm
index f2ffc67879..2c47c1feaf 100644
--- a/guix/build-system/cargo.scm
+++ b/guix/build-system/cargo.scm
@@ -98,6 +98,7 @@ to NAME and VERSION."
                       (vendor-dir "guix-vendor")
                       (cargo-build-flags ''("--release"))
                       (cargo-test-flags ''())
+                      (cargo-package-crates ''())
                       (cargo-package-flags ''("--no-metadata" "--no-verify"))
                       (features ''())
                       (skip-build? #f)
@@ -126,6 +127,7 @@ to NAME and VERSION."
                        #:vendor-dir #$vendor-dir
                        #:cargo-build-flags #$(sexp->gexp cargo-build-flags)
                        #:cargo-test-flags #$(sexp->gexp cargo-test-flags)
+                       #:cargo-package-crates #$(sexp->gexp 
cargo-package-crates)
                        #:cargo-package-flags #$(sexp->gexp cargo-package-flags)
                        #:cargo-target #$(cargo-triplet system)
                        #:features #$(sexp->gexp features)
@@ -158,6 +160,7 @@ to NAME and VERSION."
                             (vendor-dir "guix-vendor")
                             (cargo-build-flags ''("--release"))
                             (cargo-test-flags ''())
+                            (cargo-package-crates ''())
                             (cargo-package-flags ''("--no-metadata" 
"--no-verify"))
                             (cargo-target (cargo-triplet (or target system)))
                             (features ''())
@@ -189,6 +192,7 @@ to NAME and VERSION."
                        #:vendor-dir #$vendor-dir
                        #:cargo-build-flags #$(sexp->gexp cargo-build-flags)
                        #:cargo-test-flags #$(sexp->gexp cargo-test-flags)
+                       #:cargo-package-crates #$(sexp->gexp 
cargo-package-crates)
                        #:cargo-package-flags #$(sexp->gexp cargo-package-flags)
                        #:cargo-target #$(cargo-triplet (or target system))
                        #:features #$(sexp->gexp features)
diff --git a/guix/build/cargo-build-system.scm 
b/guix/build/cargo-build-system.scm
index c37fd70418..85745d4d91 100644
--- a/guix/build/cargo-build-system.scm
+++ b/guix/build/cargo-build-system.scm
@@ -302,11 +302,16 @@ directory = '" vendor-dir "'") port)
                   source
                   skip-build?
                   install-source?
+                  (cargo-package-crates '())
                   (cargo-package-flags '("--no-metadata" "--no-verify"))
+                  (vendor-dir "guix-vendor")
                   #:allow-other-keys)
   "Run 'cargo-package' for a given Cargo package."
   (if install-source?
-    (if skip-build?
+    ;; NOTE: Cargo workspace packaging support:
+    ;; #:install-source? #t + #:cargo-package-crates.
+    (if (and (null? cargo-package-crates)
+             skip-build?)
       (begin
         (install-file source "target/package")
         (with-directory-excursion "target/package"
@@ -324,7 +329,19 @@ directory = '" vendor-dir "'") port)
         ;;error: invalid inclusion of reserved file name Cargo.toml.orig in 
package source
         (when (file-exists? "Cargo.toml.orig")
           (delete-file "Cargo.toml.orig"))
-        (apply invoke `("cargo" "package" "--offline" ,@cargo-package-flags))
+
+        (if (null? cargo-package-crates)
+            (apply invoke `("cargo" "package" "--offline" 
,@cargo-package-flags))
+            (for-each
+             (lambda (pkg)
+               (apply invoke "cargo" "package" "--offline" "--package" pkg
+                      cargo-package-flags)
+               (for-each
+                (lambda (crate)
+                  (invoke "tar" "xzf" crate "-C" vendor-dir))
+                (find-files "target/package" "\\.crate$"))
+               (patch-cargo-checksums #:vendor-dir vendor-dir))
+             cargo-package-crates))
 
         ;; Then unpack the crate, reset the timestamp of all contained files, 
and
         ;; repack them.  This is necessary to ensure that they are 
reproducible.

Reply via email to