1use crate::debug_log;
2
3pub fn is_msvc() -> bool {
5 if let Ok(target) = std::env::var("TARGET") {
6 target.contains("msvc")
7 } else {
8 false
9 }
10}
11
12pub fn is_mswin_or_mingw() -> bool {
14 if let Ok(target) = std::env::var("TARGET") {
15 target.contains("msvc") || target.contains("pc-windows-gnu")
16 } else {
17 false
18 }
19}
20
21pub fn shellsplit<S: AsRef<str>>(s: S) -> Vec<String> {
23 let s = s.as_ref();
24 match shell_words::split(s) {
25 Ok(v) => v,
26 Err(e) => {
27 debug_log!("WARN: shellsplit failed: {}", e);
28 s.split_whitespace().map(Into::into).collect()
29 }
30 }
31}
32
33#[macro_export]
34macro_rules! memoize {
35 ($type:ty: $val:expr) => {{
36 static INIT: std::sync::Once = std::sync::Once::new();
37 static mut VALUE: Option<$type> = None;
38 #[allow(static_mut_refs)]
39 unsafe {
40 INIT.call_once(|| {
41 VALUE = Some($val);
42 });
43 VALUE.as_ref().unwrap()
44 }
45 }};
46}
47
48#[macro_export]
49macro_rules! debug_log {
50 ($($arg:tt)*) => {
51 eprintln!($($arg)*);
52 };
53}