-
Notifications
You must be signed in to change notification settings - Fork 83
Description
Currently pkg_config will go out of its way to not honour FOO_STATIC=1 if its is_static_available check fails, which it can fail even if the static library is made available through pkg-config.
My case in point is the liburing that rocksdb-sys tries to link. I set LIBURING_STATIC=1 and later PKG_CONFIG_ALL_STATIC=1 but liburing kept being linked dynamically, even if the static library is available.
The environment I was working in here is bog-standard ubuntu 22.04 with liburing-dev installed. This package places liburing.so and liburing.a in /usr/lib/x86_64-linux/. The pkg-config's output here is pretty sparse as a result:
# pkg-config --cflags --libs --static liburing
-luringOn the crate's side things are for the most part going as expected until the system_roots check here:
Line 1066 in 057321c
| library_exists && !system_roots.iter().any(|sys| dir.starts_with(sys)) |
In this function dirs = [ "/usr/lib/x86_64-linux" ] and system_roots = [ "/usr" ]. So the code finds that /usr/lib/x86_64-linux/liburing.a exits, but then decides that this is a system library because this is under /usr. I don't see a reason why this should be grounds for discarding this static library – in fact on your average ubuntu most static libraries installed via apt will be found under /usr/lib/x86_64-linux, making static linking options not effective.
I'm not sure why this check exists or why falling back to dynamic libraries despite the FOO_STATIC=1 environment variable is desirable, but in case this is important, I suggest we add FOO_FORCE_STATIC which would always try to link statically regardless of whether is_static_available check passes. There would be no safeguards against possible future linking failures with this environment variable set. It would just do what's written on the label.