1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
use std::path::PathBuf; use crate::target::Target; #[derive(Debug)] pub struct BuildTargets { pub include: PathBuf, pub static_lib: Option<PathBuf>, pub shared_lib: Option<PathBuf>, pub impl_lib: Option<PathBuf>, pub def: Option<PathBuf>, pub pc: PathBuf, } impl BuildTargets { pub fn new( name: &str, target: &Target, targetdir: &PathBuf, libkinds: &[&str], ) -> BuildTargets { let pc = targetdir.join(&format!("{}.pc", name)); let include = targetdir.join(&format!("{}.h", name)); let os = &target.os; let env = &target.env; let (shared_lib, static_lib, impl_lib, def) = match (os.as_str(), env.as_str()) { ("linux", _) | ("freebsd", _) | ("dragonfly", _) | ("netbsd", _) => { let static_lib = targetdir.join(&format!("lib{}.a", name)); let shared_lib = targetdir.join(&format!("lib{}.so", name)); (shared_lib, static_lib, None, None) } ("macos", _) => { let static_lib = targetdir.join(&format!("lib{}.a", name)); let shared_lib = targetdir.join(&format!("lib{}.dylib", name)); (shared_lib, static_lib, None, None) } ("windows", ref env) => { let static_lib = if *env == "msvc" { targetdir.join(&format!("{}.lib", name)) } else { targetdir.join(&format!("lib{}.a", name)) }; let shared_lib = targetdir.join(&format!("{}.dll", name)); let impl_lib = if *env == "msvc" { targetdir.join(&format!("{}.dll.lib", name)) } else { targetdir.join(&format!("{}.dll.a", name)) }; let def = targetdir.join(&format!("{}.def", name)); (shared_lib, static_lib, Some(impl_lib), Some(def)) } _ => unimplemented!("The target {}-{} is not supported yet", os, env), }; let static_lib = if libkinds.contains(&"staticlib") { Some(static_lib) } else { None }; let shared_lib = if libkinds.contains(&"cdylib") { Some(shared_lib) } else { None }; BuildTargets { pc, include, static_lib, shared_lib, impl_lib, def, } } }