diff --git a/src/build.rs b/src/build.rs index 9badcfa..48a726b 100644 --- a/src/build.rs +++ b/src/build.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; use std::hash::{DefaultHasher, Hash, Hasher}; -use std::io::Read; +use std::io::{ErrorKind, Read}; use std::path::{Path, PathBuf}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Mutex}; @@ -1277,7 +1277,33 @@ pub fn cbuild( from_build_targets.debug_info.as_ref(), build_targets.debug_info.as_ref(), ) { - copy(from_debug_info, to_debug_info)?; + if from_debug_info.exists() { + create_dir_all(to_debug_info.parent().unwrap())?; + if from_debug_info.is_dir() { + let files = + from_debug_info.read_dir()?.collect::, _>>()?; + for f in files.iter() { + let src = f.path(); + let file_name = src.strip_prefix(from_debug_info)?; + let dst = to_debug_info.join(file_name); + match std::fs::create_dir_all( + dst.parent().expect("Source path is not complete"), + ) { + Ok(()) => Ok(()), + Err(v) => { + if v.kind() == ErrorKind::AlreadyExists { + Ok(()) + } else { + Err(v) + } + } + }?; + copy(src, dst)?; + } + } else { + copy(from_debug_info, to_debug_info)?; + } + } } } diff --git a/src/build_targets.rs b/src/build_targets.rs index 53938bf..052355b 100644 --- a/src/build_targets.rs +++ b/src/build_targets.rs @@ -171,7 +171,8 @@ impl FileNames { "macos" | "ios" | "tvos" | "visionos" => { let static_lib = targetdir.join(format!("lib{lib_name}.a")); let shared_lib = targetdir.join(format!("lib{lib_name}.dylib")); - (shared_lib, static_lib, None, None, None) + let pdb = Some(targetdir.join(format!("lib{lib_name}.dSYM"))); + (shared_lib, static_lib, None, pdb, None) } "windows" => { let shared_lib = targetdir.join(format!("{lib_name}.dll")); @@ -194,9 +195,8 @@ impl FileNames { } else { targetdir.join(format!("{lib_name}.dll.a")) }; - let pdb = None; - (shared_lib, static_lib, Some(impl_lib), pdb, Some(def)) + (shared_lib, static_lib, Some(impl_lib), None, Some(def)) } } _ => return None, @@ -269,7 +269,7 @@ mod test { static_lib: PathBuf::from("/foo/bar/libferris.a"), shared_lib: PathBuf::from("/foo/bar/libferris.dylib"), impl_lib: None, - debug_info: None, + debug_info: Some(PathBuf::from("/foo/bar/libferris.dSYM")), def: None, }; diff --git a/src/install.rs b/src/install.rs index a934c32..f093af0 100644 --- a/src/install.rs +++ b/src/install.rs @@ -1,4 +1,5 @@ use clap::ArgMatches; +use std::io::ErrorKind; use std::path::{Component, Path, PathBuf}; use cargo::core::Workspace; @@ -285,12 +286,42 @@ pub fn cinstall(ws: &Workspace, packages: &[CPackage]) -> anyhow::Result<()> { ws.gctx() .shell() .status("Installing", "debugging information")?; - let destination_path = build_targets - .debug_info_file_name(&install_path_bin, &install_path_lib) - .unwrap(); + + let destination_path = if capi_config.library.install_subdir.is_none() { + build_targets + .debug_info_file_name(&install_path_bin, &install_path_lib) + .unwrap() + } else { + // We assume they are plugins, install them in the custom libdir path + build_targets + .debug_info_file_name(&install_path_lib, &install_path_lib) + .unwrap() + }; create_dir_all(destination_path.parent().unwrap())?; - copy(ws, debug_info, destination_path)?; + if debug_info.is_dir() { + let files = debug_info.read_dir()?.collect::, _>>()?; + for f in files.iter() { + let src = f.path(); + let file_name = src.strip_prefix(debug_info)?; + let dst = destination_path.join(file_name); + match std::fs::create_dir_all( + dst.parent().expect("Source path is not complete"), + ) { + Ok(()) => Ok(()), + Err(v) => { + if v.kind() == ErrorKind::AlreadyExists { + Ok(()) + } else { + Err(v) + } + } + }?; + copy(ws, src, dst)?; + } + } else { + copy(ws, debug_info, destination_path)?; + } } else { ws.gctx() .shell()