Skip to content

Commit

Permalink
cargo-coupler bundle: store lib name in PackageInfo
Browse files Browse the repository at this point in the history
Instead of recomputing it in multiple places, compute the lib filename once and
store it alongside the package name in PackageInfo.
  • Loading branch information
micahrj committed Jan 10, 2024
1 parent 1937c6f commit e9f1c33
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 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,
lib_name: String,
name: String,
format: Format,
}
Expand Down Expand Up @@ -418,8 +419,16 @@ fn bundle(cmd: &Bundle) {
process::exit(1);
}

let crate_name = package_name.replace('-', "_");
let lib_name = match target.os {
Os::Linux => format!("lib{crate_name}.so"),
Os::MacOs => format!("lib{crate_name}.dylib"),
Os::Windows => format!("{crate_name}.dll"),
};

packages_to_build.push(PackageInfo {
package_name,
lib_name,
name: coupler_metadata.name.as_ref().unwrap_or(&package.name).clone(),
format,
});
Expand Down Expand Up @@ -534,13 +543,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 src = match target.os {
Os::Linux => out_dir.join(format!("lib{crate_name}.so")),
Os::MacOs => out_dir.join(format!("lib{crate_name}.dylib")),
Os::Windows => out_dir.join(format!("{crate_name}.dll")),
};
let src = out_dir.join(&package_info.lib_name);

let name = &package_info.name;
let bundle_path = out_dir.join(format!("bundle/{name}.clap"));
Expand Down Expand Up @@ -568,13 +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 src = match target.os {
Os::Linux => out_dir.join(format!("lib{crate_name}.so")),
Os::MacOs => out_dir.join(format!("lib{crate_name}.dylib")),
Os::Windows => out_dir.join(format!("{crate_name}.dll")),
};
let src = out_dir.join(&package_info.lib_name);

let name = &package_info.name;
let bundle_path = out_dir.join(format!("bundle/{name}.vst3"));
Expand Down

0 comments on commit e9f1c33

Please sign in to comment.