Skip to content

Commit

Permalink
Avoid adding DYLD_FALLBACK_LIBRARY_PATH defaults when it is set
Browse files Browse the repository at this point in the history
The macos dynamic linker behavior wrt DYLD_FALLBACK_LIBRARY_PATH is to
use the value it is set with, and if there is no such value (the
environment variable is either not set or set but empty), it uses a
default value of $HOME/lib:/usr/local/lib:/usr/lib.

Currently, cargo takes the value of DYLD_FALLBACK_LIBRARY_PATH, prepends
its paths to it, and then unconditionally adds
$HOME/lib:/usr/local/lib:/usr/lib, which in principle, shouldn't happen
if DYLD_FALLBACK_LIBRARY_PATH was set originally.
  • Loading branch information
glandium committed Apr 16, 2019
1 parent 165be97 commit 416ed03
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,13 @@ impl<'cfg> Compilation<'cfg> {
search_path
};

search_path.extend(util::dylib_path().into_iter());
if cfg!(target_os = "macos") {
let dylib_path = util::dylib_path();
let dylib_path_is_empty = dylib_path.is_empty();
search_path.extend(dylib_path.into_iter());
if cfg!(target_os = "macos") && dylib_path_is_empty {
// These are the defaults when DYLD_FALLBACK_LIBRARY_PATH isn't
// set. Since Cargo is explicitly setting the value, make sure the
// defaults still work.
// set or set to an empty string. Since Cargo is explicitly setting
// the value, make sure the defaults still work.
if let Some(home) = env::var_os("HOME") {
search_path.push(PathBuf::from(home).join("lib"));
}
Expand Down
4 changes: 4 additions & 0 deletions tests/testsuite/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,4 +1228,8 @@ fn run_link_system_path_macos() {
// was set by the cargo that invoked the test.
p2.cargo("run").env_remove(VAR).run();
p2.cargo("test").env_remove(VAR).run();
// Ensure this still works when DYLD_FALLBACK_LIBRARY_PATH has
// a value set.
p2.cargo("run").env(VAR, &libdir).run();
p2.cargo("test").env(VAR, &libdir).run();
}

0 comments on commit 416ed03

Please sign in to comment.