How to statically link against jemalloc?

It used to be that you could use #![feature(alloc_jemalloc)] to statically link a crate - even if the artifact was dynamic library - against jemalloc as the allocator. Unfortunately, rustc no longer recognizes that feature. Is there a different way to do this now?

The global allocator interface has changed a bit: TL;DR:

extern crate alloc_jemalloc;

use alloc_jemalloc::Jemalloc;

static ALLOCATOR = Jemalloc;

Looks like there's unfortunately no Jemalloc in alloc_jemalloc - it looks like that crate is only implementing the old global allocator strategy:


The in-tree alloc-jemalloc implements the new interface:

Worked, thanks!

Oh, gotcha. It doesn't implement Alloc, but rather provides its own global allocator so you just have to do extern crate alloc_jemalloc and it Just Works. Thanks!

It's in a bit of a state of transition - the magical "just link to me" behavior is the old setup. On a sufficiently new compiler you'll need to do the tagged static thing. alloc_jemalloc has to implement both right now so things work with the bootstrap compiler.