From c9666c120b8e40321d6044f572533e160c1e0351 Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Tue, 2 Jan 2024 11:08:36 -0500 Subject: [PATCH] packages: Repack patched source archives via zstd by default. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * guix/build/utils.scm (compressor): Register zst file name extension. * guix/packages.scm (%standard-patch-inputs): Add zstd. (patch-and-repack): Rename tarxz-name nested procedure to tar-file-name, and accept a new 'ext' argument; adjust accordingly. Add zstd binding, and replace the XZ_DEFAULTS environment variable with ZSTD_NBTHREADS. Fallback to xz when zstd is not available. Reviewed-by: Ludovic Courtès Change-Id: I614a6be8c87a4a0858eadce616c51d8e9b9fc020 --- guix/build/utils.scm | 1 + guix/packages.scm | 50 +++++++++++++++++++++++++------------------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/guix/build/utils.scm b/guix/build/utils.scm index e87066cc02..9c1e19f6d8 100644 --- a/guix/build/utils.scm +++ b/guix/build/utils.scm @@ -177,6 +177,7 @@ (define (compressor file-name) ((string-suffix? "lz" file-name) "lzip") ((string-suffix? "zip" file-name) "unzip") ((string-suffix? "xz" file-name) "xz") + ((string-suffix? "zst" file-name) "zstd") (else #f))) ;no compression used/unknown file extension (define (tarball? file-name) diff --git a/guix/packages.scm b/guix/packages.scm index d260a48767..1fc10e6575 100644 --- a/guix/packages.scm +++ b/guix/packages.scm @@ -5,7 +5,7 @@ ;;; Copyright © 2016 Alex Kost ;;; Copyright © 2017, 2019, 2020, 2022 Efraim Flashner ;;; Copyright © 2019 Marius Bakke -;;; Copyright © 2020, 2021 Maxim Cournoyer +;;; Copyright © 2020, 2021, 2024 Maxim Cournoyer ;;; Copyright © 2021 Chris Marusich ;;; Copyright © 2022 Maxime Devos ;;; Copyright © 2022 jgart @@ -912,6 +912,7 @@ (define (%standard-patch-inputs system) (module-ref (resolve-interface module) var)))))) `(("tar" ,(ref '(gnu packages base) 'tar)) ("xz" ,(ref '(gnu packages compression) 'xz)) + ("zstd" ,(ref '(gnu packages compression) 'zstd)) ("bzip2" ,(ref '(gnu packages compression) 'bzip2)) ("gzip" ,(ref '(gnu packages compression) 'gzip)) ("lzip" ,(ref '(gnu packages compression) 'lzip)) @@ -974,31 +975,35 @@ (define (checkout? directory) ;; Return true if DIRECTORY is a checkout (git, svn, etc). (string-suffix? "-checkout" directory)) - (define (tarxz-name file-name) - ;; Return a '.tar.xz' file name based on FILE-NAME. + (define (tar-file-name file-name ext) + ;; Return a '$filename.tar.$ext' file name based on FILE-NAME and EXT. (let ((base (if (numeric-extension? file-name) original-file-name (file-sans-extension file-name)))) (string-append base (if (equal? (file-extension base) "tar") - ".xz" - ".tar.xz")))) + (string-append "." ext) + (string-append ".tar." ext))))) (define instantiate-patch (match-lambda - ((? string? patch) ;deprecated + ((? string? patch) ;deprecated (local-file patch #:recursive? #t)) - ((? struct? patch) ;origin, local-file, etc. + ((? struct? patch) ;origin, local-file, etc. patch))) - (let ((tar (lookup-input "tar")) - (gzip (lookup-input "gzip")) - (bzip2 (lookup-input "bzip2")) - (lzip (lookup-input "lzip")) - (xz (lookup-input "xz")) - (patch (lookup-input "patch")) - (comp (and=> (compressor source-file-name) lookup-input)) - (patches (map instantiate-patch patches))) + (let* ((tar (lookup-input "tar")) + (gzip (lookup-input "gzip")) + (bzip2 (lookup-input "bzip2")) + (lzip (lookup-input "lzip")) + (xz (lookup-input "xz")) + (zstd (or (lookup-input "zstd") + ;; Fallback to xz in case zstd is not available, such as + ;; for bootstrap packages. + xz)) + (patch (lookup-input "patch")) + (comp (and=> (compressor source-file-name) lookup-input)) + (patches (map instantiate-patch patches))) (define build (with-imported-modules '((guix build utils)) #~(begin @@ -1076,12 +1081,12 @@ (define (repack directory output) locale (system-error-errno args))))) (setenv "PATH" - (string-append #+xz "/bin" + (string-append #+zstd "/bin" (if #+comp (string-append ":" #+comp "/bin") ""))) - (setenv "XZ_DEFAULTS" (string-join (%xz-parallel-args))) + (setenv "ZSTD_NBTHREADS" (number->string (parallel-job-count))) ;; SOURCE may be either a directory, a tarball or a simple file. (let ((name (strip-store-file-name #+source)) @@ -1136,10 +1141,13 @@ (define (repack directory output) (else ;single uncompressed file (copy-file file #$output))))))) - (let ((name (if (or (checkout? original-file-name) - (not (compressor original-file-name))) - original-file-name - (tarxz-name original-file-name)))) + (let* ((ext (if zstd + "zst" ;usual case + "xz")) ;zstd-less bootstrap-origin + (name (if (or (checkout? original-file-name) + (not (compressor original-file-name))) + original-file-name + (tar-file-name original-file-name ext)))) (gexp->derivation name build #:graft? #f #:system system