]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/dylib_util.rs
Rollup merge of #107271 - Zeegomo:drop-rmw, r=oli-obk
[rust.git] / src / bootstrap / dylib_util.rs
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.
8 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 {
16         "LD_LIBRARY_PATH"
17     }
18 }
19
20 /// Parses the `dylib_path_var()` environment variable, returning a list of
21 /// paths that are members of this lookup path.
22 pub fn dylib_path() -> Vec<PathBuf> {
23     let var = match env::var_os(dylib_path_var()) {
24         Some(v) => v,
25         None => return vec![],
26     };
27     env::split_paths(&var).collect()
28 }