Fix dylib linking for Mac app bundles #12711
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Currently, Tauri allows packaging additional
.dylib
libraries and frameworks, but it does not fix their linking in the final bundled app.For example, in my case, I use the
rust-opencv
library, which links to OpenCV libraries installed via Homebrew:While Tauri can bundle these
.dylib
files, it does not adjust the binary to correctly reference them. If I deploy my app to another computer without these libraries, the app crashes. Worse, if the new system has a different version of the library installed, the app will also crash due to version mismatches.Solution
To fix this, I added an additional bundling step that:
.dylib
files using@rpath
..dylib
files themselves to use@rpath
instead of absolute paths.rpath
to locate the bundled libraries inContents/Frameworks
.This mirrors what the following Bash script does manually:
Since this script needs to run before generating the
.dmg
file, I added an extra step in Tauri’s bundling process to automate it.Issue
To control whether this step runs, I introduced a new configuration option:
By default, this option is
false
to avoid breaking existing setups.However, when testing locally with
cargo tauri build
, I encountered the following error:Do you know a way to workaround this error?