Skip to content

Commit

Permalink
Fix cargo run uniffi-bindgen when cross compiling (#2476)
Browse files Browse the repository at this point in the history
Fixes #2461
  • Loading branch information
messense authored Feb 10, 2025
1 parent e847908 commit 1dc65bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/module_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,14 +1053,18 @@ fn uniffi_bindgen_command(crate_dir: &Path) -> Result<Command> {

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
.args(["run", "--bin", "uniffi-bindgen", "--manifest-path"])
.arg(manifest_path)
.current_dir(crate_dir)
.env_remove("CARGO_BUILD_TARGET");
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
.args(["run", "--bin", "uniffi-bindgen"])
.current_dir(cargo_metadata.workspace_root)
.env_remove("CARGO_BUILD_TARGET");
command
} else {
let mut command = Command::new("uniffi-bindgen");
Expand Down
9 changes: 9 additions & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub fn maybe_mock_cargo() {
}

/// Better error formatting
#[track_caller]
pub fn handle_result<T>(result: Result<T>) -> T {
match result {
Err(e) => {
Expand Down Expand Up @@ -199,6 +200,14 @@ pub fn create_conda_env(name: &str, major: usize, minor: usize) -> Result<(PathB
.arg("--json")
.output()
.expect("Conda not available.");
if !output.status.success() {
panic!(
"Failed to create conda environment: {}\n---stdout:\n{}---stderr:\n{}",
output.status,
str::from_utf8(&output.stdout)?,
str::from_utf8(&output.stderr)?
);
}
let result: CondaCreateResult = serde_json::from_slice(&output.stdout)?;
if !result.success {
bail!("Failed to create conda environment {}.", name);
Expand Down

0 comments on commit 1dc65bf

Please sign in to comment.