Description
The is_system
function uses a heuristic "path starts with /usr
" to check whether a library is a system library. For reasons unknown to me, being a system library blocks static linking.
The function iterates all the dirs and checks if any of them is a non-system library. If even one library search path is found for the library that is "non-system", the function returns false. If all the search paths are system libraries, the function returns true.
However, the function has a bug: if the list of search dirs passed to it is empty, the function returns true. I'm not sure how should it behave if the list is empty, but certainly returning "this is a system lib" when the library is actually not, is wrong behaviour.
There's some other concerns too: the dirs are added to the list in the order they are got from pkg-config
. This is the reason the dir list may be empty in the first place; pkg-config might return something like: -I/musl/include -lssl -lcrypto -L/musl/lib -ldl
.
There's another concern too. That has more to do with the spirit of this issue I posted just a moment ago in the Rust repo: rust-lang/rust#39998 If the pkg-config knows that I want to link statically (after all, I specified the env vars!), why does it silently pass dynamic flags to cargo instead of erroring: "You said you want to link statically but what you've got here is a system lib, I can't link that statically!"