use lazy_static::lazy_static;
use std::env;
use std::path::PathBuf;

lazy_static! {
    pub static ref CARGO_TARGET_DIR: PathBuf = {
        match env::var_os("CARGO_TARGET_DIR") {
            Some(v) => v.into(),
            None => env::current_dir().unwrap().join("target"),
        }
    };
    pub static ref TARGET_LIB: PathBuf = {
        if let Some(path) = option_env!("TARGET_LIBS") {
            path.into()
        } else {
            let mut dir = CARGO_TARGET_DIR.clone();
            if let Some(target) = env::var_os("CARGO_BUILD_TARGET") {
                dir.push(target);
            }
            dir.push(env!("PROFILE"));
            dir
        }
    };
}

#[must_use]
pub fn is_rustc_test_suite() -> bool {
    option_env!("RUSTC_TEST_SUITE").is_some()
}

use cargo_metadata::MetadataCommand;
use lazy_static::lazy_static;
use std::env;
use std::path::PathBuf;

lazy_static! {
    pub static ref CARGO_TARGET_DIR: PathBuf = {
        match env::var_os("CARGO_TARGET_DIR") {
            Some(v) => v.into(),
            None => MetadataCommand::new().exec().unwrap().target_directory,
        }
    };
    pub static ref TARGET_LIB: PathBuf = {
        if let Some(path) = option_env!("TARGET_LIBS") {
            path.into()
        } else {
            let mut dir = CARGO_TARGET_DIR.clone();
            if let Some(target) = env::var_os("CARGO_BUILD_TARGET") {
                dir.push(target);
            }
            dir.push(env!("PROFILE"));
            dir
        }
    };
}

#[must_use]
pub fn is_rustc_test_suite() -> bool {
    option_env!("RUSTC_TEST_SUITE").is_some()
}

--- 
+++ 
@@ -1,4 +1,3 @@
-use cargo_metadata::MetadataCommand;
 use lazy_static::lazy_static;
 use std::env;
 use std::path::PathBuf;
@@ -7,7 +6,7 @@
     pub static ref CARGO_TARGET_DIR: PathBuf = {
         match env::var_os("CARGO_TARGET_DIR") {
             Some(v) => v.into(),
-            None => MetadataCommand::new().exec().unwrap().target_directory,
+            None => env::current_dir().unwrap().join("target"),
         }
     };
     pub static ref TARGET_LIB: PathBuf = {
Use current_dir instead of cargo_metadata

Co-Authored-By: lzutao <85091462e78fd40a2da260069fd10aa5bbcf7c19@gmail.com>