@@ -19,6 +19,7 @@ use cargo_mobile2::{
19
19
util:: { prompt, relativize_path} ,
20
20
} ;
21
21
use clap:: { Parser , Subcommand } ;
22
+ use serde:: Deserialize ;
22
23
use sublime_fuzzy:: best_match;
23
24
use tauri_utils:: resources:: ResourcePaths ;
24
25
@@ -325,12 +326,23 @@ fn connected_device_prompt<'a>(env: &'_ Env, target: Option<&str>) -> Result<Dev
325
326
device,
326
327
device. target( ) . triple,
327
328
) ;
329
+
328
330
Ok ( device)
329
331
} else {
330
332
Err ( anyhow:: anyhow!( "No connected iOS devices detected" ) )
331
333
}
332
334
}
333
335
336
+ #[ derive( Default , Deserialize ) ]
337
+ struct InstalledRuntimesList {
338
+ runtimes : Vec < InstalledRuntime > ,
339
+ }
340
+
341
+ #[ derive( Deserialize ) ]
342
+ struct InstalledRuntime {
343
+ name : String ,
344
+ }
345
+
334
346
fn simulator_prompt ( env : & ' _ Env , target : Option < & str > ) -> Result < device:: Simulator > {
335
347
let simulator_list = device:: list_simulators ( env) . map_err ( |cause| {
336
348
anyhow:: anyhow!( "Failed to detect connected iOS Simulator devices: {cause}" )
@@ -367,6 +379,19 @@ fn simulator_prompt(env: &'_ Env, target: Option<&str>) -> Result<device::Simula
367
379
} ;
368
380
Ok ( device)
369
381
} else {
382
+ log:: warn!( "No available iOS Simulator detected" ) ;
383
+ let install_ios = crate :: helpers:: prompts:: confirm (
384
+ "Would you like to install the latest iOS runtime?" ,
385
+ Some ( false ) ,
386
+ )
387
+ . unwrap_or_default ( ) ;
388
+ if install_ios {
389
+ duct:: cmd ( "xcodebuild" , [ "-downloadPlatform" , "iOS" ] )
390
+ . stdout_file ( os_pipe:: dup_stdout ( ) . unwrap ( ) )
391
+ . stderr_file ( os_pipe:: dup_stderr ( ) . unwrap ( ) )
392
+ . run ( ) ?;
393
+ return simulator_prompt ( env, target) ;
394
+ }
370
395
Err ( anyhow:: anyhow!( "No available iOS Simulator detected" ) )
371
396
}
372
397
}
@@ -382,6 +407,34 @@ fn device_prompt<'a>(env: &'_ Env, target: Option<&str>) -> Result<Device<'a>> {
382
407
}
383
408
}
384
409
410
+ fn ensure_ios_runtime_installed ( ) -> Result < ( ) > {
411
+ let installed_platforms_json =
412
+ duct:: cmd ( "xcrun" , [ "simctl" , "list" , "runtimes" , "--json" ] ) . read ( ) ?;
413
+ let installed_platforms: InstalledRuntimesList =
414
+ serde_json:: from_str ( & installed_platforms_json) . unwrap_or_default ( ) ;
415
+ if !installed_platforms
416
+ . runtimes
417
+ . iter ( )
418
+ . any ( |r| r. name . starts_with ( "iOS" ) )
419
+ {
420
+ log:: warn!( "iOS platform not installed" ) ;
421
+ let install_ios = crate :: helpers:: prompts:: confirm (
422
+ "Would you like to install the latest iOS runtime?" ,
423
+ Some ( false ) ,
424
+ )
425
+ . unwrap_or_default ( ) ;
426
+ if install_ios {
427
+ duct:: cmd ( "xcodebuild" , [ "-downloadPlatform" , "iOS" ] )
428
+ . stdout_file ( os_pipe:: dup_stdout ( ) . unwrap ( ) )
429
+ . stderr_file ( os_pipe:: dup_stderr ( ) . unwrap ( ) )
430
+ . run ( ) ?;
431
+ } else {
432
+ anyhow:: bail!( "iOS platform not installed" ) ;
433
+ }
434
+ }
435
+ Ok ( ( ) )
436
+ }
437
+
385
438
fn detect_target_ok < ' a > ( env : & Env ) -> Option < & ' a Target < ' a > > {
386
439
device_prompt ( env, None ) . map ( |device| device. target ( ) ) . ok ( )
387
440
}
0 commit comments