From 5e97a3951d8a6c6fe0f0c5b6b0f42a42563a2bc8 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 28 Nov 2022 15:15:40 +0000 Subject: [PATCH] Make sure the target dir is always explicitly set when using cargo --- build_system/mod.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/build_system/mod.rs b/build_system/mod.rs index 531f42cf873..ef1109afe0a 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -48,8 +48,15 @@ pub(crate) enum SysrootKind { pub fn main() { env::set_var("CG_CLIF_DISPLAY_CG_TIME", "1"); env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1"); - // The target dir is expected in the default location. Guard against the user changing it. - env::set_var("CARGO_TARGET_DIR", "target"); + + { + // Make sure we always explicitly specify the target dir + let target = "build/target_dir_should_be_set_explicitly"; + env::set_var("CARGO_TARGET_DIR", target); + std::fs::create_dir_all("build").unwrap(); + let _ = std::fs::remove_file(target); + let file = std::fs::File::create(target).unwrap(); + } if is_ci() { // Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway