Skip to content

Commit

Permalink
cargo-coupler bundle: store crate name in PackageInfo
Browse files Browse the repository at this point in the history
Instead of recomputing it in multiple places, compute the crate name once and
store it alongside the package name in PackageInfo.
  • Loading branch information
micahrj committed Jan 10, 2024
1 parent 1937c6f commit 86e5fb5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cargo-coupler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ impl FromStr for Target {

struct PackageInfo {
package_name: String,
crate_name: String,
name: String,
format: Format,
}
Expand Down Expand Up @@ -406,6 +407,8 @@ fn bundle(cmd: &Bundle) {
process::exit(1);
};

let crate_name = package_name.replace('-', "_");

let has_cdylib = metadata.packages[index]
.targets
.iter()
Expand All @@ -420,6 +423,7 @@ fn bundle(cmd: &Bundle) {

packages_to_build.push(PackageInfo {
package_name,
crate_name,
name: coupler_metadata.name.as_ref().unwrap_or(&package.name).clone(),
format,
});
Expand Down Expand Up @@ -534,8 +538,7 @@ fn bundle(cmd: &Bundle) {
}

fn bundle_clap(package_info: &PackageInfo, out_dir: &Path, target: &Target) {
let package_name = &package_info.package_name;
let crate_name = package_name.replace('-', "_");
let crate_name = &package_info.crate_name;
let src = match target.os {
Os::Linux => out_dir.join(format!("lib{crate_name}.so")),
Os::MacOs => out_dir.join(format!("lib{crate_name}.dylib")),
Expand Down Expand Up @@ -568,8 +571,7 @@ fn bundle_clap(package_info: &PackageInfo, out_dir: &Path, target: &Target) {
}

fn bundle_vst3(package_info: &PackageInfo, out_dir: &Path, target: &Target) {
let package_name = &package_info.package_name;
let crate_name = package_name.replace('-', "_");
let crate_name = &package_info.crate_name;
let src = match target.os {
Os::Linux => out_dir.join(format!("lib{crate_name}.so")),
Os::MacOs => out_dir.join(format!("lib{crate_name}.dylib")),
Expand Down

0 comments on commit 86e5fb5

Please sign in to comment.