Skip to content

Commit 1dc65bf

Browse files
authored
Fix cargo run uniffi-bindgen when cross compiling (#2476)
Fixes #2461
1 parent e847908 commit 1dc65bf

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/module_writer.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,14 +1053,18 @@ fn uniffi_bindgen_command(crate_dir: &Path) -> Result<Command> {
10531053

10541054
let command = if has_uniffi_bindgen_target {
10551055
let mut command = Command::new("cargo");
1056-
command.args(["run", "--bin", "uniffi-bindgen", "--manifest-path"]);
1057-
command.arg(manifest_path);
1058-
command.current_dir(crate_dir);
1056+
command
1057+
.args(["run", "--bin", "uniffi-bindgen", "--manifest-path"])
1058+
.arg(manifest_path)
1059+
.current_dir(crate_dir)
1060+
.env_remove("CARGO_BUILD_TARGET");
10591061
command
10601062
} else if has_uniffi_bindgen_workspace_package {
10611063
let mut command = Command::new("cargo");
1062-
command.args(["run", "--bin", "uniffi-bindgen"]);
1063-
command.current_dir(cargo_metadata.workspace_root);
1064+
command
1065+
.args(["run", "--bin", "uniffi-bindgen"])
1066+
.current_dir(cargo_metadata.workspace_root)
1067+
.env_remove("CARGO_BUILD_TARGET");
10641068
command
10651069
} else {
10661070
let mut command = Command::new("uniffi-bindgen");

tests/common/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub fn maybe_mock_cargo() {
8585
}
8686

8787
/// Better error formatting
88+
#[track_caller]
8889
pub fn handle_result<T>(result: Result<T>) -> T {
8990
match result {
9091
Err(e) => {
@@ -199,6 +200,14 @@ pub fn create_conda_env(name: &str, major: usize, minor: usize) -> Result<(PathB
199200
.arg("--json")
200201
.output()
201202
.expect("Conda not available.");
203+
if !output.status.success() {
204+
panic!(
205+
"Failed to create conda environment: {}\n---stdout:\n{}---stderr:\n{}",
206+
output.status,
207+
str::from_utf8(&output.stdout)?,
208+
str::from_utf8(&output.stderr)?
209+
);
210+
}
202211
let result: CondaCreateResult = serde_json::from_slice(&output.stdout)?;
203212
if !result.success {
204213
bail!("Failed to create conda environment {}.", name);

0 commit comments

Comments
 (0)