From 189852cb0d37ead479e7acd9853c506969e351fd Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Wed, 4 Oct 2023 12:17:07 +0200 Subject: [PATCH] Use external `uniffi-bindgen` if no root package is configured (#1797) 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. --- src/module_writer.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/module_writer.rs b/src/module_writer.rs index ffb8cd6cc..8d9c5cf0f 100644 --- a/src/module_writer.rs +++ b/src/module_writer.rs @@ -872,11 +872,14 @@ fn uniffi_bindgen_command(crate_dir: &Path) -> Result { .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"]);