Skip to content

Commit e873bae

Browse files
authored
fix(cli): Cargo target dir detection on Android, closes #5865 (#5932)
1 parent dee9460 commit e873bae

File tree

6 files changed

+45
-19
lines changed

6 files changed

+45
-19
lines changed

.changes/target-dir-detection.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"cli.rs": patch
3+
"cli.js": patch
4+
---
5+
6+
Fix target directory detection when compiling for Android.

tooling/cli/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ name = "cargo-tauri"
3939
path = "src/main.rs"
4040

4141
[dependencies]
42-
tauri-mobile = { version = "0.1.1", default-features = false }
42+
tauri-mobile = { version = "0.1.3", default-features = false }
4343
textwrap = { version = "0.11.0", features = [ "term_size" ] }
4444
jsonrpsee = { version = "0.16", features = [ "client", "server" ] }
4545
thiserror = "1"

tooling/cli/src/interface/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub trait AppSettings {
3636
config: &Config,
3737
target: &str,
3838
) -> crate::Result<Vec<tauri_bundler::BundleBinary>>;
39+
fn app_name(&self) -> Option<String>;
3940

4041
fn get_bundler_settings(
4142
&self,

tooling/cli/src/interface/rust.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,18 @@ impl AppSettings for RustAppSettings {
760760

761761
Ok(binaries)
762762
}
763+
764+
fn app_name(&self) -> Option<String> {
765+
self
766+
.manifest
767+
.inner
768+
.as_table()
769+
.get("package")
770+
.and_then(|p| p.as_table())
771+
.and_then(|p| p.get("name"))
772+
.and_then(|n| n.as_str())
773+
.map(|n| n.to_string())
774+
}
763775
}
764776

765777
impl RustAppSettings {

tooling/cli/src/mobile/mod.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use crate::{
66
helpers::{app_paths::tauri_dir, config::Config as TauriConfig},
7-
interface::DevProcess,
7+
interface::{AppInterface, AppSettings, DevProcess, Interface, Options as InterfaceOptions},
88
};
99
use anyhow::{bail, Result};
1010
use jsonrpsee::client_transport::ws::WsTransportClientBuilder;
@@ -31,7 +31,7 @@ use tauri_mobile::{
3131
bossy,
3232
config::app::{App, Raw as RawAppConfig},
3333
env::Error as EnvError,
34-
opts::NoiseLevel,
34+
opts::{NoiseLevel, Profile},
3535
};
3636
use tokio::runtime::Runtime;
3737

@@ -220,19 +220,14 @@ fn get_app(config: &TauriConfig) -> App {
220220
}
221221
reverse_domain.pop();
222222

223-
let manifest_path = tauri_dir().join("Cargo.toml");
224-
let app_name = if let Ok(manifest) = crate::interface::manifest::read_manifest(&manifest_path) {
225-
manifest
226-
.as_table()
227-
.get("package")
228-
.and_then(|p| p.as_table())
229-
.and_then(|p| p.get("name"))
230-
.and_then(|n| n.as_str())
231-
.map(|n| n.to_string())
232-
.unwrap_or(app_name)
233-
} else {
234-
app_name
235-
};
223+
let interface = AppInterface::new(
224+
config,
225+
// the target triple is not relevant
226+
Some("".into()),
227+
)
228+
.expect("failed to load interface");
229+
230+
let app_name = interface.app_settings().app_name().unwrap_or(app_name);
236231

237232
let raw = RawAppConfig {
238233
name: app_name,
@@ -241,7 +236,19 @@ fn get_app(config: &TauriConfig) -> App {
241236
asset_dir: None,
242237
template_pack: None,
243238
};
244-
App::from_raw(tauri_dir(), raw).unwrap()
239+
App::from_raw(tauri_dir(), raw)
240+
.unwrap()
241+
.with_target_dir_resolver(move |target, profile| {
242+
let bin_path = interface
243+
.app_settings()
244+
.app_binary_path(&InterfaceOptions {
245+
debug: matches!(profile, Profile::Debug),
246+
target: Some(target.into()),
247+
..Default::default()
248+
})
249+
.expect("failed to resolve target directory");
250+
bin_path.parent().unwrap().to_path_buf()
251+
})
245252
}
246253

247254
fn ensure_init(project_dir: PathBuf, target: Target) -> Result<()> {

0 commit comments

Comments
 (0)