|
1 | 1 | use derive_more::Display;
|
| 2 | +use failure::*; |
| 3 | +use std::path::*; |
2 | 4 |
|
3 | 5 | #[derive(Debug, Clone, Copy, PartialEq, Display)]
|
4 | 6 | pub enum Link {
|
@@ -32,24 +34,82 @@ pub struct Config {
|
32 | 34 | }
|
33 | 35 |
|
34 | 36 | impl Config {
|
35 |
| - fn as_pkg_config_name(&self) -> String { |
| 37 | + pub fn from_name(_name: &str) -> Fallible<Self> { |
| 38 | + todo!() |
| 39 | + } |
| 40 | + |
| 41 | + /// identifier used in pkg-config |
| 42 | + pub fn name(&self) -> String { |
36 | 43 | format!("mkl-{}-{}-{}", self.link, self.index_size, self.parallel)
|
37 | 44 | }
|
38 | 45 |
|
| 46 | + fn base_dir(&self) -> PathBuf { |
| 47 | + todo!() |
| 48 | + } |
| 49 | + |
| 50 | + /// Static and shared library lists to be linked |
| 51 | + pub fn libs( |
| 52 | + &self, |
| 53 | + ) -> ( |
| 54 | + Vec<PathBuf>, /* static */ |
| 55 | + Vec<String>, /* shared */ |
| 56 | + ) { |
| 57 | + // FIXME this implementation is for Linux, fix for Windows and macOS |
| 58 | + let mut static_libs = Vec::new(); |
| 59 | + let mut shared_libs = vec!["pthread".into(), "m".into(), "dl".into()]; |
| 60 | + |
| 61 | + let mut add = |name: &str| match self.link { |
| 62 | + Link::Static => { |
| 63 | + let base_dir: PathBuf = self.base_dir(); |
| 64 | + let path = base_dir.join(format!("lib{}.a", name)); |
| 65 | + assert!(path.exists()); |
| 66 | + static_libs.push(path); |
| 67 | + } |
| 68 | + Link::Shared => { |
| 69 | + shared_libs.push(name.to_string()); |
| 70 | + } |
| 71 | + }; |
| 72 | + |
| 73 | + add("mkl_core"); |
| 74 | + match self.index_size { |
| 75 | + IndexSize::LP64 => { |
| 76 | + add("mkl_intel_lp64"); |
| 77 | + } |
| 78 | + IndexSize::ILP64 => { |
| 79 | + add("mkl_intel_ilp64"); |
| 80 | + } |
| 81 | + }; |
| 82 | + match self.parallel { |
| 83 | + Parallel::OpenMP => { |
| 84 | + add("iomp5"); |
| 85 | + add("mkl_intel_thread"); |
| 86 | + } |
| 87 | + Parallel::Sequential => { |
| 88 | + add("mkl_sequential"); |
| 89 | + } |
| 90 | + }; |
| 91 | + (static_libs, shared_libs) |
| 92 | + } |
| 93 | + |
39 | 94 | /// Check if pkg-config has a corresponding setting
|
40 |
| - pub fn is_pkg_config_managed(&self) -> bool { |
| 95 | + pub fn pkg_config(&self) -> Option<pkg_config::Library> { |
41 | 96 | pkg_config::Config::new()
|
42 | 97 | .cargo_metadata(false)
|
43 |
| - .probe(&self.as_pkg_config_name()) |
44 |
| - .is_ok() |
| 98 | + .probe(&self.name()) |
| 99 | + .ok() |
45 | 100 | }
|
46 | 101 |
|
47 | 102 | /// Check if archive is cached in $XDG_DATA_HOME
|
48 |
| - pub fn is_cached(&self) -> bool { |
| 103 | + pub fn exists(&self) -> bool { |
| 104 | + todo!() |
| 105 | + } |
| 106 | + |
| 107 | + /// Download MKL archive and cache into $XDG_DATA_HOME |
| 108 | + pub fn download(&self) -> PathBuf { |
49 | 109 | todo!()
|
50 | 110 | }
|
51 | 111 |
|
52 | 112 | pub fn print_cargo_metadata(&self) {
|
53 |
| - // |
| 113 | + todo!() |
54 | 114 | }
|
55 | 115 | }
|
0 commit comments