Line data Source code
1 : use lief_ffi as ffi;
2 : use std::path::Path;
3 :
4 : /// Enable globally cache/memoization. One can also leverage this function
5 : /// by setting the environment variable `DYLDSC_ENABLE_CACHE` to `1`
6 : ///
7 : /// By default, LIEF will use the directory specified by the environment
8 : /// variable `DYLDSC_CACHE_DIR` as its cache-root directory:
9 : ///
10 : /// ```bash
11 : /// DYLDSC_ENABLE_CACHE=1 DYLDSC_CACHE_DIR=/tmp/my_dir ./my-program
12 : /// ```
13 : ///
14 : /// Otherwise, if `DYLDSC_CACHE_DIR` is not set, LIEF will use the following
15 : /// directory (in this priority):
16 : ///
17 : /// 1. System or user cache directory
18 : /// - macOS: `DARWIN_USER_TEMP_DIR` / `DARWIN_USER_CACHE_DIR` + `/dyld_shared_cache`
19 : /// - Linux: `${XDG_CACHE_HOME}/dyld_shared_cache`
20 : /// - Windows: `%LOCALAPPDATA%\dyld_shared_cache`
21 : /// 2. Home directory
22 : /// - macOS/Linux: `$HOME/.dyld_shared_cache`
23 : /// - Windows: `%USERPROFILE%\.dyld_shared_cache`
24 : ///
25 : /// See [`crate::dsc::DyldSharedCache::enable_caching`] for a finer granularity
26 0 : pub fn enable_cache() -> bool {
27 0 : ffi::dsc_enable_cache()
28 0 : }
29 :
30 : /// Same behavior as [`enable_cache`] but with a user-provided cache directory
31 0 : pub fn enable_cache_from_dir<P: AsRef<Path>>(target_dir: P) -> bool {
32 0 : ffi::dsc_enable_cache_from_dir(target_dir.as_ref().to_str().unwrap())
33 0 : }
|