Skip to content

Commit

Permalink
Patch the target name to the custom name if provided
Browse files Browse the repository at this point in the history
Fixes #166.
  • Loading branch information
lu-zero committed Feb 17, 2021
1 parent ac90801 commit 5b59fc0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ fn build_pc_file(
Ok(())
}

fn patch_lib_kind_in_target(ws: &mut Workspace, libkinds: &[&str]) -> anyhow::Result<()> {
fn patch_target(
ws: &mut Workspace,
libkinds: &[&str],
capi_config: &CApiConfig,
) -> anyhow::Result<()> {
use cargo::core::compiler::CrateType;

let pkg = ws.current_mut()?;
Expand All @@ -115,6 +119,7 @@ fn patch_lib_kind_in_target(ws: &mut Workspace, libkinds: &[&str]) -> anyhow::Re
for target in targets.iter_mut() {
if target.is_lib() {
target.set_kind(TargetKind::Lib(kinds.clone()));
target.set_name(&capi_config.library.name);
}
}

Expand Down Expand Up @@ -548,8 +553,6 @@ pub fn cbuild(
.map_or_else(|| vec!["staticlib", "cdylib"], |v| v.collect::<Vec<_>>());
let only_staticlib = !libkinds.contains(&"cdylib");

patch_lib_kind_in_target(ws, &libkinds)?;

let name = &ws
.current()?
.manifest()
Expand All @@ -562,6 +565,10 @@ pub fn cbuild(
let root_path = ws.current()?.root().to_path_buf();
let capi_config = load_manifest_capi_config(name, &root_path, &ws)?;

patch_target(ws, &libkinds, &capi_config)?;

let name = &capi_config.library.name;

let install_paths = InstallPaths::new(name, args, &capi_config);

let mut pc = PkgConfig::from_workspace(name, &install_paths, args, &capi_config);
Expand Down
2 changes: 1 addition & 1 deletion src/build_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl BuildTargets {
None
};

let lib_name = &capi_config.library.name;
let lib_name = name;

let os = &target.os;
let env = &target.env;
Expand Down

0 comments on commit 5b59fc0

Please sign in to comment.