Skip to content

Commit

Permalink
Add Cargo compile targets configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Dec 12, 2022
1 parent 1b5cdaa commit 5e10b05
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/cargo_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,24 @@ pub struct RemainingCoreMetadata {
pub name: Option<String>,
/// The directory containing the wheel data
pub data: Option<String>,
/// Cargo compile targets
pub targets: Option<Vec<CargoTarget>>,
#[serde(flatten)]
pub other: HashMap<String, toml_edit::easy::Value>,
}

/// Cargo compile target
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[serde(rename_all = "kebab-case")]
pub struct CargoTarget {
/// Name as given in the `Cargo.toml` or generated from the file name
pub name: String,
/// Kind of target ("bin", "lib")
pub kind: Option<String>,
/// Bridge model, which kind of bindings to use
pub bindings: Option<String>,
}

#[cfg(test)]
mod test {
use super::*;
Expand Down Expand Up @@ -137,11 +151,20 @@ mod test {
[package.metadata.maturin]
classifiers = ["Programming Language :: Python"]
requires-dist = ["flask~=1.1.0", "toml==0.10.0"]
[[package.metadata.maturin.targets]]
name = "pyo3_pure"
kind = "lib"
bindings = "pyo3"
"#
);

let cargo_toml: Result<CargoToml, _> = toml_edit::easy::from_str(cargo_toml);
assert!(cargo_toml.is_ok());

let maturin = cargo_toml.unwrap().remaining_core_metadata();
let targets = maturin.targets.unwrap();
assert_eq!("pyo3_pure", targets[0].name);
}

#[test]
Expand Down
7 changes: 7 additions & 0 deletions test-crates/hello-world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ readme = "../../README.md"
default-run = "hello-world"

[dependencies]

[[package.metadata.maturin.targets]]
name = "hello-world"
bindings = "bin"

[[package.metadata.maturin.targets]]
name = "foo"

0 comments on commit 5e10b05

Please sign in to comment.