@@ -49,25 +49,68 @@ export type AppleTargetName = (typeof APPLE_TARGETS)[number];
4949export  const  ALL_TARGETS  =  [ ...ANDROID_TARGETS ,  ...APPLE_TARGETS ]  as  const ; 
5050export  type  TargetName  =  ( typeof  ALL_TARGETS ) [ number ] ; 
5151
52+ /** 
53+  * Tier 3 Rust targets that are not available via `rustup target add`  
54+  * and require building the standard library from source using `-Zbuild-std`. 
55+  *  
56+  * @see  https://doc.rust-lang.org/rustc/platform-support.html 
57+  * @see  https://doc.rust-lang.org/cargo/reference/unstable.html#build-std 
58+  */ 
59+ export  const  TIER_3_TARGETS : readonly  TargetName [ ]  =  [ 
60+   "aarch64-apple-visionos" , 
61+   "aarch64-apple-visionos-sim" , 
62+ ]  as  const ; 
63+ 
64+ /** 
65+  * Check if a target is a tier 3 target that requires build-std 
66+  */ 
67+ export  function  isTier3Target ( target : TargetName ) : boolean  { 
68+   return  TIER_3_TARGETS . includes ( target ) ; 
69+ } 
70+ 
5271/** 
5372 * Ensure the targets are installed into the Rust toolchain 
5473 * We do this up-front because the error message and fix is very unclear from the failure when missing. 
5574 */ 
5675export  function  ensureInstalledTargets ( expectedTargets : Set < TargetName > )  { 
5776  const  installedTargets  =  getInstalledTargets ( ) ; 
58-   const  missingTargets  =  new  Set ( [ 
59-     ...[ ...expectedTargets ] . filter ( ( target )  =>  ! installedTargets . has ( target ) ) , 
77+   const  missingStandardTargets  =  new  Set ( [ 
78+     ...[ ...expectedTargets ] . filter ( 
79+       ( target )  =>  ! installedTargets . has ( target )  &&  ! isTier3Target ( target ) , 
80+     ) , 
6081  ] ) ; 
61-   if  ( missingTargets . size  >  0 )  { 
62-     // TODO: Ask the user if they want to run this 
82+   const  tier3Targets  =  new  Set ( [ 
83+     ...[ ...expectedTargets ] . filter ( ( target )  =>  isTier3Target ( target ) ) , 
84+   ] ) ; 
85+ 
86+   // Handle standard targets that can be installed via rustup 
87+   if  ( missingStandardTargets . size  >  0 )  { 
6388    throw  new  UsageError ( 
6489      `You're missing ${  
65-         missingTargets . size  
90+         missingStandardTargets . size  
6691      }   targets - to fix this, run:\n\n${ chalk . italic ( 
67-         `rustup target add ${ [ ...missingTargets ] . join ( " " ) }  ,  
92+         `rustup target add ${ [ ...missingStandardTargets ] . join ( " " ) }  ,  
6893      ) }  `, 
6994    ) ; 
7095  } 
96+ 
97+   // Handle tier 3 targets that require build-std setup 
98+   if  ( tier3Targets . size  >  0 )  { 
99+     throw  new  UsageError ( 
100+       `You're using tier 3 targets (${ [ ...tier3Targets ] . join ( ", " ) }   + 
101+         `To set up support for these targets:\n\n`  + 
102+         `1. Install nightly Rust with the rust-src component:\n`  + 
103+         `   ${ chalk . italic ( "rustup toolchain install nightly --component rust-src" ) }   + 
104+         `2. Configure Cargo to use build-std by creating a .cargo/config.toml file:\n`  + 
105+         `   ${ chalk . italic ( "[unstable]" ) }   + 
106+         `   ${ chalk . italic ( 'build-std = ["std", "panic_abort"]' ) }   + 
107+         `3. Set your default toolchain to nightly:\n`  + 
108+         `   ${ chalk . italic ( "rustup default nightly" ) }   + 
109+         `For more information, see:\n`  + 
110+         `- Rust Platform Support: ${ chalk . italic ( "https://doc.rust-lang.org/rustc/platform-support.html" ) }   + 
111+         `- Cargo build-std: ${ chalk . italic ( "https://doc.rust-lang.org/cargo/reference/unstable.html#build-std" ) }  , 
112+     ) ; 
113+   } 
71114} 
72115
73116export  function  isAndroidTarget ( 
0 commit comments