From b08570349d10e788c6393bbb423bcd1b0467dd73 Mon Sep 17 00:00:00 2001 From: Ludovic LANGE Date: Tue, 6 Jul 2021 00:07:58 +0200 Subject: [PATCH] Notmuch dynamic library can now be loaded on macos On macos, the name of dynamic libraries is a little bit different than on Unix. The code was looking for a `libnotmuch.so.5` library, while on macos it's installed as `libnotmuch.5.dylib`. This commit uses cfg attribute to conditionally change the library name. Closes #106 --- melib/src/backends.rs | 6 +++++- melib/src/backends/notmuch.rs | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/melib/src/backends.rs b/melib/src/backends.rs index 9b86a24d..24a2d7f3 100644 --- a/melib/src/backends.rs +++ b/melib/src/backends.rs @@ -156,7 +156,11 @@ impl Backends { } #[cfg(feature = "notmuch_backend")] { - if libloading::Library::new("libnotmuch.so.5").is_ok() { + #[cfg(not(target_os = "macos"))] + let dlpath = "libnotmuch.so.5"; + #[cfg(target_os = "macos")] + let dlpath = "libnotmuch.5.dylib"; + if libloading::Library::new(dlpath).is_ok() { b.register( "notmuch".to_string(), Backend { diff --git a/melib/src/backends/notmuch.rs b/melib/src/backends/notmuch.rs index d2de9367..e131cef4 100644 --- a/melib/src/backends/notmuch.rs +++ b/melib/src/backends/notmuch.rs @@ -307,7 +307,11 @@ impl NotmuchDb { _is_subscribed: Box bool>, event_consumer: BackendEventConsumer, ) -> Result> { - let lib = Arc::new(libloading::Library::new("libnotmuch.so.5")?); + #[cfg(not(target_os = "macos"))] + let dlpath = "libnotmuch.so.5"; + #[cfg(target_os = "macos")] + let dlpath = "libnotmuch.5.dylib"; + let lib = Arc::new(libloading::Library::new(dlpath)?); let path = Path::new(s.root_mailbox.as_str()).expand(); if !path.exists() { return Err(MeliError::new(format!(