From 41eac5d0c16496156db53acee9fbdfaec4c6218b Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Tue, 8 Nov 2022 13:46:17 +1100 Subject: [PATCH] Compatibility with macOS --- Cargo.toml | 1 + common/malloc_utils/Cargo.toml | 11 ++++++++--- common/malloc_utils/src/lib.rs | 11 ++++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 02cf4d9436..655d99ac6d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -87,6 +87,7 @@ members = [ "validator_client", "validator_client/slashing_protection", ] +resolver = "2" [patch] [patch.crates-io] diff --git a/common/malloc_utils/Cargo.toml b/common/malloc_utils/Cargo.toml index 1a7b97d449..c88ec0bd5a 100644 --- a/common/malloc_utils/Cargo.toml +++ b/common/malloc_utils/Cargo.toml @@ -9,11 +9,16 @@ lighthouse_metrics = { path = "../lighthouse_metrics" } lazy_static = "1.4.0" libc = "0.2.79" parking_lot = "0.12.0" -jemallocator = { version = "0.5.0", optional = true, features = ["background_threads"] } jemalloc-ctl = { version = "0.5.0", optional = true } +# Jemalloc's background_threads feature requires Linux (pthreads). +[target.'cfg(target_os = "linux")'.dependencies] +jemallocator = { version = "0.5.0", optional = true, features = ["stats", "background_threads"] } + +[target.'cfg(not(target_os = "linux"))'.dependencies] +jemallocator = { version = "0.5.0", optional = true, features = ["stats"] } + [features] mallinfo2 = [] -jemalloc = ["jemallocator", "jemallocator/stats", "jemalloc-ctl"] -jemalloc-stats = ["jemallocator/stats"] +jemalloc = ["jemallocator", "jemalloc-ctl"] jemalloc-profiling = ["jemallocator/profiling"] diff --git a/common/malloc_utils/src/lib.rs b/common/malloc_utils/src/lib.rs index 75ccac6639..1eab8b3baa 100644 --- a/common/malloc_utils/src/lib.rs +++ b/common/malloc_utils/src/lib.rs @@ -26,7 +26,8 @@ #[cfg(all( target_os = "linux", - not(any(target_env = "musl", feature = "jemalloc")) + not(target_env = "musl"), + not(feature = "jemalloc") ))] mod glibc; @@ -37,7 +38,8 @@ pub use interface::*; #[cfg(all( target_os = "linux", - not(any(target_env = "musl", feature = "jemalloc")) + not(target_env = "musl"), + not(feature = "jemalloc") ))] mod interface { pub use crate::glibc::configure_glibc_malloc as configure_memory_allocator; @@ -54,7 +56,10 @@ mod interface { pub use crate::jemalloc::scrape_jemalloc_metrics as scrape_allocator_metrics; } -#[cfg(any(not(target_os = "linux"), target_env = "musl"))] +#[cfg(all( + any(not(target_os = "linux"), target_env = "musl"), + not(feature = "jemalloc") +))] mod interface { #[allow(dead_code, clippy::unnecessary_wraps)] pub fn configure_memory_allocator() -> Result<(), String> {