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 78 79 80 81 82 83
use std::path::PathBuf; use crate::build::CApiConfig; 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], capi_config: &CApiConfig, ) -> BuildTargets { let pc = targetdir.join(&format!("{}.pc", name)); let mut header_name = PathBuf::from(&capi_config.header.name); header_name.set_extension("h"); let include = targetdir.join(&header_name); let lib_name = &capi_config.library.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", _) | ("android", _) => { let static_lib = targetdir.join(&format!("lib{}.a", lib_name)); let shared_lib = targetdir.join(&format!("lib{}.so", lib_name)); (shared_lib, static_lib, None, None) } ("macos", _) | ("ios", _) => { let static_lib = targetdir.join(&format!("lib{}.a", lib_name)); let shared_lib = targetdir.join(&format!("lib{}.dylib", lib_name)); (shared_lib, static_lib, None, None) } ("windows", ref env) => { let static_lib = if *env == "msvc" { targetdir.join(&format!("{}.lib", lib_name)) } else { targetdir.join(&format!("lib{}.a", lib_name)) }; let shared_lib = targetdir.join(&format!("{}.dll", lib_name)); let impl_lib = if *env == "msvc" { targetdir.join(&format!("{}.dll.lib", lib_name)) } else { targetdir.join(&format!("{}.dll.a", lib_name)) }; let def = targetdir.join(&format!("{}.def", lib_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, } } }