refactor(cli): use jsonrpsee for mobile CLI options communication (#5657)

This commit is contained in:
Lucas Fernandes Nogueira 2022-11-20 09:48:02 -03:00 committed by GitHub
parent 538e21e2e7
commit 03d6c6a68f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 419 additions and 195 deletions

450
tooling/cli/Cargo.lock generated
View File

@ -98,21 +98,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]]
name = "async-channel"
version = "1.7.1"
name = "arrayvec"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e14485364214912d3b19cc3435dde4df66065127f05fa0d75c712f36f12c2f28"
dependencies = [
"concurrent-queue",
"event-listener",
"futures-core",
]
checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"
[[package]]
name = "async-task"
version = "4.3.0"
name = "async-lock"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524"
checksum = "c8101efe8695a6c17e02911402145357e718ac92d3ff88ae8419e84b1707b685"
dependencies = [
"event-listener",
"futures-lite",
]
[[package]]
name = "async-trait"
@ -125,12 +124,6 @@ dependencies = [
"syn",
]
[[package]]
name = "atomic-waker"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a"
[[package]]
name = "attohttpc"
version = "0.23.1"
@ -223,6 +216,15 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a32fd6af2b5827bce66c29053ba0e7c42b9dcab01835835058558c10851a46b"
[[package]]
name = "beef"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1"
dependencies = [
"serde",
]
[[package]]
name = "bit-set"
version = "0.5.3"
@ -280,6 +282,15 @@ dependencies = [
"generic-array 0.12.4",
]
[[package]]
name = "block-buffer"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
dependencies = [
"generic-array 0.14.5",
]
[[package]]
name = "block-buffer"
version = "0.10.2"
@ -298,20 +309,6 @@ dependencies = [
"byte-tools",
]
[[package]]
name = "blocking"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6ccb65d468978a086b69884437ded69a90faab3bbe6e67f242173ea728acccc"
dependencies = [
"async-channel",
"async-task",
"atomic-waker",
"fastrand",
"futures-lite",
"once_cell",
]
[[package]]
name = "bstr"
version = "0.2.17"
@ -378,16 +375,10 @@ dependencies = [
"pkg-config",
]
[[package]]
name = "cache-padded"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c"
[[package]]
name = "cargo-mobile"
version = "0.1.0"
source = "git+https://github.com/tauri-apps/cargo-mobile?branch=dev#76e6e8e7ba289ff5e2c74f72d003f19572c9dba9"
source = "git+https://github.com/tauri-apps/cargo-mobile?branch=dev#068cda074b0ff0c42f8d5297d8a2d5c29fd75c03"
dependencies = [
"cocoa",
"colored 1.9.3",
@ -575,15 +566,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2382f75942f4b3be3690fe4f86365e9c853c1587d6ee58212cebf6e2a9ccd101"
[[package]]
name = "concurrent-queue"
version = "1.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af4780a44ab5696ea9e28294517f1fffb421a83a25af521333c838635509db9c"
dependencies = [
"cache-padded",
]
[[package]]
name = "console"
version = "0.15.0"
@ -873,6 +855,15 @@ dependencies = [
"generic-array 0.12.4",
]
[[package]]
name = "digest"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
dependencies = [
"generic-array 0.14.5",
]
[[package]]
name = "digest"
version = "0.10.3"
@ -1221,7 +1212,6 @@ checksum = "7f21eda599937fba36daeb58a22e8f5cee2d14c4a17b5b7739c7c8e5e3b8230c"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
@ -1244,17 +1234,6 @@ version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf"
[[package]]
name = "futures-executor"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ff63c23854bee61b6e9cd331d523909f238fc7636290b96826e9cfa5faa00ab"
dependencies = [
"futures-core",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-io"
version = "0.3.24"
@ -1299,6 +1278,16 @@ version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1"
[[package]]
name = "futures-timer"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c"
dependencies = [
"gloo-timers",
"send_wrapper",
]
[[package]]
name = "futures-util"
version = "0.3.24"
@ -1408,6 +1397,51 @@ dependencies = [
"regex",
]
[[package]]
name = "gloo-net"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec897194fb9ac576c708f63d35604bc58f2a262b8cec0fabfed26f3991255f21"
dependencies = [
"futures-channel",
"futures-core",
"futures-sink",
"gloo-utils",
"js-sys",
"pin-project",
"serde",
"serde_json",
"thiserror",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
]
[[package]]
name = "gloo-timers"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fb7d06c1c8cc2a29bee7ec961009a0b2caa0793ee4900c2ffb348734ba1c8f9"
dependencies = [
"futures-channel",
"futures-core",
"js-sys",
"wasm-bindgen",
]
[[package]]
name = "gloo-utils"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40913a05c8297adca04392f707b1e73b12ba7b8eab7244a4961580b1fd34063c"
dependencies = [
"js-sys",
"serde",
"serde_json",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "h2"
version = "0.3.14"
@ -1608,6 +1642,22 @@ dependencies = [
"want",
]
[[package]]
name = "hyper-rustls"
version = "0.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59df7c4e19c950e6e0e868dcc0a300b09a9b88e9ec55bd879ca819087a77355d"
dependencies = [
"http",
"hyper",
"log",
"rustls",
"rustls-native-certs",
"tokio",
"tokio-rustls",
"webpki-roots",
]
[[package]]
name = "ident_case"
version = "1.0.1"
@ -1729,29 +1779,6 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "interprocess"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c58ec7fbda1df9a93f587b780659db3c99f61f4be27f9c82c9b37684ffd0366"
dependencies = [
"blocking",
"cfg-if",
"futures",
"intmap",
"libc",
"once_cell",
"spinning",
"thiserror",
"winapi",
]
[[package]]
name = "intmap"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae52f28f45ac2bc96edb7714de995cffc174a395fb0abf5bff453587c980d7b9"
[[package]]
name = "ipnet"
version = "2.5.0"
@ -1848,6 +1875,153 @@ dependencies = [
"serde",
]
[[package]]
name = "jsonrpsee"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5af9646e616e37c61093ef85e25bd883ae0c22e2fa1e6eedfe590048247116e3"
dependencies = [
"jsonrpsee-client-transport",
"jsonrpsee-core",
"jsonrpsee-http-client",
"jsonrpsee-server",
"jsonrpsee-types",
"jsonrpsee-wasm-client",
"jsonrpsee-ws-client",
]
[[package]]
name = "jsonrpsee-client-transport"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e85cfc9c2f17eab237fdfa2efe5c1608fd06a90e1e0d7fd7b10f2d0e153f375"
dependencies = [
"anyhow",
"futures-channel",
"futures-timer",
"futures-util",
"gloo-net",
"http",
"jsonrpsee-core",
"jsonrpsee-types",
"pin-project",
"rustls-native-certs",
"soketto",
"thiserror",
"tokio",
"tokio-rustls",
"tokio-util",
"tracing",
"webpki-roots",
]
[[package]]
name = "jsonrpsee-core"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "673d68136e2f0f67323bab95b3a7177df26ac21ddbf395fc32d60f30fe5a1364"
dependencies = [
"anyhow",
"arrayvec 0.7.2",
"async-lock",
"async-trait",
"beef",
"futures-channel",
"futures-timer",
"futures-util",
"globset",
"hyper",
"jsonrpsee-types",
"parking_lot",
"rand 0.8.5",
"rustc-hash",
"serde",
"serde_json",
"soketto",
"thiserror",
"tokio",
"tracing",
"wasm-bindgen-futures",
]
[[package]]
name = "jsonrpsee-http-client"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42007820863ab29f3adeacf43886ef54abaedb35bc33dada25771db4e1f94de4"
dependencies = [
"async-trait",
"hyper",
"hyper-rustls",
"jsonrpsee-core",
"jsonrpsee-types",
"rustc-hash",
"serde",
"serde_json",
"thiserror",
"tokio",
"tracing",
]
[[package]]
name = "jsonrpsee-server"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a78f34520019321bd466d00620606db2f40827362d0185b3b95040328eb502f6"
dependencies = [
"futures-channel",
"futures-util",
"http",
"hyper",
"jsonrpsee-core",
"jsonrpsee-types",
"serde",
"serde_json",
"soketto",
"tokio",
"tokio-stream",
"tokio-util",
"tower",
"tracing",
]
[[package]]
name = "jsonrpsee-types"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7985a27ee315c7c8c5c5033ac133e9472aec881edfd947780f5a9970efb7cbbf"
dependencies = [
"anyhow",
"beef",
"serde",
"serde_json",
"thiserror",
"tracing",
]
[[package]]
name = "jsonrpsee-wasm-client"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46811fcec615d8e58228e7e281b3238693b26da1eb2469ac208af40a217bc8d9"
dependencies = [
"jsonrpsee-client-transport",
"jsonrpsee-core",
"jsonrpsee-types",
]
[[package]]
name = "jsonrpsee-ws-client"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "480fc9922f10b8fca3f07c07c51e137ddcf13fd60a304f117cfaa9e9bf41c60b"
dependencies = [
"http",
"jsonrpsee-client-transport",
"jsonrpsee-core",
"jsonrpsee-types",
]
[[package]]
name = "jsonschema"
version = "0.16.0"
@ -1927,7 +2101,7 @@ version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe"
dependencies = [
"arrayvec",
"arrayvec 0.5.2",
"bitflags",
"cfg-if",
"ryu",
@ -3060,6 +3234,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustc_version"
version = "0.4.0"
@ -3081,6 +3261,27 @@ dependencies = [
"webpki",
]
[[package]]
name = "rustls-native-certs"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0167bac7a9f490495f3c33013e7722b53cb087ecbe082fb0c6387c96f634ea50"
dependencies = [
"openssl-probe",
"rustls-pemfile",
"schannel",
"security-framework",
]
[[package]]
name = "rustls-pemfile"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55"
dependencies = [
"base64",
]
[[package]]
name = "ryu"
version = "1.0.10"
@ -3229,6 +3430,12 @@ version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a41d061efea015927ac527063765e73601444cdc344ba855bc7bd44578b25e1c"
[[package]]
name = "send_wrapper"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f638d531eccd6e23b980caf34876660d38e265409d8e99b397ab71eb3612fad0"
[[package]]
name = "serde"
version = "1.0.137"
@ -3349,6 +3556,19 @@ dependencies = [
"opaque-debug 0.2.3",
]
[[package]]
name = "sha-1"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6"
dependencies = [
"block-buffer 0.9.0",
"cfg-if",
"cpufeatures",
"digest 0.9.0",
"opaque-debug 0.3.0",
]
[[package]]
name = "sha-1"
version = "0.10.0"
@ -3429,6 +3649,22 @@ dependencies = [
"winapi",
]
[[package]]
name = "soketto"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d1c5305e39e09653383c2c7244f2f78b3bcae37cf50c64cb4789c9f5096ec2"
dependencies = [
"base64",
"bytes",
"futures",
"http",
"httparse",
"log",
"rand 0.8.5",
"sha-1 0.9.8",
]
[[package]]
name = "spin"
version = "0.5.2"
@ -3444,15 +3680,6 @@ dependencies = [
"lock_api",
]
[[package]]
name = "spinning"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d4f0e86297cad2658d92a707320d87bf4e6ae1050287f51d19b67ef3f153a7b"
dependencies = [
"lock_api",
]
[[package]]
name = "stable_deref_trait"
version = "1.2.0"
@ -3659,8 +3886,8 @@ dependencies = [
"ignore",
"image",
"include_dir",
"interprocess",
"json-patch",
"jsonrpsee",
"jsonschema",
"kuchiki",
"libc",
@ -3923,6 +4150,28 @@ dependencies = [
"syn",
]
[[package]]
name = "tokio-rustls"
version = "0.23.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59"
dependencies = [
"rustls",
"tokio",
"webpki",
]
[[package]]
name = "tokio-stream"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d660770404473ccd7bc9f8b28494a811bc18542b915c0855c51e8f419d5223ce"
dependencies = [
"futures-core",
"pin-project-lite",
"tokio",
]
[[package]]
name = "tokio-tungstenite"
version = "0.17.2"
@ -3943,6 +4192,7 @@ checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740"
dependencies = [
"bytes",
"futures-core",
"futures-io",
"futures-sink",
"pin-project-lite",
"tokio",
@ -4026,9 +4276,21 @@ dependencies = [
"cfg-if",
"log",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.29"
@ -4288,6 +4550,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994"
dependencies = [
"cfg-if",
"serde",
"serde_json",
"wasm-bindgen-macro",
]

View File

@ -42,7 +42,7 @@ path = "src/main.rs"
# cargo-mobile = { path = "../../../cargo-mobile/", default-features = false }
cargo-mobile = { git = "https://github.com/tauri-apps/cargo-mobile", branch = "dev", default-features = false }
textwrap = { version = "0.11.0", features = ["term_size"] }
interprocess = "1"
jsonrpsee = { version = "0.16", features = [ "client", "server" ]}
thiserror = "1"
sublime_fuzzy = "0.7"
clap = { version = "4.0", features = [ "derive" ] }

View File

@ -132,8 +132,7 @@ fn with_config<T>(
let tauri_config = get_tauri_config(None)?;
let tauri_config_guard = tauri_config.lock().unwrap();
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
let cli_options =
cli_options.unwrap_or_else(|| read_options(tauri_config_, MobileTarget::Android));
let cli_options = cli_options.unwrap_or_else(read_options);
let (app, config, metadata) = get_config(None, tauri_config_, &cli_options);
(app, config, metadata, cli_options)
};

View File

@ -3,7 +3,7 @@ use super::{
MobileTarget,
};
use crate::{
helpers::{config::get as get_tauri_config, flock},
helpers::flock,
interface::{AppSettings, Interface, Options as InterfaceOptions},
mobile::{write_options, CliOptions},
Result,
@ -77,11 +77,11 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {
ensure_init(config.project_dir(), MobileTarget::Android)?;
let env = env()?;
let mut env = env()?;
init_dot_cargo(app, Some((&env, config)))?;
let open = options.open;
run_build(options, config, &env, noise_level)?;
run_build(options, config, &mut env, noise_level)?;
if open {
open_and_wait(config, &env);
@ -96,7 +96,7 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {
fn run_build(
mut options: Options,
config: &AndroidConfig,
env: &Env,
env: &mut Env,
noise_level: NoiseLevel,
) -> Result<()> {
let profile = if options.debug {
@ -111,13 +111,6 @@ fn run_build(
options.aab = true;
}
let bundle_identifier = {
let tauri_config = get_tauri_config(None)?;
let tauri_config_guard = tauri_config.lock().unwrap();
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
tauri_config_.tauri.bundle.identifier.clone()
};
let mut build_options = options.clone().into();
let interface = crate::build::setup(&mut build_options, true)?;
@ -135,7 +128,7 @@ fn run_build(
noise_level,
vars: Default::default(),
};
write_options(cli_options, &bundle_identifier, MobileTarget::Android)?;
let _handle = write_options(cli_options, &mut env.base)?;
options
.features

View File

@ -3,7 +3,7 @@ use super::{
MobileTarget,
};
use crate::{
helpers::{config::get as get_tauri_config, flock},
helpers::flock,
interface::{AppSettings, Interface, MobileOptions, Options as InterfaceOptions},
mobile::{write_options, CliOptions, DevChild, DevProcess},
Result,
@ -94,13 +94,6 @@ fn run_dev(
let mut dev_options = options.clone().into();
let mut interface = crate::dev::setup(&mut dev_options)?;
let bundle_identifier = {
let tauri_config = get_tauri_config(None)?;
let tauri_config_guard = tauri_config.lock().unwrap();
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
tauri_config_.tauri.bundle.identifier.clone()
};
let app_settings = interface.app_settings();
let bin_path = app_settings.app_binary_path(&InterfaceOptions {
debug: !dev_options.release_mode,
@ -125,13 +118,14 @@ fn run_dev(
no_watch: options.no_watch,
},
|options| {
let mut env = env.clone();
let cli_options = CliOptions {
features: options.features.clone(),
args: options.args.clone(),
noise_level,
vars: Default::default(),
};
write_options(cli_options, &bundle_identifier, MobileTarget::Android)?;
let _handle = write_options(cli_options, &mut env.base)?;
if open {
open_and_wait(config, &env)

View File

@ -147,7 +147,7 @@ fn with_config<T>(
let tauri_config = get_tauri_config(None)?;
let tauri_config_guard = tauri_config.lock().unwrap();
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
let cli_options = cli_options.unwrap_or_else(|| read_options(tauri_config_, MobileTarget::Ios));
let cli_options = cli_options.unwrap_or_else(read_options);
let (app, config, metadata) = get_config(None, tauri_config_, &cli_options);
(app, config, metadata, cli_options)
};

View File

@ -3,7 +3,7 @@ use super::{
MobileTarget,
};
use crate::{
helpers::{config::get as get_tauri_config, flock},
helpers::flock,
interface::{AppSettings, Interface, Options as InterfaceOptions},
mobile::{write_options, CliOptions},
Result,
@ -69,11 +69,11 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {
|app, config, _metadata, _cli_options| {
ensure_init(config.project_dir(), MobileTarget::Ios)?;
let env = env()?;
let mut env = env()?;
init_dot_cargo(app, None)?;
let open = options.open;
run_build(options, config, &env, noise_level)?;
run_build(options, config, &mut env, noise_level)?;
if open {
open_and_wait(config, &env);
@ -88,7 +88,7 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {
fn run_build(
mut options: Options,
config: &AppleConfig,
env: &Env,
env: &mut Env,
noise_level: NoiseLevel,
) -> Result<()> {
let profile = if options.debug {
@ -97,13 +97,6 @@ fn run_build(
Profile::Release
};
let bundle_identifier = {
let tauri_config = get_tauri_config(None)?;
let tauri_config_guard = tauri_config.lock().unwrap();
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
tauri_config_.tauri.bundle.identifier.clone()
};
let mut build_options = options.clone().into();
let interface = crate::build::setup(&mut build_options, true)?;
@ -121,7 +114,7 @@ fn run_build(
noise_level,
vars: Default::default(),
};
write_options(cli_options, &bundle_identifier, MobileTarget::Ios)?;
let _handle = write_options(cli_options, env)?;
options
.features

View File

@ -3,7 +3,7 @@ use super::{
APPLE_DEVELOPMENT_TEAM_ENV_VAR_NAME,
};
use crate::{
helpers::{config::get as get_tauri_config, flock},
helpers::flock,
interface::{AppSettings, Interface, MobileOptions, Options as InterfaceOptions},
mobile::{write_options, CliOptions, DevChild, DevProcess},
Result,
@ -109,13 +109,6 @@ fn run_dev(
let mut dev_options = options.clone().into();
let mut interface = crate::dev::setup(&mut dev_options)?;
let bundle_identifier = {
let tauri_config = get_tauri_config(None)?;
let tauri_config_guard = tauri_config.lock().unwrap();
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
tauri_config_.tauri.bundle.identifier.clone()
};
let app_settings = interface.app_settings();
let bin_path = app_settings.app_binary_path(&InterfaceOptions {
debug: !dev_options.release_mode,
@ -140,13 +133,14 @@ fn run_dev(
no_watch: options.no_watch,
},
|options| {
let mut env = env.clone();
let cli_options = CliOptions {
features: options.features.clone(),
args: options.args.clone(),
noise_level,
vars: Default::default(),
};
write_options(cli_options, &bundle_identifier, MobileTarget::Ios)?;
let _handle = write_options(cli_options, &mut env)?;
if open {
open_and_wait(config, &env)

View File

@ -13,15 +13,19 @@ use cargo_mobile::{
env::Error as EnvError,
opts::NoiseLevel,
};
use interprocess::local_socket::{LocalSocketListener, LocalSocketStream};
use jsonrpsee::client_transport::ws::WsTransportClientBuilder;
use jsonrpsee::core::client::{Client, ClientBuilder, ClientT};
use jsonrpsee::rpc_params;
use jsonrpsee::server::{RpcModule, ServerBuilder, ServerHandle};
use serde::{Deserialize, Serialize};
use shared_child::SharedChild;
use std::{
collections::HashMap,
env::set_var,
env::var,
ffi::OsString,
fmt::Write,
io::{BufRead, BufReader, Write as _},
net::SocketAddr,
path::PathBuf,
process::ExitStatus,
sync::{
@ -29,6 +33,7 @@ use std::{
Arc,
},
};
use tokio::runtime::Runtime;
#[cfg(not(windows))]
use cargo_mobile::env::Env;
@ -122,15 +127,6 @@ pub struct CliOptions {
pub vars: HashMap<String, OsString>,
}
fn options_local_socket_name(bundle_identifier: &str, target: Target) -> PathBuf {
let out_dir = std::env::temp_dir();
let out_dir = out_dir.join(".tauri").join(bundle_identifier);
let _ = std::fs::create_dir_all(&out_dir);
out_dir
.join("cli-options")
.with_extension(target.command_name())
}
fn env_vars() -> HashMap<String, OsString> {
let mut vars = HashMap::new();
for (k, v) in std::env::vars_os() {
@ -154,58 +150,49 @@ fn env() -> Result<Env, EnvError> {
/// Writes CLI options to be used later on the Xcode and Android Studio build commands
pub fn write_options(
mut options: CliOptions,
bundle_identifier: &str,
target: Target,
) -> crate::Result<()> {
env: &mut Env,
) -> crate::Result<(Runtime, ServerHandle)> {
options.vars.extend(env_vars());
let name = options_local_socket_name(bundle_identifier, target);
let _ = std::fs::remove_file(&name);
let mut value = serde_json::to_string(&options)?;
value.push('\n');
std::thread::spawn(move || {
let listener = LocalSocketListener::bind(name).expect("failed to start local socket");
for mut conn in listener.incoming().flatten() {
let _ = conn.write_all(value.as_bytes());
}
let runtime = Runtime::new().unwrap();
let r: anyhow::Result<(ServerHandle, SocketAddr)> = runtime.block_on(async move {
let server = ServerBuilder::default().build("127.0.0.1:0").await?;
let addr = server.local_addr()?;
let mut module = RpcModule::new(());
module.register_method("options", move |_, _| Ok(options.clone()))?;
let handle = server.start(module)?;
Ok((handle, addr))
});
let (handle, addr) = r?;
Ok(())
env.insert_env_var("TAURI_OPTIONS_SERVER_ADDR".into(), addr.to_string().into());
Ok((runtime, handle))
}
fn read_options(config: &TauriConfig, target: Target) -> CliOptions {
let name = options_local_socket_name(&config.tauri.bundle.identifier, target);
let conn = LocalSocketStream::connect(name).unwrap_or_else(|_| {
log::error!(
"failed to connect to local socket. You must keep the Tauri CLI alive with the `{cmd} dev` or `{cmd} build --open` commands.",
cmd = target.command_name()
);
std::process::exit(1);
});
conn
.set_nonblocking(true)
.expect("failed to set local socket stream to nonblocking");
let mut conn = BufReader::new(conn);
fn read_options() -> CliOptions {
let runtime = tokio::runtime::Runtime::new().unwrap();
let options = runtime
.block_on(async move {
let (tx, rx) = WsTransportClientBuilder::default()
.build(
format!(
"ws://{}",
var("TAURI_OPTIONS_SERVER_ADDR").expect("missing addr environment variable")
)
.parse()
.unwrap(),
)
.await?;
let client: Client = ClientBuilder::default().build_with_tokio(tx, rx);
let options: CliOptions = client.request("options", rpc_params![]).await?;
Ok::<CliOptions, anyhow::Error>(options)
})
.expect("failed to read CLI options");
let mut attempt = 0;
let max_tries = 5;
let buffer = loop {
let mut buffer = String::new();
if conn.read_line(&mut buffer).is_ok() {
break buffer;
}
std::thread::sleep(std::time::Duration::from_secs(1));
attempt += 1;
if attempt == max_tries {
log::error!(
"failed to connect to local socket. You must keep the Tauri CLI alive with the `{cmd} dev` or `{cmd} build --open` commands.",
cmd = target.command_name()
);
std::process::exit(1);
}
};
let options: CliOptions = serde_json::from_str(&buffer).expect("invalid CLI options");
for (k, v) in &options.vars {
set_var(k, v);
}