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

jack-sys: search for jack library with pkg-config #154

Merged
merged 2 commits into from
Dec 13, 2021

Conversation

Be-ing
Copy link
Contributor

@Be-ing Be-ing commented Nov 30, 2021

This fixes linking with PipeWire's JACK headers.
Fixes #142

jack-sys/build.rs Outdated Show resolved Hide resolved
@fogti
Copy link

fogti commented Nov 30, 2021

I'm surprised that this library doesn't use links = "jack" in Cargo.toml (see also).

I think there is also a problem with how this would interfere with the following code segment:

rust-jack/jack-sys/src/lib.rs

Lines 1077 to 1104 in 90ab9bd

// Load optional functions:
#[cfg(windows)]
const jack_lib: &'static str = "libjack.dll";
#[cfg(unix)]
const jack_lib: &'static str = "libjack.so\0";
type jack_get_cycle_times_t = unsafe extern "C" fn(
client: *const jack_client_t,
current_frames: *mut jack_nframes_t,
current_usecs: *mut jack_time_t,
next_usecs: *mut jack_time_t,
period_usecs: *mut ::libc::c_float,
) -> ::libc::c_int;
lazy_static! {
pub static ref jack_get_cycle_times: Option<jack_get_cycle_times_t> = {
libloading::Library::new(jack_lib)
.ok()
.and_then(|lib| unsafe {
lib.get::<jack_get_cycle_times_t>(b"jack_get_cycle_times\0")
.ok()
.map(|sym| sym.into_raw())
.map(|sym| *sym.deref() as jack_get_cycle_times_t)
})
};
}

(as jack_lib is hard-coded, but if we get another value from pkg-config, we might e.g. dlopen the wrong file; although that risk is probably really small, as most systems which want to mess with library paths probably set rpaths (sic) properly)

@@ -0,0 +1,3 @@
fn main() {
pkg_config::probe_library("jack").unwrap();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a good idea to not always fail hard when the pkg-config call fails, e.g.:

Suggested change
pkg_config::probe_library("jack").unwrap();
let _ = pkg_config::probe_library("jack");

Copy link
Contributor Author

@Be-ing Be-ing Dec 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? In what scenario would that be helpful?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically every scenario in which pkg-config or the jack.pc file is unavailable, and/but the jack runtime libraries are available, as pkg-config isn't really necessary for the library code to work, the code doesn't access need to reference any include files or such which would be found that way, it is only used to increase the accuracy of the linking (which may be incomplete, as noted above).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

additional, it is really likely to just break completely on windows, as it is even more likely that jack.pc files or pkg-config are just unavailable there. pkg_config::probe_library prints a warning in that case anyway, so if the final linking is failing or does something unexpected the user has enough information to fix it, but I don't think that pkg-config should be always required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I changed this and added a comment. I have no idea how Cargo locates C libraries on Windows.

@fogti
Copy link

fogti commented Nov 30, 2021

(btw I really hope I'm not too intimidating, this is a small change and it appears to work, but I would like to make it somewhat more error-proof)

@Be-ing
Copy link
Contributor Author

Be-ing commented Dec 1, 2021

I think there is also a problem with how this would interfere with the following code segment:

I don't think there's any problem there. Fedora's pipewire-jack-audio-connection-kit package installs a /etc/ld.so.conf.d/pipewire-jack-x86_64.conf file with the contents /usr/lib64/pipewire-0.3/jack/. I presume other distributions likewise take care of adding PipeWire's libjack to the dynamic linker search path.

@navaati
Copy link

navaati commented Dec 12, 2021

Yes, please make this happen :)

@wmedrano wmedrano merged commit bbabe92 into RustAudio:main Dec 13, 2021
@Be-ing
Copy link
Contributor Author

Be-ing commented Dec 13, 2021

Thanks for merging. Could you publish a patch release so I don't have to hack the Cargo.toml of everything using this crate to get it to build?

@wmedrano
Copy link
Member

Done. Live in 0.8.3.

@Be-ing
Copy link
Contributor Author

Be-ing commented Dec 13, 2021

jack 0.8.3 is still failing with the same link error for me. Do you need to bump the version of jack-sys too?

@wmedrano
Copy link
Member

Sorry about that. Just bumped jack-sys to 0.2.3 and jack to 0.8.4.

@Be-ing
Copy link
Contributor Author

Be-ing commented Dec 13, 2021

Now it works, thanks!

Be-ing added a commit to Be-ing/cpal that referenced this pull request Dec 13, 2021
This fixes the build with Pipewire's implementation of JACK:
RustAudio/rust-jack#154
Be-ing added a commit to Be-ing/loopers that referenced this pull request Dec 13, 2021
This fixes the build with Pipewire:
RustAudio/rust-jack#154
@navaati
Copy link

navaati commented Dec 13, 2021

Worked flawlessly, thanks a lot !

Be-ing added a commit to Be-ing/midir that referenced this pull request Jan 28, 2022
Boddlnagg pushed a commit to Boddlnagg/midir that referenced this pull request Feb 12, 2022
@Be-ing Be-ing deleted the pkg-config branch April 10, 2022 14:24
@Be-ing Be-ing mentioned this pull request Apr 12, 2022
ibmibmibm pushed a commit to ibmibmibm/midir that referenced this pull request Dec 16, 2022
ibmibmibm pushed a commit to ibmibmibm/midir that referenced this pull request Dec 17, 2022
allthebestmoviestvshowslists9 added a commit to allthebestmoviestvshowslists9/cpal that referenced this pull request Aug 15, 2024
This fixes the build with Pipewire's implementation of JACK:
RustAudio/rust-jack#154
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 this pull request may close these issues.

failure to link with pipewire-jack-audio-connection-kit-devel
4 participants