Skip to content

Commit

Permalink
Use the path to the bundle instead of DSO in init
Browse files Browse the repository at this point in the history
On macOS. As clarified in
free-audio/clap@f6d86a7.
Closes #12.
  • Loading branch information
robbert-vdh committed Mar 24, 2023
1 parent a9a7b64 commit 189c440
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 9 additions & 6 deletions src/plugin/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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.");
}
Expand Down

0 comments on commit 189c440

Please sign in to comment.