cargo-build-system: Accept a #:features argument

* 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.
This commit is contained in:
Jakub Kądziołka 2020-03-06 22:34:53 +01:00
parent 34ad1a550c
commit 927c251846
No known key found for this signature in database
GPG Key ID: E315A75846131564
3 changed files with 14 additions and 16 deletions

View File

@ -244,18 +244,8 @@ provides defaults for 80% of the use cases.")
(install-file manpage (string-append (install-file manpage (string-append
(assoc-ref outputs "out") (assoc-ref outputs "out")
"/share/man/man1")))) "/share/man/man1"))))
#t)) #t)))
(replace 'install #:features '("pcre2")))
;; 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")))
(native-inputs (native-inputs
`(("asciidoc" ,asciidoc) `(("asciidoc" ,asciidoc)
("pcre2" ,pcre2) ("pcre2" ,pcre2)

View File

@ -4,6 +4,7 @@
;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org> ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
;;; Copyright © 2016 David Craven <david@craven.ch> ;;; Copyright © 2016 David Craven <david@craven.ch>
;;; Copyright © 2019 Ivan Petkov <ivanppetkov@gmail.com> ;;; Copyright © 2019 Ivan Petkov <ivanppetkov@gmail.com>
;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -76,6 +77,7 @@ to NAME and VERSION."
(vendor-dir "guix-vendor") (vendor-dir "guix-vendor")
(cargo-build-flags ''("--release")) (cargo-build-flags ''("--release"))
(cargo-test-flags ''("--release")) (cargo-test-flags ''("--release"))
(features ''())
(skip-build? #f) (skip-build? #f)
(phases '(@ (guix build cargo-build-system) (phases '(@ (guix build cargo-build-system)
%standard-phases)) %standard-phases))
@ -104,6 +106,7 @@ to NAME and VERSION."
#:vendor-dir ,vendor-dir #:vendor-dir ,vendor-dir
#:cargo-build-flags ,cargo-build-flags #:cargo-build-flags ,cargo-build-flags
#:cargo-test-flags ,cargo-test-flags #:cargo-test-flags ,cargo-test-flags
#:features ,features
#:skip-build? ,skip-build? #:skip-build? ,skip-build?
#:tests? ,(and tests? (not skip-build?)) #:tests? ,(and tests? (not skip-build?))
#:phases ,phases #:phases ,phases

View File

@ -3,6 +3,7 @@
;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com> ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
;;; Copyright © 2019 Ivan Petkov <ivanppetkov@gmail.com> ;;; Copyright © 2019 Ivan Petkov <ivanppetkov@gmail.com>
;;; Copyright © 2019, 2020 Efraim Flashner <efraim@flashner.co.il> ;;; Copyright © 2019, 2020 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -140,11 +141,14 @@ directory = '" port)
(define* (build #:key (define* (build #:key
skip-build? skip-build?
features
(cargo-build-flags '("--release")) (cargo-build-flags '("--release"))
#:allow-other-keys) #:allow-other-keys)
"Build a given Cargo package." "Build a given Cargo package."
(or skip-build? (or skip-build?
(apply invoke `("cargo" "build" ,@cargo-build-flags)))) (apply invoke "cargo" "build"
"--features" (string-join features)
cargo-build-flags)))
(define* (check #:key (define* (check #:key
tests? tests?
@ -152,10 +156,10 @@ directory = '" port)
#:allow-other-keys) #:allow-other-keys)
"Run tests for a given Cargo package." "Run tests for a given Cargo package."
(if tests? (if tests?
(apply invoke `("cargo" "test" ,@cargo-test-flags)) (apply invoke "cargo" "test" cargo-test-flags)
#t)) #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." "Install a given Cargo package."
(let* ((out (assoc-ref outputs "out"))) (let* ((out (assoc-ref outputs "out")))
(mkdir-p out) (mkdir-p out)
@ -168,7 +172,8 @@ directory = '" port)
;; otherwise cargo will raise an error. ;; otherwise cargo will raise an error.
(or skip-build? (or skip-build?
(not (has-executable-target?)) (not (has-executable-target?))
(invoke "cargo" "install" "--path" "." "--root" out)))) (invoke "cargo" "install" "--path" "." "--root" out
"--features" (string-join features)))))
(define %standard-phases (define %standard-phases
(modify-phases gnu:%standard-phases (modify-phases gnu:%standard-phases