diff mbox series

[bug#36841] build/cargo-build-system: Patch cargo checksums.

Message ID 20190729190422.6834-1-efraim@flashner.co.il
State Accepted
Headers show
Series [bug#36841] build/cargo-build-system: Patch cargo checksums. | expand

Commit Message

Efraim Flashner July 29, 2019, 7:04 p.m. UTC
* guix/build/cargo-build-system.scm (patch-cargo-checksums): New phase.
(%standard-phases): Add 'patch-cargo-checksums after
'patch-generated-file-shebangs.
---
 guix/build/cargo-build-system.scm | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

Comments

Ivan Petkov July 30, 2019, 1:44 a.m. UTC | #1
Hi Efraim,

> On Jul 29, 2019, at 12:04 PM, Efraim Flashner <efraim@flashner.co.il> wrote:
> 
> +;; After patching the 'patch-generated-file-shebangs phase any vendored crates
> +;; will have a mismatch on their checksum.
> +(define* (patch-cargo-checksums #:key
> +                                (vendor-dir "guix-vendor")
> +                                #:allow-other-keys)

[snip]

> +    (replace 'install install)
> +    (add-after 'patch-generated-file-shebangs 'patch-cargo-checksums patch-cargo-checksums)))

I can’t quite remember the order the phases run in off the top of my head. Would it be possible to
make the configure/checksum generation phase run after shebang-patching (or ensure the patching
happens first)? It would avoid having to checksum all the files twice that way…

—Ivan
Efraim Flashner July 30, 2019, 5:59 a.m. UTC | #2
On Mon, Jul 29, 2019 at 06:44:31PM -0700, Ivan Petkov wrote:
> Hi Efraim,
> 
> > On Jul 29, 2019, at 12:04 PM, Efraim Flashner <efraim@flashner.co.il> wrote:
> > 
> > +;; After patching the 'patch-generated-file-shebangs phase any vendored crates
> > +;; will have a mismatch on their checksum.
> > +(define* (patch-cargo-checksums #:key
> > +                                (vendor-dir "guix-vendor")
> > +                                #:allow-other-keys)
> 
> [snip]
> 
> > +    (replace 'install install)
> > +    (add-after 'patch-generated-file-shebangs 'patch-cargo-checksums patch-cargo-checksums)))
> 
> I can’t quite remember the order the phases run in off the top of my head. Would it be possible to
> make the configure/checksum generation phase run after shebang-patching (or ensure the patching
> happens first)? It would avoid having to checksum all the files twice that way…
> 
> —Ivan

I thought about it a bit more after I sent the patch, and I'm pretty
sure this is only needed when there's a Cargo.lock file in the build
directory. So in actuality it should be more like:

(when (file-exists? "Cargo.lock")
  (begin
    (delete-file "Cargo.lock")
    (invoke "cargo" "generate-lockfile")
    (patch-cargo-checksums ...)))

I'm going to close this bug/patch and re-submit it when I've given it a
bit more work so it doesn't do the expensive compute-checksums
computation on all builds.
diff mbox series

Patch

diff --git a/guix/build/cargo-build-system.scm b/guix/build/cargo-build-system.scm
index f38de16cf7..8e1ee62f65 100644
--- a/guix/build/cargo-build-system.scm
+++ b/guix/build/cargo-build-system.scm
@@ -2,6 +2,7 @@ 
 ;;; Copyright © 2016 David Craven <david@craven.ch>
 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2019 Ivan Petkov <ivanppetkov@gmail.com>
+;;; Copyright © 2019 Efraim Flashner <efraim@flashner.co.il>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -121,6 +122,23 @@  directory = '" port)
   (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
   #t)
 
+;; After patching the 'patch-generated-file-shebangs phase any vendored crates
+;; will have a mismatch on their checksum.
+(define* (patch-cargo-checksums #:key
+                                (vendor-dir "guix-vendor")
+                                #:allow-other-keys)
+  "Patch the checksums of the vendored crates after patching their shebangs."
+  (for-each
+    (lambda (filename)
+      (delete-file filename)
+      (let* ((dir (dirname filename)))
+        (display (string-append
+                   "patch-cargo-checksums: generate-checksums for "
+                   dir "\n"))
+        (generate-checksums dir)))
+    (find-files "guix-vendor" ".cargo-checksum.json"))
+  #t)
+
 (define* (build #:key
                 skip-build?
                 (cargo-build-flags '("--release"))
@@ -162,7 +180,8 @@  directory = '" port)
     (replace 'configure configure)
     (replace 'build build)
     (replace 'check check)
-    (replace 'install install)))
+    (replace 'install install)
+    (add-after 'patch-generated-file-shebangs 'patch-cargo-checksums patch-cargo-checksums)))
 
 (define* (cargo-build #:key inputs (phases %standard-phases)
                       #:allow-other-keys #:rest args)