Skip to content

Commit

Permalink
Merge #1299
Browse files Browse the repository at this point in the history
1299: Fix build error when required features of bin target isn't enabled r=messense a=messense



Co-authored-by: messense <messense@icloud.com>
  • Loading branch information
bors[bot] and messense authored Nov 26, 2022
2 parents de6b0a8 + 6e496a9 commit 33d9c73
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

* Bump MSRV to 1.62.0 in [#1297](https://github.com/PyO3/maturin/pull/1297)
* Fix build error when required features of bin target isn't enabled in [#1299](https://github.com/PyO3/maturin/pull/1299)

## [0.14.2] - 2022-11-24

Expand Down
21 changes: 20 additions & 1 deletion src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,30 @@ pub fn compile(
bindings_crate: &BridgeModel,
) -> Result<Vec<HashMap<String, BuildArtifact>>> {
let root_pkg = context.cargo_metadata.root_package().unwrap();
let resolved_features = context
.cargo_metadata
.resolve
.as_ref()
.and_then(|resolve| resolve.nodes.iter().find(|node| node.id == root_pkg.id))
.map(|node| node.features.clone())
.unwrap_or_default();
let mut targets: Vec<_> = root_pkg
.targets
.iter()
.filter(|target| match bindings_crate {
BridgeModel::Bin(_) => target.kind.contains(&"bin".to_string()),
BridgeModel::Bin(_) => {
let is_bin = target.kind.contains(&"bin".to_string());
if target.required_features.is_empty() {
is_bin
} else {
// Check all required features are enabled for this bin target
is_bin
&& target
.required_features
.iter()
.all(|f| resolved_features.contains(f))
}
}
_ => target.kind.contains(&"cdylib".to_string()),
})
.collect();
Expand Down

0 comments on commit 33d9c73

Please sign in to comment.