Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,17 @@ 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.
if let Ok(home) = env::var("HOME") {
// 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"));
}
search_path.push(PathBuf::from("/usr/local/lib"));
search_path.push(PathBuf::from("/lib"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove /lib?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's explained in the corresponding commit message. In short, contrary to what the dyld documentation says, it's not in the default, and never has been (and the doc has always been wrong).

search_path.push(PathBuf::from("/usr/lib"));
}
let search_path = join_paths(&search_path, util::dylib_path_envvar())?;
Expand Down
11 changes: 9 additions & 2 deletions tests/testsuite/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,13 @@ fn run_link_system_path_macos() {
)
.unwrap();
p.root().rm_rf();
p2.cargo("run").run();
p2.cargo("test").run();
const VAR: &str = "DYLD_FALLBACK_LIBRARY_PATH";
// Reset DYLD_FALLBACK_LIBRARY_PATH so that we don't inherit anything that
// 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();
}