Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 100 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ anyhow = "1.0.80"
base64 = "0.22.0"
glob = "0.3.0"
cargo-config2 = "0.1.24"
cargo_metadata = "0.19.0"
cargo_metadata = "0.20.0"
cargo-options = "0.7.2"
cbindgen = { version = "0.29.0", default-features = false }
flate2 = "1.0.18"
Expand Down
32 changes: 21 additions & 11 deletions src/build_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,16 +946,16 @@ fn filter_cargo_targets(
config_targets: Option<&[crate::pyproject_toml::CargoTarget]>,
) -> Result<Vec<CompileTarget>> {
let root_pkg = cargo_metadata.root_package().unwrap();
let resolved_features = cargo_metadata
let resolved_features: Vec<String> = cargo_metadata
.resolve
.as_ref()
.and_then(|resolve| resolve.nodes.iter().find(|node| node.id == root_pkg.id))
.map(|node| node.features.clone())
.and_then(|resolve| resolve.nodes.iter().find(|&node| node.id == root_pkg.id))
.map(|node| node.features.iter().map(|f| f.to_string()).collect())
.unwrap_or_default();
let mut targets: Vec<_> = root_pkg
.targets
.iter()
.filter(|target| match bridge {
.filter(|&target| match bridge {
BridgeModel::Bin(_) => {
let is_bin = target.is_bin();
if target.required_features.is_empty() {
Expand Down Expand Up @@ -1028,15 +1028,19 @@ fn filter_cargo_targets(
fn has_abi3(deps: &HashMap<&str, &Node>) -> Result<Option<Abi3Version>> {
for &lib in PYO3_BINDING_CRATES.iter() {
let lib = lib.as_str();
if let Some(pyo3_crate) = deps.get(lib) {
if let Some(&pyo3_crate) = deps.get(lib) {
// Find the minimal abi3 python version. If there is none, abi3 hasn't been selected
// This parser abi3-py{major}{minor} and returns the minimal (major, minor) tuple
let abi3_selected = pyo3_crate.features.iter().any(|x| x == "abi3");
let abi3_selected = pyo3_crate
.features
.iter()
.map(AsRef::as_ref)
.any(|x| x == "abi3");

let min_abi3_version = pyo3_crate
.features
.iter()
.filter(|x| x.starts_with("abi3-py") && x.len() >= "abi3-pyxx".len())
.filter(|&x| x.starts_with("abi3-py") && x.len() >= "abi3-pyxx".len())
.map(|x| {
Ok((
(x.as_bytes()[7] as char).to_string().parse::<u8>()?,
Expand Down Expand Up @@ -1072,10 +1076,11 @@ fn is_generating_import_lib(cargo_metadata: &Metadata) -> Result<bool> {
.filter(|package| cargo_metadata[&package.id].name.as_str() == lib)
.collect::<Vec<_>>();
match pyo3_packages.as_slice() {
[pyo3_crate] => {
&[pyo3_crate] => {
let generate_import_lib = pyo3_crate
.features
.iter()
.map(AsRef::as_ref)
.any(|x| x == "generate-import-lib" || x == "generate-abi3-import-lib");
return Ok(generate_import_lib);
}
Expand Down Expand Up @@ -1176,9 +1181,9 @@ pub fn find_bridge(cargo_metadata: &Metadata, bridge: Option<&str>) -> Result<Br
.packages
.iter()
.filter_map(|pkg| {
let name = &pkg.name;
let name = pkg.name.as_ref();
if name == "pyo3" || name == "pyo3-ffi" || name == "cpython" || name == "uniffi" {
Some((name.as_ref(), pkg))
Some((name, pkg))
} else {
None
}
Expand Down Expand Up @@ -1251,7 +1256,12 @@ pub fn find_bridge(cargo_metadata: &Metadata, bridge: Option<&str>) -> Result<Br
if !bridge.is_bin() && bridge.is_pyo3_crate(lib) {
let lib_name = lib.as_str();
let pyo3_node = deps[lib_name];
if !pyo3_node.features.contains(&"extension-module".to_string()) {
if !pyo3_node
.features
.iter()
.map(AsRef::as_ref)
.any(|f| f == "extension-module")
{
let version = &cargo_metadata[&pyo3_node.id].version;
if (version.major, version.minor) < (0, 26) {
// pyo3 0.26+ will use the `PYO3_BUILD_EXTENSION_MODULE` env var instead
Expand Down
6 changes: 3 additions & 3 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ fn compile_target(
};

// Extract the location of the .so/.dll/etc. from cargo's json output
if crate_name == &context.crate_name {
if crate_name.as_ref() == context.crate_name {
let tuples = artifact
.target
.crate_types
Expand Down Expand Up @@ -677,9 +677,9 @@ fn pyo3_version(cargo_metadata: &cargo_metadata::Metadata) -> Option<(u64, u64,
.packages
.iter()
.filter_map(|pkg| {
let name = &pkg.name;
let name = pkg.name.as_ref();
if name == "pyo3" || name == "pyo3-ffi" {
Some((name.as_ref(), pkg))
Some((name, pkg))
} else {
None
}
Expand Down
2 changes: 1 addition & 1 deletion src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ impl Metadata24 {
license: package.license.clone(),
license_files,
project_url,
..Metadata24::new(name, version)
..Metadata24::new(name.to_string(), version)
};
Ok(metadata)
}
Expand Down
4 changes: 2 additions & 2 deletions src/source_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,15 @@ pub fn find_path_deps(cargo_metadata: &Metadata) -> Result<HashMap<String, PathD
let dependency = top
.dependencies
.iter()
.find(|package| {
.find(|&package| {
// Package ids are opaque and there seems to be no way to query their name.
let dep_name = &cargo_metadata
.packages
.iter()
.find(|package| &package.id == dep_id)
.unwrap()
.name;
&package.name == dep_name
package.name == dep_name.as_ref()
})
.unwrap();
if let Some(path) = &dependency.path {
Expand Down
Loading