Download packages/tauri/crates/tauri-cli/src/mobile/ios/dev.rs from echodict/readest: direct link, hf CLI and curl.
- Browser
- Download file 12.5 kB
-
https://huggingface.co/datasets/echodict/readest/resolve/main/packages/tauri/crates/tauri-cli/src/mobile/ios/dev.rs
- Command line
-
hf download hf://datasets/echodict/readest/packages/tauri/crates/tauri-cli/src/mobile/ios/dev.rs
-
curl -L -o dev.rs https://huggingface.co/datasets/echodict/readest/resolve/main/packages/tauri/crates/tauri-cli/src/mobile/ios/dev.rs
12.5 kB
| // Copyright 2019-2024 Tauri Programme within The Commons Conservancy | |
| // SPDX-License-Identifier: Apache-2.0 | |
| // SPDX-License-Identifier: MIT | |
| use super::{ | |
| device_prompt, ensure_init, env, get_app, get_config, inject_resources, load_pbxproj, | |
| open_and_wait, synchronize_project_config, MobileTarget, ProjectConfig, | |
| }; | |
| use crate::{ | |
| dev::Options as DevOptions, | |
| error::{Context, ErrorExt}, | |
| helpers::{ | |
| app_paths::tauri_dir, | |
| config::{get as get_tauri_config, ConfigHandle}, | |
| flock, | |
| plist::merge_plist, | |
| }, | |
| interface::{AppInterface, Interface, MobileOptions, Options as InterfaceOptions}, | |
| mobile::{ | |
| ios::ensure_ios_runtime_installed, use_network_address_for_dev_url, write_options, CliOptions, | |
| DevChild, DevHost, DevProcess, | |
| }, | |
| ConfigValue, Result, | |
| }; | |
| use clap::{ArgAction, Parser}; | |
| use cargo_mobile2::{ | |
| apple::{ | |
| config::Config as AppleConfig, | |
| device::{Device, DeviceKind, RunError}, | |
| target::BuildError, | |
| }, | |
| env::Env, | |
| opts::{NoiseLevel, Profile}, | |
| }; | |
| use url::Host; | |
| use std::{env::set_current_dir, net::Ipv4Addr, path::PathBuf}; | |
| const PHYSICAL_IPHONE_DEV_WARNING: &str = "To develop on physical phones you need the `--host` option (not required for Simulators). See the documentation for more information: https://v2.tauri.app/develop/#development-server"; | |
| pub struct Options { | |
| /// List of cargo features to activate | |
| pub features: Vec<String>, | |
| /// Exit on panic | |
| exit_on_panic: bool, | |
| /// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file | |
| /// | |
| /// Configurations are merged in the order they are provided, which means a particular value overwrites previous values when a config key-value pair conflicts. | |
| /// | |
| /// Note that a platform-specific file is looked up and merged with the default file by default | |
| /// (tauri.macos.conf.json, tauri.linux.conf.json, tauri.windows.conf.json, tauri.android.conf.json and tauri.ios.conf.json) | |
| /// but you can use this for more specific use cases such as different build flavors. | |
| pub config: Vec<ConfigValue>, | |
| /// Run the code in release mode | |
| pub release_mode: bool, | |
| /// Skip waiting for the frontend dev server to start before building the tauri application. | |
| pub no_dev_server_wait: bool, | |
| /// Disable the file watcher | |
| pub no_watch: bool, | |
| /// Additional paths to watch for changes. | |
| pub additional_watch_folders: Vec<PathBuf>, | |
| /// Open Xcode instead of trying to run on a connected device | |
| pub open: bool, | |
| /// Runs on the given device name | |
| pub device: Option<String>, | |
| /// Force prompting for an IP to use to connect to the dev server on mobile. | |
| pub force_ip_prompt: bool, | |
| /// Use the public network address for the development server. | |
| /// If an actual address it provided, it is used instead of prompting to pick one. | |
| /// | |
| /// This option is particularly useful along the `--open` flag when you intend on running on a physical device. | |
| /// | |
| /// This replaces the devUrl configuration value to match the public network address host, | |
| /// it is your responsibility to set up your development server to listen on this address | |
| /// by using 0.0.0.0 as host for instance. | |
| /// | |
| /// When this is set or when running on an iOS device the CLI sets the `TAURI_DEV_HOST` | |
| /// environment variable so you can check this on your framework's configuration to expose the development server | |
| /// on the public network address. | |
| pub host: DevHost, | |
| /// Disable the built-in dev server for static files. | |
| pub no_dev_server: bool, | |
| /// Specify port for the built-in dev server for static files. Defaults to 1430. | |
| pub port: Option<u16>, | |
| /// Command line arguments passed to the runner. | |
| /// Use `--` to explicitly mark the start of the arguments. | |
| /// e.g. `tauri ios dev -- [runnerArgs]`. | |
| pub args: Vec<String>, | |
| /// Path to the certificate file used by your dev server. Required for mobile dev when using HTTPS. | |
| pub root_certificate_path: Option<PathBuf>, | |
| } | |
| impl From<Options> for DevOptions { | |
| fn from(options: Options) -> Self { | |
| Self { | |
| runner: None, | |
| target: None, | |
| features: options.features, | |
| exit_on_panic: options.exit_on_panic, | |
| config: options.config, | |
| release_mode: options.release_mode, | |
| args: options.args, | |
| no_watch: options.no_watch, | |
| additional_watch_folders: options.additional_watch_folders, | |
| no_dev_server: options.no_dev_server, | |
| no_dev_server_wait: options.no_dev_server_wait, | |
| port: options.port, | |
| host: options.host.0.unwrap_or_default(), | |
| } | |
| } | |
| } | |
| pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> { | |
| crate::helpers::app_paths::resolve(); | |
| let result = run_command(options, noise_level); | |
| if result.is_err() { | |
| crate::dev::kill_before_dev_process(); | |
| } | |
| result | |
| } | |
| fn run_command(options: Options, noise_level: NoiseLevel) -> Result<()> { | |
| // setup env additions before calling env() | |
| if let Some(root_certificate_path) = &options.root_certificate_path { | |
| std::env::set_var( | |
| "TAURI_DEV_ROOT_CERTIFICATE", | |
| std::fs::read_to_string(root_certificate_path).fs_context( | |
| "failed to read root certificate file", | |
| root_certificate_path.clone(), | |
| )?, | |
| ); | |
| } | |
| let env = env().context("failed to load iOS environment")?; | |
| let device = if options.open { | |
| None | |
| } else { | |
| match device_prompt(&env, options.device.as_deref()) { | |
| Ok(d) => Some(d), | |
| Err(e) => { | |
| log::error!("{e}"); | |
| None | |
| } | |
| } | |
| }; | |
| if device.is_some() { | |
| ensure_ios_runtime_installed()?; | |
| } | |
| let mut dev_options: DevOptions = options.clone().into(); | |
| let target_triple = device | |
| .as_ref() | |
| .map(|d| d.target().triple.to_string()) | |
| .unwrap_or_else(|| "aarch64-apple-ios".into()); | |
| dev_options.target = Some(target_triple.clone()); | |
| let tauri_config = get_tauri_config( | |
| tauri_utils::platform::Target::Ios, | |
| &options.config.iter().map(|c| &c.0).collect::<Vec<_>>(), | |
| )?; | |
| let (interface, config) = { | |
| let tauri_config_guard = tauri_config.lock().unwrap(); | |
| let tauri_config_ = tauri_config_guard.as_ref().unwrap(); | |
| let interface = AppInterface::new(tauri_config_, Some(target_triple))?; | |
| let app = get_app(MobileTarget::Ios, tauri_config_, &interface); | |
| let (config, _metadata) = get_config( | |
| &app, | |
| tauri_config_, | |
| &dev_options.features, | |
| &Default::default(), | |
| )?; | |
| (interface, config) | |
| }; | |
| let tauri_path = tauri_dir(); | |
| set_current_dir(tauri_path).context("failed to set current directory to Tauri directory")?; | |
| ensure_init( | |
| &tauri_config, | |
| config.app(), | |
| config.project_dir(), | |
| MobileTarget::Ios, | |
| false, | |
| )?; | |
| inject_resources(&config, tauri_config.lock().unwrap().as_ref().unwrap())?; | |
| let info_plist_path = config | |
| .project_dir() | |
| .join(config.scheme()) | |
| .join("Info.plist"); | |
| let mut src_plists = vec![info_plist_path.clone().into()]; | |
| if tauri_path.join("Info.plist").exists() { | |
| src_plists.push(tauri_path.join("Info.plist").into()); | |
| } | |
| if tauri_path.join("Info.ios.plist").exists() { | |
| src_plists.push(tauri_path.join("Info.ios.plist").into()); | |
| } | |
| if let Some(info_plist) = &tauri_config | |
| .lock() | |
| .unwrap() | |
| .as_ref() | |
| .unwrap() | |
| .bundle | |
| .ios | |
| .info_plist | |
| { | |
| src_plists.push(info_plist.clone().into()); | |
| } | |
| let merged_info_plist = merge_plist(src_plists)?; | |
| merged_info_plist | |
| .to_file_xml(&info_plist_path) | |
| .map_err(std::io::Error::other) | |
| .fs_context("failed to save merged Info.plist file", info_plist_path)?; | |
| let mut pbxproj = load_pbxproj(&config)?; | |
| // synchronize pbxproj | |
| synchronize_project_config( | |
| &config, | |
| &tauri_config, | |
| &mut pbxproj, | |
| &mut plist::Dictionary::new(), | |
| &ProjectConfig { | |
| code_sign_identity: None, | |
| team_id: None, | |
| provisioning_profile_uuid: None, | |
| }, | |
| !options.release_mode, | |
| )?; | |
| if pbxproj.has_changes() { | |
| pbxproj | |
| .save() | |
| .fs_context("failed to save pbxproj file", pbxproj.path)?; | |
| } | |
| run_dev( | |
| interface, | |
| options, | |
| dev_options, | |
| tauri_config, | |
| device, | |
| env, | |
| &config, | |
| noise_level, | |
| ) | |
| } | |
| fn run_dev( | |
| mut interface: AppInterface, | |
| options: Options, | |
| mut dev_options: DevOptions, | |
| tauri_config: ConfigHandle, | |
| device: Option<Device>, | |
| env: Env, | |
| config: &AppleConfig, | |
| noise_level: NoiseLevel, | |
| ) -> Result<()> { | |
| // when --host is provided or running on a physical device or resolving 0.0.0.0 we must use the network IP | |
| if options.host.0.is_some() | |
| || device | |
| .as_ref() | |
| .map(|device| !matches!(device.kind(), DeviceKind::Simulator)) | |
| .unwrap_or(false) | |
| || tauri_config | |
| .lock() | |
| .unwrap() | |
| .as_ref() | |
| .unwrap() | |
| .build | |
| .dev_url | |
| .as_ref() | |
| .is_some_and(|url| { | |
| matches!( | |
| url.host(), | |
| Some(Host::Ipv4(i)) if i == Ipv4Addr::UNSPECIFIED | |
| ) | |
| }) | |
| { | |
| use_network_address_for_dev_url(&tauri_config, &mut dev_options, options.force_ip_prompt)?; | |
| } | |
| crate::dev::setup(&interface, &mut dev_options, tauri_config.clone())?; | |
| let app_settings = interface.app_settings(); | |
| let out_dir = app_settings.out_dir(&InterfaceOptions { | |
| debug: !dev_options.release_mode, | |
| target: dev_options.target.clone(), | |
| ..Default::default() | |
| })?; | |
| let _lock = flock::open_rw(out_dir.join("lock").with_extension("ios"), "iOS")?; | |
| let set_host = options.host.0.is_some(); | |
| let open = options.open; | |
| interface.mobile_dev( | |
| MobileOptions { | |
| debug: true, | |
| features: options.features, | |
| args: options.args, | |
| config: dev_options.config.clone(), | |
| no_watch: options.no_watch, | |
| additional_watch_folders: options.additional_watch_folders, | |
| }, | |
| |options| { | |
| let cli_options = CliOptions { | |
| dev: true, | |
| features: options.features.clone(), | |
| args: options.args.clone(), | |
| noise_level, | |
| vars: Default::default(), | |
| config: dev_options.config.clone(), | |
| target_device: None, | |
| }; | |
| let _handle = write_options(tauri_config.lock().unwrap().as_ref().unwrap(), cli_options)?; | |
| let open_xcode = || { | |
| if !set_host { | |
| log::warn!("{PHYSICAL_IPHONE_DEV_WARNING}"); | |
| } | |
| open_and_wait(config, &env) | |
| }; | |
| if open { | |
| open_xcode() | |
| } else if let Some(device) = &device { | |
| match run(device, options, config, noise_level, &env) { | |
| Ok(c) => Ok(Box::new(c) as Box<dyn DevProcess + Send>), | |
| Err(RunError::BuildFailed(BuildError::Sdk(sdk_err))) => { | |
| log::warn!("{sdk_err}"); | |
| open_xcode() | |
| } | |
| Err(e) => { | |
| crate::dev::kill_before_dev_process(); | |
| crate::error::bail!("failed to run iOS app: {}", e) | |
| } | |
| } | |
| } else { | |
| open_xcode() | |
| } | |
| }, | |
| ) | |
| } | |
| fn run( | |
| device: &Device<'_>, | |
| options: MobileOptions, | |
| config: &AppleConfig, | |
| noise_level: NoiseLevel, | |
| env: &Env, | |
| ) -> std::result::Result<DevChild, RunError> { | |
| let profile = if options.debug { | |
| Profile::Debug | |
| } else { | |
| Profile::Release | |
| }; | |
| device | |
| .run( | |
| config, | |
| env, | |
| noise_level, | |
| false, // do not quit on app exit | |
| profile, | |
| ) | |
| .map(DevChild::new) | |
| } | |