-
-
Notifications
You must be signed in to change notification settings - Fork 759
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
Adds world to the link path; bad neighbor #447
Comments
We pull this information directly from pkg-config. This seems like an upstream issue? |
What would you expect pkg-config to provide? It's the correct folder. |
I guess I'm a bit confused about what's being proposed. This crate uses the pkg-config-rs crate which just calls down to pkg-config. Is there a C or Rust project that postprocesses the output of pkg-config in the way you're proposing that I can look at for reference? |
What method on pkg-config is in use? I find build.rs a bit hard to reconcile with the output I'm seeing. |
Snap! |
As far as I can tell, pkg-config is behaving as expected:
The output is correct; and we're telling it it's okay to include system lib folders. Have you seen pkg-config provide -L flags more specific than a folder? What does this command give you? |
I don't think I've seen it though I couldn't say that nothing is that specific. |
This produces the desired output on my system. Instead of letting pkg_config control STDOUT, we replicate the code paths for a dynamic link. Is static linking of libssl a thing?
Produces:
|
Static linkage is a very common scenario, particularly for OpenSSL. This kind of logic seems like it should be handled in pkg-config-rs itself since this seems like not an issue unique to this library? |
Do you think it can be generalized? Can we always know the library names to generate more specific paths? |
I don't see any library names hardcoded in that snippet? I am still confused as to why this is necessary. What other projects do this kind of thing? Is this a policy change that needs to be made over the entire Rust ecosystem? |
To me this is both simultaneously correct and incorrect behavior. It's correct that pkg-config prints out a search path because the lib is actually located there. It's incorrect because it's already baked in the linker and wasn't necessary (and then allows picking up the wrong libs). I'm not really sure what the best solution is here for everyone, but for OpenSSL specifically it's probably worth having very specific logic as it's just so common. I wouldn't mind adding a |
@alexcrichton why is |
I didn't realize that system libs were automatically linked, since I've had linkage fail even with a system alternative to a lib present. I suppose it makes sense for linkers to not support globs, but I wasn't sure of the mechanics there. I've been using Conan pretty extensively to avoid spending time on linking issues in my C libs, and if you make system libs the fallback (vs priority) for linking, 'conan install' with a 2-line conanfile might be sufficient for providing an x-plat (incl. windows) OpenSSL build. This might not be desirable on well-updated linux distro, but could be a good option for Windows and older macs, perhaps? Upstream releases are quite quick to pass through conan.io. Example conanfile.txt
I'm calling tangent on myself here, but there are specific benefits to de-prioritizing system libs over those explicitly provided through |
@sfackler at this point I... don't really remember. It may have been for static linking so the compiler could pick up |
We should probably move this discussion over to the pkg-config-rs repo then. |
pkg-config-rs can't change the default behavior without a breaking change. See rust-lang/pkg-config-rs#11 I pulled another all-nighter on this problem, and I've hit a final wall. My last resort was
I'm using OpenSSL 1.0.2j. https://github.com/imazen/imageflow/tree/server_ssl Surely there is some known method for using openssl (on linux only) without clobbering the link path? It can't be this hard. |
Sounds like it's time for a breaking change to pkg-config-rs? |
Ok seriously this is not that hard to fix. I'm sorry I'd like to avoid making a breaking change to pkg-config-rs, but let's please work through this before just assigning blame. @nathanaeljones I'm sorry you're running into problems here, working with OpenSSL shouldn't be so difficult! I've pushed 0.3.9 which has an option to disable the relevant env var. The openssl-sys crate does not work without it enabled because it can't find the headers. This'll need some more work. |
We could potentially do pkg-config lookup twice - the first time configured to emit system directories but not write anything to stdout for the include paths, and then run it a second time for the rust linkage stuff. |
Sounds plausible to me! |
I didn't mean to imply any blame - it's clear that the system dirs are needed for header lookup, and that the pkg-config default is orthogonal to this issue (I've also eliminate all other crates using it).
|
From looking at the cargo source, those arrays should work fine? https://github.com/rust-lang/cargo/blob/de6bce9aaef528572cd2307fbf3b245c0dab8566/src/cargo/ops/cargo_compile.rs#L519 |
Does it work for you? (Even with /usr/lib, but using .cargo/config)? |
Seems to:
|
I believe this should do the right thing: #565. |
Thanks! Those vars seem to be letting compilation complete! I am seeing that it prevents caching: The last hash changes every build, although I can verify .cargo/config is not being touched. Is this happening for you? |
Yeah, I am seeing openssl-sys rebuilding if I touch src/main.rs. Seems like a bug to file on Cargo I think. Build script overrides have not been very heavily used I don't think so it's not super surprising. |
I took a couple weeks off Rust to try out several different versions of the flu. I'm back, and have filed rust-lang/cargo#3658 For me, no file changes (nor modified date changes) are required to force a rebuild. |
It would not appear there there is a workaround this. Cargo randomizes order before hashing. |
Dropping "conf" increased the success rate from 25% to 50% (leaving just the randomized order of rustc-link-lib). |
Cargo PR: rust-lang/cargo#3659 |
As openssl-sys adds the world to the link path, it prevents linking against any libs that have a different version in /usr/lib
It appears that link path order is randomized by cargo, so this will cause nicely randomized link failures if other native crates are in use (or silently cause the wrong/unpatched version of a lib to be linked instead).
This can be fixed by producing the following output instead:
The text was updated successfully, but these errors were encountered: