From c2ac2e3f383ebf22a1049ca32f54656f14e56c48 Mon Sep 17 00:00:00 2001 From: Efraim Flashner Date: Sat, 30 Sep 2023 23:48:56 +0300 Subject: build: cargo-build-system: Check for pregenerated files. * guix/build/cargo-build-system.scm (check-for-pregenerated-files): New procedure. (%standard-phases): Add 'check-for-pregenerated-files phase between 'unpack and 'unpack-rust-crates. --- guix/build/cargo-build-system.scm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'guix/build') diff --git a/guix/build/cargo-build-system.scm b/guix/build/cargo-build-system.scm index fbba554e9b..9094ea41d1 100644 --- a/guix/build/cargo-build-system.scm +++ b/guix/build/cargo-build-system.scm @@ -111,6 +111,13 @@ Cargo.toml file present at its root." (define (rust-package? name) (string-prefix? "rust-" name)) +(define* (check-for-pregenerated-files #:rest _) + "Check the source code for files which are known to generally be bundled +libraries or executables." + (let ((pregenerated-files (find-files "." "\\.(a|dll|exe|lib)$"))) + (when (not (null-list? pregenerated-files)) + (error "Possible pre-generated files found:" pregenerated-files)))) + (define* (configure #:key inputs (vendor-dir "guix-vendor") #:allow-other-keys) @@ -285,7 +292,8 @@ directory = '" port) (replace 'check check) (replace 'install install) (add-after 'build 'package package) - (add-after 'unpack 'unpack-rust-crates unpack-rust-crates) + (add-after 'unpack 'check-for-pregenerated-files check-for-pregenerated-files) + (add-after 'check-for-pregenerated-files 'unpack-rust-crates unpack-rust-crates) (add-after 'patch-generated-file-shebangs 'patch-cargo-checksums patch-cargo-checksums))) (define* (cargo-build #:key inputs (phases %standard-phases) -- cgit v1.2.3 From fafbad0ce2dc9d94bc03b5e9e5ec8dad759ca929 Mon Sep 17 00:00:00 2001 From: Efraim Flashner Date: Wed, 4 Oct 2023 12:20:14 +0300 Subject: build: cargo-build-system: Reset timestamps in crates. This fixes reproducibility in rust crates from the package phase, see . * 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(-) (limited to 'guix/build') 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) -- cgit v1.2.3 From 163592c8431e25a807396576b0956f0c97640c41 Mon Sep 17 00:00:00 2001 From: Efraim Flashner Date: Wed, 4 Oct 2023 16:06:42 +0300 Subject: build: cargo-build-system: Strip enough prefix in package. * guix/build/cargo-build-system.scm (package): When using the source as the packaged crate also strip the 'rust-' prefix. --- guix/build/cargo-build-system.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guix/build') diff --git a/guix/build/cargo-build-system.scm b/guix/build/cargo-build-system.scm index 8bf6ba510b..e54882be34 100644 --- a/guix/build/cargo-build-system.scm +++ b/guix/build/cargo-build-system.scm @@ -231,10 +231,10 @@ directory = '" port) (for-each (lambda (file) (make-file-writable file) - ;; Strip the hash and replace '.tar.gz' with '.crate'. + ;; Strip the hash and rust prefix and replace '.tar.gz' with '.crate'. (rename-file file (string-append (string-drop-right - (string-drop file 35) + (string-drop file 40) (string-length ".tar.gz")) ".crate"))) (find-files "." "\\.tar\\.gz$")))) -- cgit v1.2.3 From 0058ed81b0d994f2e9747c31cd002e7b292f7fe4 Mon Sep 17 00:00:00 2001 From: Efraim Flashner Date: Sun, 8 Oct 2023 20:09:17 +0300 Subject: build: cargo-build-system: Find more pregenerated files. * guix/build/cargo-build-system.scm (check-for-pregenerated-files): Also search for MacOS dynamic libraries. --- guix/build/cargo-build-system.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guix/build') diff --git a/guix/build/cargo-build-system.scm b/guix/build/cargo-build-system.scm index e54882be34..505c0b4b01 100644 --- a/guix/build/cargo-build-system.scm +++ b/guix/build/cargo-build-system.scm @@ -114,7 +114,7 @@ Cargo.toml file present at its root." (define* (check-for-pregenerated-files #:rest _) "Check the source code for files which are known to generally be bundled libraries or executables." - (let ((pregenerated-files (find-files "." "\\.(a|dll|exe|lib)$"))) + (let ((pregenerated-files (find-files "." "\\.(a|dll|dylib|exe|lib)$"))) (when (not (null-list? pregenerated-files)) (error "Possible pre-generated files found:" pregenerated-files)))) -- cgit v1.2.3