guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

195/276: build: cargo-build-system: Reset timestamps in crates.


From: guix-commits
Subject: 195/276: build: cargo-build-system: Reset timestamps in crates.
Date: Wed, 18 Oct 2023 04:50:03 -0400 (EDT)

efraim pushed a commit to branch rust-team
in repository guix.

commit fafbad0ce2dc9d94bc03b5e9e5ec8dad759ca929
Author: Efraim Flashner <efraim@flashner.co.il>
AuthorDate: Wed Oct 4 12:20:14 2023 +0300

    build: cargo-build-system: Reset timestamps in crates.
    
    This fixes reproducibility in rust crates from the package phase,
    see <https://issues.guix.gnu.org/50015>.
    
    * guix/build/cargo-build-system.scm (package): After running 'cargo
    package' on the source unpack the tarball, reset the timestamps and
    repack it.
---
 guix/build/cargo-build-system.scm | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/guix/build/cargo-build-system.scm 
b/guix/build/cargo-build-system.scm
index 9094ea41d1..8bf6ba510b 100644
--- a/guix/build/cargo-build-system.scm
+++ b/guix/build/cargo-build-system.scm
@@ -242,7 +242,32 @@ directory = '" 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" ,@cargo-package-flags))))
+        (apply invoke `("cargo" "package" ,@cargo-package-flags))
+
+        ;; Then unpack the crate, reset the timestamp of all contained files, 
and
+        ;; repack them.  This is necessary to ensure that they are 
reproducible.
+        (with-directory-excursion "target/package"
+          (for-each
+            (lambda (crate)
+              (invoke "tar" "xf" crate)
+              (delete-file crate)
+              ;; Some of the crate names have underscores, so we need to
+              ;; search the current directory to find the unpacked crate.
+              (let ((dir
+                      (car (scandir "."
+                                    (lambda (file)
+                                      (and (not (member file '("." "..")))
+                                           (not (string-suffix? ".crate" 
file))))))))
+                ;; XXX: copied from (gnu build install)
+                (for-each (lambda (file)
+                            (let ((s (lstat file)))
+                              (unless (eq? (stat:type s) 'symlink)
+                                (utime file 0 0 0 0))))
+                          (find-files dir #:directories? #t))
+                (apply invoke "tar" "czf" (string-append dir ".crate")
+                       (find-files dir #:directories? #t))
+                (delete-file-recursively dir)))
+            (find-files "." "\\.crate$")))))
     (format #t "Not installing cargo sources, skipping `cargo package`.~%"))
   #t)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]