Skip to content

Commit

Permalink
Implement installing MSVC debug symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
amyspark committed May 4, 2024
1 parent 58f3133 commit 6fc7e69
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/build_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub struct BuildTargets {
pub static_lib: Option<PathBuf>,
pub shared_lib: Option<PathBuf>,
pub impl_lib: Option<PathBuf>,
pub debug_info: Option<PathBuf>,
pub def: Option<PathBuf>,
pub pc: PathBuf,
pub target: Target,
Expand Down Expand Up @@ -75,7 +76,7 @@ impl BuildTargets {
let os = &target.os;
let env = &target.env;

let (shared_lib, static_lib, impl_lib, def) = match (os.as_str(), env.as_str()) {
let (shared_lib, static_lib, impl_lib, debug_info, def) = match (os.as_str(), env.as_str()) {
("none", _)
| ("linux", _)
| ("freebsd", _)
Expand All @@ -87,12 +88,12 @@ impl BuildTargets {
| ("emscripten", _) => {
let static_lib = targetdir.join(format!("lib{lib_name}.a"));
let shared_lib = targetdir.join(format!("lib{lib_name}.so"));
(shared_lib, static_lib, None, None)
(shared_lib, static_lib, None, None, None)
}
("macos", _) | ("ios", _) | ("tvos", _) => {
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)
(shared_lib, static_lib, None, None, None)
}
("windows", env) => {
let static_lib = if env == "msvc" {
Expand All @@ -107,7 +108,12 @@ impl BuildTargets {
targetdir.join(format!("{lib_name}.dll.a"))
};
let def = targetdir.join(format!("{lib_name}.def"));
(shared_lib, static_lib, Some(impl_lib), Some(def))
let pdb = if env == "msvc" {
Some(targetdir.join(format!("{lib_name}.pdb")))
} else {
None
};
(shared_lib, static_lib, Some(impl_lib), pdb, Some(def))
}
_ => unimplemented!("The target {}-{} is not supported yet", os, env),
};
Expand All @@ -131,6 +137,7 @@ impl BuildTargets {
static_lib,
shared_lib,
impl_lib,
debug_info,
def,
target: target.clone(),
extra: Default::default(),
Expand Down
25 changes: 25 additions & 0 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ pub fn cinstall(ws: &Workspace, packages: &[CPackage]) -> anyhow::Result<()> {
install_path_lib.push(subdir);
}

let install_path_bin = append_to_destdir(destdir.as_deref(), &paths.bindir);
let install_path_lib = append_to_destdir(destdir.as_deref(), &install_path_lib);
let install_path_pc = append_to_destdir(destdir.as_deref(), &paths.pkgconfigdir);
let install_path_include = append_to_destdir(destdir.as_deref(), &paths.includedir);
Expand Down Expand Up @@ -231,6 +232,30 @@ pub fn cinstall(ws: &Workspace, packages: &[CPackage]) -> anyhow::Result<()> {
)?;
}

if let Some(ref debug_info) = build_targets.debug_info {
ws.gctx()
.shell()
.status("Installing", "debugging information")?;
let lib_type = LibType::from_build_targets(build_targets);
match lib_type {
// FIXME: Requires setting split-debuginfo to packed and
// specifying the corresponding file name convention
// in BuildTargets::new.
LibType::So | LibType::Dylib => {
copy(
debug_info,
install_path_lib.join(debug_info.file_name().unwrap()),
)?;
}
LibType::Windows => {
copy(
debug_info,
install_path_bin.join(debug_info.file_name().unwrap()),
)?;
}
}
}

if let Some(ref shared_lib) = build_targets.shared_lib {
ws.gctx().shell().status("Installing", "shared library")?;

Expand Down

0 comments on commit 6fc7e69

Please sign in to comment.