From 8d8edddb2e1074bf36a14b244c7ed9a0eec054dc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timo=20K=C3=B6sters?= <timo@koesters.xyz>
Date: Fri, 4 Feb 2022 16:59:30 +0100
Subject: [PATCH] feat: allow disabling jemalloc via feature

---
 Cargo.toml  | 8 ++++----
 src/main.rs | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index aac840b5..dd31c849 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -86,17 +86,17 @@ sha-1 = "0.9.8"
 clap = { version = "3.0.10", default-features = false, features = ["std", "derive"] }
 maplit = "1.0.2"
 
-[target.'cfg(not(target_env = "msvc"))'.dependencies]
-tikv-jemalloc-ctl = { version = "0.4.2", features = ['use_std'] }
-tikv-jemallocator = { version = "0.4.1", features = ['unprefixed_malloc_on_supported_platforms'] }
+tikv-jemalloc-ctl = { version = "0.4.2", features = ["use_std"], optional = true }
+tikv-jemallocator = { version = "0.4.1", features = ["unprefixed_malloc_on_supported_platforms"], optional = true }
 
 [features]
-default = ["conduit_bin", "backend_sqlite", "backend_rocksdb"]
+default = ["conduit_bin", "backend_sqlite", "backend_rocksdb", "jemalloc"]
 backend_sled = ["sled"]
 backend_persy = ["persy", "parking_lot"]
 backend_sqlite = ["sqlite"]
 backend_heed = ["heed", "crossbeam"]
 backend_rocksdb = ["rocksdb"]
+jemalloc = ["tikv-jemalloc-ctl", "tikv-jemallocator"]
 sqlite = ["rusqlite", "parking_lot", "tokio/signal"]
 conduit_bin = [] # TODO: add rocket to this when it is optional
 
diff --git a/src/main.rs b/src/main.rs
index b3e85c95..ea09dd5b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -26,10 +26,10 @@ use tracing_subscriber::{prelude::*, EnvFilter};
 pub use conduit::*; // Re-export everything from the library crate
 pub use rocket::State;
 
-#[cfg(not(target_env = "msvc"))]
+#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
 use tikv_jemallocator::Jemalloc;
 
-#[cfg(not(target_env = "msvc"))]
+#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
 #[global_allocator]
 static GLOBAL: Jemalloc = Jemalloc;