From 189c44023256cb79f309300b6befa6b044e0251b Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Fri, 24 Mar 2023 15:34:26 +0100 Subject: [PATCH] Use the path to the bundle instead of DSO in init On macOS. As clarified in https://github.com/free-audio/clap/commit/f6d86a7e7c9cd3da233cb9ffa8e54396000ecabf. Closes #12. --- CHANGELOG.md | 2 ++ src/plugin/library.rs | 15 +++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8567b34..fbe93ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ Versioning](https://semver.org/spec/v2.0.0.html). ### Fixed +- The path passed to `clap_entry::init()` now points to the bundle on macOS, + rather than the DSO. - The `--verbosity` option's value now propagated to child processes when tests are run out of process. Previously the default `debug` value would always be used. diff --git a/src/plugin/library.rs b/src/plugin/library.rs index 57af62b..654a3d4 100644 --- a/src/plugin/library.rs +++ b/src/plugin/library.rs @@ -111,6 +111,15 @@ impl PluginLibrary { .unwrap_or_else(|_| PathBuf::from(".")) .join(path); + // This is the path passed to `clap_entry::init()`. On macOS this should point to the + // bundle, not the DSO. + let path_cstring = CString::new( + path.as_os_str() + .to_str() + .context("Path contains invalid UTF-8")?, + ) + .context("Path contains null bytes")?; + // NOTE: Apple says you can dlopen() bundles. This is a lie. #[cfg(target_os = "macos")] let path = { @@ -133,12 +142,6 @@ impl PluginLibrary { // The entry point needs to be initialized before it can be used. It will be deinitialized // when the `Plugin` object is dropped. let entry_point = get_clap_entry_point(&library)?; - let path_cstring = CString::new( - path.as_os_str() - .to_str() - .context("Path contains invalid UTF-8")?, - ) - .context("Path contains null bytes")?; if !unsafe_clap_call! { entry_point=>init(path_cstring.as_ptr()) } { anyhow::bail!("'clap_plugin_entry::init({path_cstring:?})' returned false."); }