Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynamically load libjack at runtime instead of linking #159

Closed
Be-ing opened this issue Jan 21, 2022 · 6 comments · Fixed by #162
Closed

dynamically load libjack at runtime instead of linking #159

Be-ing opened this issue Jan 21, 2022 · 6 comments · Fixed by #162

Comments

@Be-ing
Copy link
Contributor

Be-ing commented Jan 21, 2022

To work around issues of ABI compatibility, particularly on Windows, cross platform C/C++ applications that use JACK typically use a shim that dynamically loads libjack and forwards API calls to the dynamically loaded library. This allows applications to run even if libjack is not available. There are a handful of implementations of this:

https:/x42/weakjack (GPLv2+)
https:/jackaudio/jack2/blob/develop/common/JackWeakAPI.c (LGPL2.1+)
https:/DISTRHO/DPF/blob/develop/distrho/src/jackbridge/JackBridge.hpp (MIT)
https:/juce-framework/JUCE/blob/develop/modules/juce_audio_devices/native/juce_linux_JackAudio.cpp#L26 (ISC)

This could be accomplished by building one of those C shims and statically linking it with jack-sys. Alternatively libloading could be used to do this in Rust. libloading is already used in jack-sys for jack_get_cycle_times.

@Be-ing
Copy link
Contributor Author

Be-ing commented Jan 21, 2022

Removing the need for having libjack available at build time would also make it easier to build Rust applications, especially on Windows and macOS or cross compiling.

@Be-ing
Copy link
Contributor Author

Be-ing commented Jan 27, 2022

dlib could help with this.

@wmedrano
Copy link
Member

Thanks for the references, I'll give it a try this weekend. This feature is definitely very value-able when cross compiling.

@Be-ing
Copy link
Contributor Author

Be-ing commented Jan 27, 2022

libloading is already used in jack-sys for jack_get_cycle_times.

Getting this to work with dlib could get tricky. However, I think this is unnecessary. Digging into the JACK2 source code, jack_get_cycle_times was added in 2010. The declaration in jack.h is marked with the JACK_OPTIONAL_WEAK_EXPORT macro, which is documented as existing so applications can use newer JACK API functions and keep the application compatible with old versions of JACK. Today, considering the function has existed in JACK2 for 12 years, it is very unlikely anyone will try to use these Rust bindings with a version of libjack so old it does not have jack_get_cycle_times, especially considering that Rust being in development wasn't even announced until the year jack_get_cycle_times was added to JACK2. In the worst case scenario, the library would fail to load with dlib and the application could recover from that.

@Be-ing
Copy link
Contributor Author

Be-ing commented Jan 28, 2022

My Pinephone Pro just arrived yesterday and I'm looking into how to cross compile Rust from my x86-64 laptop running Linux to the Pinephone Pro. Not having to link a cross-compiled libjack would make this easier.

This was referenced Feb 5, 2022
@wmedrano
Copy link
Member

wmedrano commented Feb 5, 2022

Is there any chance you can try the current PR?

[dependencies]
jack = { git = "https:/RustAudio/rust-jack", branch = "dlib" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants