Skip to content

Commit

Permalink
Compatibility with macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul committed Nov 8, 2022
1 parent 69ecba7 commit 41eac5d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ members = [
"validator_client",
"validator_client/slashing_protection",
]
resolver = "2"

[patch]
[patch.crates-io]
Expand Down
11 changes: 8 additions & 3 deletions common/malloc_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
11 changes: 8 additions & 3 deletions common/malloc_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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> {
Expand Down

0 comments on commit 41eac5d

Please sign in to comment.