1 // Various utilities for working with dylib paths.
2 //
3 // This file is meant to be included directly to avoid a dependency on the bootstrap library from
4 // the rustc and rustdoc wrappers. This improves compilation time by reducing the linking time.
5
6 /// Returns the environment variable which the dynamic library lookup path
7 /// resides in for this platform.
dylib_path_var() -> &'static str8 pub fn dylib_path_var() -> &'static str {
9 if cfg!(target_os = "windows") {
10 "PATH"
11 } else if cfg!(target_os = "macos") {
12 "DYLD_LIBRARY_PATH"
13 } else if cfg!(target_os = "haiku") {
14 "LIBRARY_PATH"
15 } else if cfg!(target_os = "aix") {
16 "LIBPATH"
17 } else {
18 "LD_LIBRARY_PATH"
19 }
20 }
21
22 /// Parses the `dylib_path_var()` environment variable, returning a list of
23 /// paths that are members of this lookup path.
dylib_path() -> Vec<PathBuf>24 pub fn dylib_path() -> Vec<PathBuf> {
25 let var = match env::var_os(dylib_path_var()) {
26 Some(v) => v,
27 None => return vec![],
28 };
29 env::split_paths(&var).collect()
30 }
31