-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
cargo run
exports bad DYLD_LIBRARY_PATH on macOS
#3366
Comments
This is a pretty tricky issue but I think the solution is that we should probably just not try to add any "system directories" to @casey would you be willing to help test out a patch for this? I think the relevant section of code is here and we likely just want to filter out paths that aren't in the build directory. |
Sure, I'd be happy to. One thing I'm curious about, when is DYLD_LIBRARY_PATH necessary for a binary to work? All my binaries seem to run fine without it. |
It's sometimes needed for plugins but it's primarily used for build scripts which generate dynamic native libraries. |
I've run into the same problem with |
@pkgw ok! If you need any help just let me know. I think the basic patch here is to just only append paths that look like they're in the cargo build directory, and ignore others. |
…arch paths. This drops `native_dirs` entries that are not within the target directory when modifying the (DY)LD_LIBRARY_PATH environment variable before running programs.
OK, I've create a pull request, #3651, that applies this strategy. I was even able to test it and it works in my test case! However, I have to admit that I mostly forget what's even going on in this code, so I'm far from confident that it's doing the right thing. Fortunately it's only a few lines' worth of changes. My test case:
However, I just ran the test suite and the patch definitely breaks the |
Oh hey, I was updating the README for |
I do agree with the assessment that setting |
@sgrif thanks for confirming the fix! I'd also be totally up for leveraging |
I believe this was fixed in #3651 |
I'm seeing this on stable (
|
Hi, new to rust and having the same problem (downloading everything via
|
@ns-cweber or @aredier do you know what installed
And maybe try running this inside your hello-world project:
I'm wondering if this might get fixed by #6355. I'm unable to reproduce, so I'd like to get to the bottom of it (this has been reported a few times — rust-lang/rust#34869 rust-lang/rust#36250). EDIT: Just FYI, jpeg comes in from a long dependency chain Security → Foundation → CoreServices → QuartzCore →... → ImageIO. I'm a little confused how |
@ehuss It seemed I used the wrong version of rustup ( however if you still want the info on my system: libjpeg was installed as a dependency by brew on my system (MacOS 10.14.1).
and
as for
it gave a command not found |
We just fixed that URL yesterday, btw: #6455 |
See also rust-lang/rustup#1507 @alexcrichton would it be possible to add a redirect on https://static.rust-lang.org/rustup.sh to https://sh.rustup.rs? It has an ancient 3 year old version from https://github.com/rust-lang-deprecated/rustup.sh. Considering some documentation (like Cargo) still points at that old version (links in TRPL up to 1.13 link to the old version — https://doc.rust-lang.org/1.13.0/book/getting-started.html — fixed in rust-lang/rust#38122). |
An excellent idea, done now! |
Hm, maybe that wasn't the best idea. curl without
If it can't point directly at the up-to-date file, maybe replace it with something like this: #!/bin/bash
echo "The location of rustup.sh has moved."
echo "Run the following command to install from the new location:"
echo " curl https://sh.rustup.rs -sSf | sh" (or whatever wording sounds good) |
Yeah it's true that without |
The old book had -L, but cargo does not. None of the modern documentation uses it either (book, rustup). |
Oh for sure I think I've figured out a good middle-ground though, the HTTP redirect response body now contains the shell script you recommended, so if |
Genius. |
@alexcrichton Just a suggestion, to add |
Hi; just came here to say this is still very much an issue. I am trying to port rust/cargo to mxe (I'm on MacOS) and am seeing the exact same issue with Really, There must be some way to get around this (because MacPorts itself doesn't have this issue when building Rust) but I haven't yet found the way to do it. Sent with GitHawk |
@Lord-Kamina |
@ehuss I am not using rustup; I am trying to build and seeing these issues with rust 1.36 and cargo 0.37 (downloaded from https://static.rust-lang.org/dist/2019-07-04), running EDIT: Ignore me, you're correct; cargo at least is correctly setting only Sent with GitHawk |
I've been going down the rabbit hole for a while on this one. Thankfully though, it seems like it's actually hopefully a pretty simple fix. Or, if it isn't, at least maybe I'm reporting the issue in the right repo ^_^
I originally thought it was a git2-rs issue, and reported it in https://github.com/alexcrichton/git2-rs/issues/175. Then I thought it was a rustc issue, and reported it here: rust-lang/rust#36250.
Finally though, I've gotten to the bottom of it, and it appears to be a cargo bug.
A few things need to happen to trigger the issue:
We are linking ina dynamic library that is not provided by the system, for example something from homebrew in
/usr/local/lib
, or from macports in/opt/local/lib
.We are also linking in a system framework.
In the nonstandard location in 1., there is a dynamically linked library which the system framework from 2. needs. However, this library in 1. is not the version that the framework expects.
We run the binary with
cargo run
.To make everything concrete, let's say that we're linking in
openssl
provided by macports in/opt/local/lib
, the framework we're using is theApplicationServices
framework, and we also happen to havelibiconv
installed in/opt/local/lib
.Cargo will export
DYLD_LIBRARY_PATH=/opt/local/lib:...
, and we'll get the following error:What's happening is that the
LanguageModeling
framework, which is a transitive dependency of theApplicationServices
framework also depends onlibiconv
. Normally it finds it in/usr/lib/libiconv.dylib
. However, because of the value ofDYLD_LIBRARY_PATH
, it finds it in/usr/local/lib/libiconv.dylib
, and we get the error because it is the wrong version with a missing symbol.If we run the binary directly, without the environment variable, it works:
Although the conditions needed to trigger this bug may seem esoteric, they are actually very common on mac development machines. Developers often have a ton of stuff installed via macports or homebrew.
There are a few ways that this might be resolved:
The
DYLD_LIBRARY_PATH
value seems to be unnecessary at least in this case, since the binary works when run directly. If so, perhaps we can avoid exporting it so as not to cause this breakage? However, perhaps there are other situations where the variable is necessary to find libraries? What's the purpose of the export?If the
DYLD_LIBRARY_PATH
value is necessary, then we need to communicate that to developers somehow. It would be very frustrating to have a binary which runs withcargo run
, but which cannot be run directly.And, if we do need
DYLD_LIBRARY_PATH
, then we should consider ifDYLD_FALLBACK_LIBRARY_PATH
might suffice.DYLD_FALLBACK_LIBRARY_PATH
does not disrupt the normal order of dynamic library lookup, but instead is only consulted if the dynamic linker cannot find a library in the normal places.The text was updated successfully, but these errors were encountered: