Skip to content

Commit

Permalink
Use external uniffi-bindgen if no root package is configured
Browse files Browse the repository at this point in the history
A "root package" in Cargo exists in a workspace if the workspace
Cargo.toml also has a `[package]` section.
In that case maturin tries to find a binary target called
`uniffi-bindgen` to use.

But if there's no root package to begin with it should fall back to an
external `uniffi-bindgen` instead of panicking.
  • Loading branch information
badboy committed Oct 4, 2023
1 parent 2e7e8ef commit 2e2d99c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/module_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,11 +872,14 @@ fn uniffi_bindgen_command(crate_dir: &Path) -> Result<Command> {
.no_deps()
.verbose(true)
.exec()?;
let root_pkg = cargo_metadata.root_package().unwrap();
let root_pkg = cargo_metadata.root_package();
let has_uniffi_bindgen_target = root_pkg
.targets
.iter()
.any(|target| target.name == "uniffi-bindgen" && target.is_bin());
.map(|pkg| {
pkg.targets
.iter()
.any(|target| target.name == "uniffi-bindgen" && target.is_bin())
})
.unwrap_or(false);
let command = if has_uniffi_bindgen_target {
let mut command = Command::new("cargo");
command.args(["run", "--bin", "uniffi-bindgen", "--manifest-path"]);
Expand Down

0 comments on commit 2e2d99c

Please sign in to comment.