build_probe_mpi/os/
windows.rs

1#![deny(missing_docs)]
2#![warn(missing_copy_implementations)]
3#![warn(trivial_casts)]
4#![warn(trivial_numeric_casts)]
5#![warn(unused_extern_crates)]
6#![warn(unused_import_braces)]
7#![warn(unused_qualifications)]
8
9use super::super::Library;
10use std::{env, error::Error, fmt, path::PathBuf};
11
12#[derive(Debug)]
13struct VarError {
14    key: String,
15    origin: env::VarError,
16}
17
18impl fmt::Display for VarError {
19    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20        write!(f, "{}: {}", self.key, self.origin)
21    }
22}
23
24impl Error for VarError {
25    fn source(&self) -> Option<&(dyn Error + 'static)> {
26        Some(&self.origin)
27    }
28}
29
30fn var(key: &str) -> Result<String, VarError> {
31    env::var(key).map_err(|e| VarError {
32        key: key.to_owned(),
33        origin: e,
34    })
35}
36
37/// Probe the environment for MS-MPI
38pub fn probe() -> Result<Library, Vec<Box<dyn Error>>> {
39    let mut errs: Vec<Box<dyn Error>> = vec![];
40
41    let include_path = match var("MSMPI_INC") {
42        Ok(include_path) => Some(include_path),
43        Err(err) => {
44            errs.push(Box::new(err));
45            None
46        }
47    };
48
49    let lib_env = if env::var("CARGO_CFG_TARGET_ARCH") == Ok("x86".to_string()) {
50        "MSMPI_LIB32"
51    } else if env::var("CARGO_CFG_TARGET_ARCH") == Ok("x86_64".to_string()) {
52        "MSMPI_LIB64"
53    } else {
54        panic!("rsmpi does not support your windows architecture!");
55    };
56
57    let lib_path = match var(lib_env) {
58        Ok(lib_path) => Some(lib_path),
59        Err(err) => {
60            errs.push(Box::new(err));
61            None
62        }
63    };
64
65    if errs.len() > 0 {
66        return Err(errs);
67    }
68
69    Ok(Library {
70        mpicc: None,
71        libs: vec!["msmpi".to_owned()],
72        lib_paths: vec![lib_path.map(PathBuf::from).unwrap()],
73        include_paths: vec![include_path.map(PathBuf::from).unwrap()],
74        version: String::from("MS-MPI"),
75        _priv: (),
76    })
77}