Skip to content

Commit b978d11

Browse files
committed
Auto merge of #6856 - glandium:DYLD_FALLBACK_LIBRARY_PATH, r=alexcrichton
Cleanups wrt DYLD_FALLBACK_LIBRARY_PATH handling
2 parents b6581d3 + 416ed03 commit b978d11

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/cargo/core/compiler/compilation.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,17 @@ impl<'cfg> Compilation<'cfg> {
178178
search_path
179179
};
180180

181-
search_path.extend(util::dylib_path().into_iter());
182-
if cfg!(target_os = "macos") {
181+
let dylib_path = util::dylib_path();
182+
let dylib_path_is_empty = dylib_path.is_empty();
183+
search_path.extend(dylib_path.into_iter());
184+
if cfg!(target_os = "macos") && dylib_path_is_empty {
183185
// These are the defaults when DYLD_FALLBACK_LIBRARY_PATH isn't
184-
// set. Since Cargo is explicitly setting the value, make sure the
185-
// defaults still work.
186-
if let Ok(home) = env::var("HOME") {
186+
// set or set to an empty string. Since Cargo is explicitly setting
187+
// the value, make sure the defaults still work.
188+
if let Some(home) = env::var_os("HOME") {
187189
search_path.push(PathBuf::from(home).join("lib"));
188190
}
189191
search_path.push(PathBuf::from("/usr/local/lib"));
190-
search_path.push(PathBuf::from("/lib"));
191192
search_path.push(PathBuf::from("/usr/lib"));
192193
}
193194
let search_path = join_paths(&search_path, util::dylib_path_envvar())?;

tests/testsuite/run.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,13 @@ fn run_link_system_path_macos() {
12231223
)
12241224
.unwrap();
12251225
p.root().rm_rf();
1226-
p2.cargo("run").run();
1227-
p2.cargo("test").run();
1226+
const VAR: &str = "DYLD_FALLBACK_LIBRARY_PATH";
1227+
// Reset DYLD_FALLBACK_LIBRARY_PATH so that we don't inherit anything that
1228+
// was set by the cargo that invoked the test.
1229+
p2.cargo("run").env_remove(VAR).run();
1230+
p2.cargo("test").env_remove(VAR).run();
1231+
// Ensure this still works when DYLD_FALLBACK_LIBRARY_PATH has
1232+
// a value set.
1233+
p2.cargo("run").env(VAR, &libdir).run();
1234+
p2.cargo("test").env(VAR, &libdir).run();
12281235
}

0 commit comments

Comments
 (0)