GNU bug report logs - #39959
[PATCH] cargo-build-system: Accept a #:features argument

Previous Next

Package: guix-patches;

Reported by: Jakub Kądziołka <kuba <at> kadziolka.net>

Date: Fri, 6 Mar 2020 21:51:02 UTC

Severity: normal

Tags: patch

Done: Jakub Kądziołka <kuba <at> kadziolka.net>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 39959 in the body.
You can then email your comments to 39959 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#39959; Package guix-patches. (Fri, 06 Mar 2020 21:51:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jakub Kądziołka <kuba <at> kadziolka.net>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Fri, 06 Mar 2020 21:51:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Jakub Kądziołka <kuba <at> kadziolka.net>
To: guix-patches <at> gnu.org
Subject: [PATCH] cargo-build-system: Accept a #:features argument
Date: Fri,  6 Mar 2020 22:44:49 +0100
* guix/build/cargo-build-system.scm (build, install): Pass the features
  to cargo.
  (check): Remove indirection layer for consistency with build and
  install.
* guix/build-system/cargo.scm (cargo-build): New argument; pass it into
  the builder.
* gnu/packages/rust-apps.scm (ripgrep): Use the new argument instead of
  a custom phase.
---

I am looking into packaging rustup, which, like ripgrep, also needs to
pass a --features argument to cargo. This suggests that proper support
for it in the build system is warranted.

In #39445, Efraim suggested using cargo-build-flags as an argument to
"cargo install". Alas, the --release flag is not accepted by "cargo
install" at all, which makes a design like this necessary.

Unresolved question: can this be merged directly to master? There are
exactly 300 hits for cargo-build-system in
gnu/packages/{rust-apps,crates-io}.scm if we exclude all the libraries
with #:skip-build? #t.

 gnu/packages/rust-apps.scm        | 14 ++------------
 guix/build-system/cargo.scm       |  2 ++
 guix/build/cargo-build-system.scm | 12 ++++++++----
 3 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/gnu/packages/rust-apps.scm b/gnu/packages/rust-apps.scm
index 72c982f23c..fa02ded8ec 100644
--- a/gnu/packages/rust-apps.scm
+++ b/gnu/packages/rust-apps.scm
@@ -243,18 +243,8 @@ provides defaults for 80% of the use cases.")
                 (install-file manpage (string-append
                                         (assoc-ref outputs "out")
                                         "/share/man/man1"))))
-             #t))
-         (replace 'install
-           ;; Adapted from (guix build cargo-build-system). The flags need to
-           ;; be passed to `cargo install' too, as otherwise it will build
-           ;; another binary, without the features.
-           (lambda* (#:key outputs #:allow-other-keys)
-             (let ((out (assoc-ref outputs "out")))
-               (mkdir-p out)
-               (setenv "CARGO_TARGET_DIR" "./target")
-               (invoke "cargo" "install" "--path" "." "--root" out
-                       "--features" "pcre2")))))
-       #:cargo-build-flags '("--release" "--features" "pcre2")))
+             #t)))
+       #:features '("pcre2")))
     (native-inputs
      `(("asciidoc" ,asciidoc)
        ("pcre2" ,pcre2)
diff --git a/guix/build-system/cargo.scm b/guix/build-system/cargo.scm
index 1e8b3a578e..2b5f301dc2 100644
--- a/guix/build-system/cargo.scm
+++ b/guix/build-system/cargo.scm
@@ -76,6 +76,7 @@ to NAME and VERSION."
                       (vendor-dir "guix-vendor")
                       (cargo-build-flags ''("--release"))
                       (cargo-test-flags ''("--release"))
+                      (features ''())
                       (skip-build? #f)
                       (phases '(@ (guix build cargo-build-system)
                                   %standard-phases))
@@ -104,6 +105,7 @@ to NAME and VERSION."
                     #:vendor-dir ,vendor-dir
                     #:cargo-build-flags ,cargo-build-flags
                     #:cargo-test-flags ,cargo-test-flags
+                    #:features ,features
                     #:skip-build? ,skip-build?
                     #:tests? ,(and tests? (not skip-build?))
                     #:phases ,phases
diff --git a/guix/build/cargo-build-system.scm b/guix/build/cargo-build-system.scm
index 0721989589..0e2faee3c1 100644
--- a/guix/build/cargo-build-system.scm
+++ b/guix/build/cargo-build-system.scm
@@ -140,11 +140,14 @@ directory = '" port)
 
 (define* (build #:key
                 skip-build?
+                features
                 (cargo-build-flags '("--release"))
                 #:allow-other-keys)
   "Build a given Cargo package."
   (or skip-build?
-      (apply invoke `("cargo" "build" ,@cargo-build-flags))))
+      (apply invoke "cargo" "build"
+             "--features" (string-join features)
+             cargo-build-flags)))
 
 (define* (check #:key
                 tests?
@@ -152,10 +155,10 @@ directory = '" port)
                 #:allow-other-keys)
   "Run tests for a given Cargo package."
   (if tests?
-      (apply invoke `("cargo" "test" ,@cargo-test-flags))
+      (apply invoke "cargo" "test" cargo-test-flags)
       #t))
 
-(define* (install #:key inputs outputs skip-build? #:allow-other-keys)
+(define* (install #:key inputs outputs skip-build? features #:allow-other-keys)
   "Install a given Cargo package."
   (let* ((out (assoc-ref outputs "out")))
     (mkdir-p out)
@@ -168,7 +171,8 @@ directory = '" port)
     ;; otherwise cargo will raise an error.
     (or skip-build?
         (not (has-executable-target?))
-        (invoke "cargo" "install" "--path" "." "--root" out))))
+        (invoke "cargo" "install" "--path" "." "--root" out
+                "--features" (string-join features)))))
 
 (define %standard-phases
   (modify-phases gnu:%standard-phases
-- 
2.25.1





Reply sent to Jakub Kądziołka <kuba <at> kadziolka.net>:
You have taken responsibility. (Mon, 23 Mar 2020 22:29:02 GMT) Full text and rfc822 format available.

Notification sent to Jakub Kądziołka <kuba <at> kadziolka.net>:
bug acknowledged by developer. (Mon, 23 Mar 2020 22:29:02 GMT) Full text and rfc822 format available.

Message #10 received at 39959-done <at> debbugs.gnu.org (full text, mbox):

From: Jakub Kądziołka <kuba <at> kadziolka.net>
To: 39959-done <at> debbugs.gnu.org
Subject: Done: [PATCH] cargo-build-system: Accept a #:features argument
Date: Mon, 23 Mar 2020 23:28:46 +0100
[Message part 1 (text/plain, inline)]
Pushed to staging as 927c2518465579d48315e8e6b5102097c146fece.
[signature.asc (application/pgp-signature, inline)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 21 Apr 2020 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 3 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.