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

Bug: is_system erroneously reports that a library is a system library in some cases. #36

Open
golddranks opened this issue Feb 21, 2017 · 6 comments

Comments

@golddranks
Copy link

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!"

@alexcrichton
Copy link
Member

Does configuring this crate work?

@golddranks
Copy link
Author

golddranks commented Feb 22, 2017

It doesn't work, since the is_system check on this row: https://github.com/alexcrichton/pkg-config-rs/blob/master/src/lib.rs#L433 prevents static build even if the flags are set.

@alexcrichton
Copy link
Member

Sounds like a bug to fix then!

@golddranks
Copy link
Author

I'll look into it in the near future!

@golddranks
Copy link
Author

#37 Sent a PR.

I left the check with empty directory list as is, because it seems reasonable to think a library is a system lib if no search path is specified. But I fixed two other problems.

@golddranks
Copy link
Author

golddranks commented Mar 1, 2017

There's still one problem:

The is_system check prevents library from being linked statically. But if people use system-provided musl-dev libs, they are in the system dirs (for example, /usr/lib/x86_64-linux-musl/), and it's reasonable to link against them.

I don't know if there even exists a simple, non-distro specific heuristic that is able to prevent obviously wrong choices while allowing the correct ones. (One of reasonable candidates is checking whether the path contains word "musl"; that works at least on Debian and Arch, but that would be not only distro-specific, but also target-specific. Not sure if we even have other static targets than musl, though.)

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

No branches or pull requests

2 participants