Subject: [bug#71076] [PATCH 15/81] gnu: Add rust-tikv-jemalloc-sys-0.5.

From: Herman Rimm <[email-masked]>
Date: Mon, 20 May 2024 10:58:20 +0200

* gnu/packages/crates-io.scm (override-jemalloc,
rust-tikv-jemalloc-sys-0.5): Add variables.
(rust-tikv-jemalloc-sys-0.4): Inherit from rust-tikv-jemalloc-sys-0.5.

Change-Id: Ic37cea079d42883b91e8cfd5382fd9d95d658851
---
 gnu/packages/crates-io.scm | 49 +++++++++++++++++++++++++++++++-------
 1 file changed, 41 insertions(+), 8 deletions(-)

diff --git a/gnu/packages/crates-io.scm b/gnu/packages/crates-io.scm
index 7076dff8f2..8aee499902 100644
--- a/gnu/packages/crates-io.scm
+++ b/gnu/packages/crates-io.scm
@@ -128,7 +128,8 @@ (define-module (gnu packages crates-io)
   #:use-module (gnu packages xorg)
   #:use-module (gnu packages gtk)
   #:use-module (gnu packages webkit)
-  #:use-module (srfi srfi-1))
+  #:use-module (srfi srfi-1)
+  #:export (override-jemalloc))
 
 ;;;
 ;;; Please: Try to add new module packages in alphabetic order.
@@ -82683,6 +82684,18 @@ (define-public rust-thrift-0.13
         ("rust-ordered-float" ,rust-ordered-float-1)
         ("rust-threadpool" ,rust-threadpool-1))))))
 
+(define override-jemalloc
+#~(modify-phases %standard-phases
+    (add-after 'configure 'override-jemalloc
+      (lambda* (#:key inputs #:allow-other-keys)
+        ;; This flag is needed when not using the bundled jemalloc.
+        ;; https://github.com/tikv/jemallocator/issues/19
+        (setenv "CARGO_FEATURE_UNPREFIXED_MALLOC_ON_SUPPORTED_PLATFORMS"
+                "1")
+        (setenv "JEMALLOC_OVERRIDE"
+                (string-append (assoc-ref inputs "jemalloc")
+                               "/lib/libjemalloc_pic.a"))))))
+
 (define-public rust-tikv-jemalloc-ctl-0.4
   (package
     (name "rust-tikv-jemalloc-ctl")
@@ -82716,8 +82729,34 @@ (define-public rust-tikv-jemalloc-ctl-0.4
 introspection APIs.")
     (license (list license:expat license:asl2.0))))
 
+(define-public rust-tikv-jemalloc-sys-0.5
+  (package
+    (name "rust-tikv-jemalloc-sys")
+    (version "0.5.4+5.3.0-patched")
+    (source
+     (origin
+       (method url-fetch)
+       (uri (crate-uri "tikv-jemalloc-sys" version))
+       (file-name (string-append name "-" version ".tar.gz"))
+       (sha256
+        (base32
+          "1lc5vm1p9dqdvd3mn3264zddnd7z6i95ch3y69prnjgxp0y480ll"))
+       (modules '((guix build utils)))
+       (snippet '(delete-file-recursively "jemalloc"))))
+    (build-system cargo-build-system)
+    (arguments
+     (list
+      #:cargo-inputs (list rust-cc-1 rust-libc-0.2)
+      #:phases override-jemalloc))
+    (native-inputs (list jemalloc))
+    (home-page "https://github.com/tikv/jemallocator")
+    (synopsis "Rust FFI bindings to jemalloc")
+    (description "This package provides Rust FFI bindings to jemalloc.")
+    (license (list license:expat license:asl2.0))))
+
 (define-public rust-tikv-jemalloc-sys-0.4
   (package
+    (inherit rust-tikv-jemalloc-sys-0.5)
     (name "rust-tikv-jemalloc-sys")
     (version "0.4.1+5.2.1-patched")
     (source
@@ -82732,18 +82771,12 @@ (define-public rust-tikv-jemalloc-sys-0.4
        (modules '((guix build utils)))
        (snippet
         '(begin (delete-file-recursively "jemalloc")))))
-    (build-system cargo-build-system)
     (arguments
      `(#:skip-build? #t
        #:cargo-inputs
        (("rust-cc" ,rust-cc-1)
         ("rust-fs-extra" ,rust-fs-extra-1)
-        ("rust-libc" ,rust-libc-0.2))))
-    (home-page
-     "https://github.com/tikv/jemallocator")
-    (synopsis "Rust FFI bindings to jemalloc")
-    (description "This package provides a Rust FFI bindings to jemalloc.")
-    (license (list license:expat license:asl2.0))))
+        ("rust-libc" ,rust-libc-0.2))))))
 
 (define-public rust-tikv-jemallocator-0.4
   (package
-- 
2.41.0