From 1039832b66ec00e1b68de720e6f3c5133e0a9b68 Mon Sep 17 00:00:00 2001 From: Hinton Date: Tue, 9 Jan 2024 10:37:19 +0100 Subject: [PATCH] Support uniffi-bindgen in cargo workspaces --- src/module_writer.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/module_writer.rs b/src/module_writer.rs index 19bab78bb..0c13e0105 100644 --- a/src/module_writer.rs +++ b/src/module_writer.rs @@ -880,13 +880,27 @@ fn uniffi_bindgen_command(crate_dir: &Path) -> Result { .any(|target| target.name == "uniffi-bindgen" && target.is_bin()) }) .unwrap_or(false); + let has_uniffi_bindgen_workspace_package = cargo_metadata.packages.iter().any(|pkg| { + pkg.targets + .iter() + .any(|target| target.name == "uniffi-bindgen" && target.is_bin()) + }); + let command = if has_uniffi_bindgen_target { let mut command = Command::new("cargo"); command.args(["run", "--bin", "uniffi-bindgen", "--manifest-path"]); command.arg(manifest_path); + command.current_dir(crate_dir); + command + } else if has_uniffi_bindgen_workspace_package { + let mut command = Command::new("cargo"); + command.args(["run", "--bin", "uniffi-bindgen"]); + command.current_dir(cargo_metadata.workspace_root); command } else { - Command::new("uniffi-bindgen") + let mut command = Command::new("uniffi-bindgen"); + command.current_dir(crate_dir); + command }; Ok(command) } @@ -922,7 +936,6 @@ fn generate_uniffi_bindings( }; let mut cmd = uniffi_bindgen_command(crate_dir)?; - cmd.current_dir(crate_dir); cmd.args([ "generate", "--no-format",