in src/bindgen/cargo/cargo.rs [186:205]
fn find_pkg_to_generate_bindings_ref(&self, package_name: &str) -> Option<PackageRef> {
// Keep a list of candidates in case the manifest check fails, so that the old behavior
// still applies, returning the first package that was found
let mut candidates = vec![];
for package in &self.metadata.packages {
if package.name_and_version.name == package_name {
// If we are sure it is the right package return it
if Path::new(package.manifest_path.as_str()) == self.manifest_path {
return Some(package.name_and_version.clone());
}
// Otherwise note that a package was found
candidates.push(package.name_and_version.clone());
}
}
// If we could not verify the manifest path but we found candidates return the first one if
// any, this is the old behavior which did not check for manifest path, kept for backwards
// compatibility
candidates.into_iter().next()
}