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

Don't let pkg-config add system lib dirs to the search path #50

Merged
merged 1 commit into from
Jul 1, 2020

Conversation

rinon
Copy link
Contributor

@rinon rinon commented Feb 13, 2019

Adding system-wide library directories to the linker search path causes these
directories to be searched before other paths added by later crates. If a
library is present in the system-wide directory and a later crate wants to
specifically link against a different version of that library in another path,
the linker will choose the library from the first search directory it
finds. If the linker doesn't find a library in any of the specified search
directories, it falls back on system-wide paths, so we don't need to print the
path we found zlib in if it is in one of those system paths.

This resolves issue #49.

Adding system-wide library directories to the linker search path causes these
directories to be searched before other paths added by later crates. If a
library is present in the system-wide directory and a later crate wants to
specifically link against a different version of that library in another path,
the linker will choose the library from the first search directory it
finds. If the linker doesn't find a library in any of the specified search
directories, it falls back on system-wide paths, so we don't need to print the
path we found zlib in if it is in one of those system paths.
@alexcrichton
Copy link
Member

@joshtriplett can you take a look at this?

@joshtriplett
Copy link
Member

@alexcrichton Why does pkg-config-rs default to allowing system library directories by default, rather than sticking with the default behavior of the pkg-config executable and stripping them out?

This seems like what any library should be doing, not just libz-sys.

@rinon
Copy link
Contributor Author

rinon commented Feb 19, 2019

Agreed, I'd prefer that to be the default, but @alexcrichton didn't want to do this this because it changes the behavior of pkg-config-rs (rust-lang/pkg-config-rs#35). There's a longer discussion in rust-lang/pkg-config-rs#11.

@alexcrichton
Copy link
Member

@joshtriplett way long ago when it first came up I didn't want to maintain a list of "what are the system library directories" for all platforms, but times change!

@rinon
Copy link
Contributor Author

rinon commented Feb 19, 2019

Why would pkg-config-rs need to maintain a list? pkg-config by default filters the list, do we need to duplicate that in Rust?

@rinon
Copy link
Contributor Author

rinon commented Apr 8, 2019

Just wanted to ping this PR and see if it can be merged.

@joshtriplett
Copy link
Member

Looks reasonable; thank you for the patch.

@joshtriplett joshtriplett merged commit f7aec58 into rust-lang:master Jul 1, 2020
jonhoo pushed a commit to jonhoo/curl-rust that referenced this pull request Apr 12, 2022
In its default configuration, pkg-config adds system-wide library
directories to the linker search path (rust-lang/pkg-config-rs#11).
This causes these directories to be searched before other paths added
by later crates or by `-Clink-arg` in rustflags. If a library is present in
the system-wide directory and a later build step wants to specifically
link against a different version of that library in another path, the linker
will choose the library from the first search directory it finds. If the linker
doesn't find a library in any of the specified search directories, it falls
back on system-wide paths, so we don't need to print the
path we found lubcurl in if it is in one of those system paths.

rust-lang/libz-sys#50
jonhoo pushed a commit to jonhoo/curl-rust that referenced this pull request Apr 12, 2022
In its default configuration, pkg-config adds system-wide library
directories to the linker search path (rust-lang/pkg-config-rs#11).
This causes these directories to be searched before other paths added
by later crates or by `-Clink-arg` in rustflags. If a library is present in
the system-wide directory and a later build step wants to specifically
link against a different version of that library in another path, the linker
will choose the library from the first search directory it finds. If the linker
doesn't find a library in any of the specified search directories, it falls
back on system-wide paths, so we don't need to print the
path we found lubcurl in if it is in one of those system paths.

See rust-lang/libz-sys#50 for the same fix to libz that landed a while back.
jonhoo pushed a commit to jonhoo/git2-rs that referenced this pull request Apr 13, 2022
In its default configuration, pkg-config adds system-wide library
directories to the linker search path (rust-lang/pkg-config-rs#11).
This causes these directories to be searched before other paths added
by later crates or by -Clink-arg in rustflags. If a library is present in
the system-wide directory and a later build step wants to specifically
link against a different version of that library in another path, the linker
will choose the library from the first search directory it finds. If the linker
doesn't find a library in any of the specified search directories, it falls
back on system-wide paths, so we don't need to print the
path we found libssh2 in if it is in one of those system paths.

See rust-lang/libz-sys#50 for the same fix to libz that landed a while back.
See also alexcrichton/curl-rust#441 for the same fix to libcurl-sys.
joshtriplett pushed a commit to rust-lang/git2-rs that referenced this pull request Apr 27, 2022
In its default configuration, pkg-config adds system-wide library
directories to the linker search path (rust-lang/pkg-config-rs#11).
This causes these directories to be searched before other paths added
by later crates or by -Clink-arg in rustflags. If a library is present in
the system-wide directory and a later build step wants to specifically
link against a different version of that library in another path, the linker
will choose the library from the first search directory it finds. If the linker
doesn't find a library in any of the specified search directories, it falls
back on system-wide paths, so we don't need to print the
path we found libssh2 in if it is in one of those system paths.

See rust-lang/libz-sys#50 for the same fix to libz that landed a while back.
See also alexcrichton/curl-rust#441 for the same fix to libcurl-sys.
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.

None yet

3 participants