[bug#77093,rust-team,08/18] build/cargo: Use system jemalloc.

Message ID 02e5f7ff3d45b516a797c3e68c257748336dbae2.1742281797.git.hako@ultrarare.space
State New
Headers
Series New Rust packaging workflow based on lockfile importer. |

Commit Message

Hilton Chain March 18, 2025, 7:24 a.m. UTC
  From: Efraim Flashner <efraim@flashner.co.il>

* guix/build/cargo-build-system.scm (configure): Set environment variables to
use system jemalloc.

Change-Id: Ibb1c025c7354ba2befd2770e3f1ccd785baa06c3
Modified-by: Hilton Chain <hako@ultrarare.space>
---
 guix/build/cargo-build-system.scm | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

Efraim Flashner March 18, 2025, 11:49 a.m. UTC | #1
I'm not sure how I feel about this one.  On one hand the
unprefixed_malloc flag is definitely necessary.  On the other hand
sometimes we use libjemalloc.so and sometimes libjemalloc_pic.a, and I
don't remember when/why we use one over the other, other than "it just
works"

On Tue, Mar 18, 2025 at 03:24:21PM +0800, Hilton Chain wrote:
> From: Efraim Flashner <efraim@flashner.co.il>
> 
> * guix/build/cargo-build-system.scm (configure): Set environment variables to
> use system jemalloc.
> 
> Change-Id: Ibb1c025c7354ba2befd2770e3f1ccd785baa06c3
> Modified-by: Hilton Chain <hako@ultrarare.space>
> ---
>  guix/build/cargo-build-system.scm | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/guix/build/cargo-build-system.scm b/guix/build/cargo-build-system.scm
> index a1c4f556bb..b547421b88 100644
> --- a/guix/build/cargo-build-system.scm
> +++ b/guix/build/cargo-build-system.scm
> @@ -248,6 +248,12 @@ (define* (configure #:key inputs
>    (setenv "LIBSSH2_SYS_USE_PKG_CONFIG" "1")
>    (setenv "SODIUM_USE_PKG_CONFIG" "1")
>    (setenv "ZSTD_SYS_USE_PKG_CONFIG" "1")
> +  ;; 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")
> +  (when (assoc-ref inputs "jemalloc")
> +    (setenv "JEMALLOC_OVERRIDE"
> +            (string-append (assoc-ref inputs "jemalloc") "/lib/libjemalloc.so")))
>    (when (assoc-ref inputs "openssl")
>      (setenv "OPENSSL_DIR" (assoc-ref inputs "openssl")))
>    (when (assoc-ref inputs "gettext")
> -- 
> 2.48.1
>
  
Hilton Chain March 18, 2025, 12:09 p.m. UTC | #2
On Tue, 18 Mar 2025 19:49:21 +0800,
Efraim Flashner wrote:
>
> [1  <text/plain; utf-8 (quoted-printable)>]
> I'm not sure how I feel about this one.  On one hand the
> unprefixed_malloc flag is definitely necessary.  On the other hand
> sometimes we use libjemalloc.so and sometimes libjemalloc_pic.a, and I
> don't remember when/why we use one over the other, other than "it just
> works"
>
> On Tue, Mar 18, 2025 at 03:24:21PM +0800, Hilton Chain wrote:
> > From: Efraim Flashner <efraim@flashner.co.il>
> >
> > * guix/build/cargo-build-system.scm (configure): Set environment variables to
> > use system jemalloc.
> >
> > Change-Id: Ibb1c025c7354ba2befd2770e3f1ccd785baa06c3
> > Modified-by: Hilton Chain <hako@ultrarare.space>
> > ---
> >  guix/build/cargo-build-system.scm | 6 ++++++
> >  1 file changed, 6 insertions(+)

I'll drop this one for now then, I didn't search the source tree :P
  

Patch

diff --git a/guix/build/cargo-build-system.scm b/guix/build/cargo-build-system.scm
index a1c4f556bb..b547421b88 100644
--- a/guix/build/cargo-build-system.scm
+++ b/guix/build/cargo-build-system.scm
@@ -248,6 +248,12 @@  (define* (configure #:key inputs
   (setenv "LIBSSH2_SYS_USE_PKG_CONFIG" "1")
   (setenv "SODIUM_USE_PKG_CONFIG" "1")
   (setenv "ZSTD_SYS_USE_PKG_CONFIG" "1")
+  ;; 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")
+  (when (assoc-ref inputs "jemalloc")
+    (setenv "JEMALLOC_OVERRIDE"
+            (string-append (assoc-ref inputs "jemalloc") "/lib/libjemalloc.so")))
   (when (assoc-ref inputs "openssl")
     (setenv "OPENSSL_DIR" (assoc-ref inputs "openssl")))
   (when (assoc-ref inputs "gettext")