Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let XWIN_CACHE_DIR override cmake cache #74

Merged
merged 2 commits into from
Oct 27, 2023
Merged
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
39 changes: 24 additions & 15 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,16 @@ impl XWinOptions {
cargo: &cargo_options::CommonOptions,
cmd: &mut Command,
) -> Result<()> {
let xwin_cache_dir = self.xwin_cache_dir.clone().unwrap_or_else(|| {
dirs::cache_dir()
// If the really is no cache dir, cwd will also do
.unwrap_or_else(|| env::current_dir().expect("Failed to get current dir"))
.join(env!("CARGO_PKG_NAME"))
.join("xwin")
});
let xwin_cache_dir = self
.xwin_cache_dir
.clone()
.unwrap_or_else(|| {
dirs::cache_dir()
// If the really is no cache dir, cwd will also do
.unwrap_or_else(|| env::current_dir().expect("Failed to get current dir"))
.join(env!("CARGO_PKG_NAME"))
})
.join("xwin");
fs::create_dir_all(&xwin_cache_dir)?;
let xwin_cache_dir = xwin_cache_dir.canonicalize()?;

Expand Down Expand Up @@ -396,16 +399,22 @@ impl XWinOptions {
}

fn setup_cmake_toolchain(&self, target: &str, xwin_cache_dir: &Path) -> Result<PathBuf> {
let cache_dir = dirs::cache_dir()
.unwrap_or_else(|| env::current_dir().expect("Failed to get current dir"))
.join(env!("CARGO_PKG_NAME"));
let cmake = cache_dir.join("cmake");
fs::create_dir_all(&cmake)?;

let override_file = cmake.join("override.cmake");
let cmake_cache_dir = self
.xwin_cache_dir
.clone()
.unwrap_or_else(|| {
dirs::cache_dir()
// If the really is no cache dir, cwd will also do
.unwrap_or_else(|| env::current_dir().expect("Failed to get current dir"))
.join(env!("CARGO_PKG_NAME"))
})
.join("cmake");
fs::create_dir_all(&cmake_cache_dir)?;

let override_file = cmake_cache_dir.join("override.cmake");
fs::write(override_file, include_bytes!("override.cmake"))?;

let toolchain_file = cmake.join(format!("{}-toolchain.cmake", target));
let toolchain_file = cmake_cache_dir.join(format!("{}-toolchain.cmake", target));
let target_arch = target
.split_once('-')
.map(|(x, _)| x)
Expand Down
Loading