Skip to content

Commit

Permalink
fix(cli): Cargo target dir detection on Android, closes #5865 (#5932)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Dec 28, 2022
1 parent dee9460 commit e873bae
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 19 deletions.
6 changes: 6 additions & 0 deletions .changes/target-dir-detection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"cli.rs": patch
"cli.js": patch
---

Fix target directory detection when compiling for Android.
4 changes: 2 additions & 2 deletions tooling/cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tooling/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ name = "cargo-tauri"
path = "src/main.rs"

[dependencies]
tauri-mobile = { version = "0.1.1", default-features = false }
tauri-mobile = { version = "0.1.3", default-features = false }
textwrap = { version = "0.11.0", features = [ "term_size" ] }
jsonrpsee = { version = "0.16", features = [ "client", "server" ] }
thiserror = "1"
Expand Down
1 change: 1 addition & 0 deletions tooling/cli/src/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub trait AppSettings {
config: &Config,
target: &str,
) -> crate::Result<Vec<tauri_bundler::BundleBinary>>;
fn app_name(&self) -> Option<String>;

fn get_bundler_settings(
&self,
Expand Down
12 changes: 12 additions & 0 deletions tooling/cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,18 @@ impl AppSettings for RustAppSettings {

Ok(binaries)
}

fn app_name(&self) -> Option<String> {
self
.manifest
.inner
.as_table()
.get("package")
.and_then(|p| p.as_table())
.and_then(|p| p.get("name"))
.and_then(|n| n.as_str())
.map(|n| n.to_string())
}
}

impl RustAppSettings {
Expand Down
39 changes: 23 additions & 16 deletions tooling/cli/src/mobile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use crate::{
helpers::{app_paths::tauri_dir, config::Config as TauriConfig},
interface::DevProcess,
interface::{AppInterface, AppSettings, DevProcess, Interface, Options as InterfaceOptions},
};
use anyhow::{bail, Result};
use jsonrpsee::client_transport::ws::WsTransportClientBuilder;
Expand All @@ -31,7 +31,7 @@ use tauri_mobile::{
bossy,
config::app::{App, Raw as RawAppConfig},
env::Error as EnvError,
opts::NoiseLevel,
opts::{NoiseLevel, Profile},
};
use tokio::runtime::Runtime;

Expand Down Expand Up @@ -220,19 +220,14 @@ fn get_app(config: &TauriConfig) -> App {
}
reverse_domain.pop();

let manifest_path = tauri_dir().join("Cargo.toml");
let app_name = if let Ok(manifest) = crate::interface::manifest::read_manifest(&manifest_path) {
manifest
.as_table()
.get("package")
.and_then(|p| p.as_table())
.and_then(|p| p.get("name"))
.and_then(|n| n.as_str())
.map(|n| n.to_string())
.unwrap_or(app_name)
} else {
app_name
};
let interface = AppInterface::new(
config,
// the target triple is not relevant
Some("".into()),
)
.expect("failed to load interface");

let app_name = interface.app_settings().app_name().unwrap_or(app_name);

let raw = RawAppConfig {
name: app_name,
Expand All @@ -241,7 +236,19 @@ fn get_app(config: &TauriConfig) -> App {
asset_dir: None,
template_pack: None,
};
App::from_raw(tauri_dir(), raw).unwrap()
App::from_raw(tauri_dir(), raw)
.unwrap()
.with_target_dir_resolver(move |target, profile| {
let bin_path = interface
.app_settings()
.app_binary_path(&InterfaceOptions {
debug: matches!(profile, Profile::Debug),
target: Some(target.into()),
..Default::default()
})
.expect("failed to resolve target directory");
bin_path.parent().unwrap().to_path_buf()
})
}

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

0 comments on commit e873bae

Please sign in to comment.