1- import  {  chalk ,  UsageError ,   assertFixable  }  from  "@react-native-node-api/cli-utils" ; 
2- import  {  getInstalledTargets ,   isBuildStdAvailable  }  from  "./rustup.js" ; 
1+ import  {  chalk ,  UsageError  }  from  "@react-native-node-api/cli-utils" ; 
2+ import  {  getInstalledTargets  }  from  "./rustup.js" ; 
33
44export  const  ANDROID_TARGETS  =  [ 
55  "aarch64-linux-android" , 
@@ -26,9 +26,9 @@ export const APPLE_TARGETS = [
2626  /* 
2727  "aarch64-apple-tvos", 
2828  "aarch64-apple-tvos-sim", 
29-   */ 
3029  "aarch64-apple-visionos", 
3130  "aarch64-apple-visionos-sim", 
31+   */ 
3232
3333  // "aarch64-apple-watchos", 
3434  // "aarch64-apple-watchos-sim", 
@@ -50,68 +50,22 @@ export const ALL_TARGETS = [...ANDROID_TARGETS, ...APPLE_TARGETS] as const;
5050export  type  TargetName  =  ( typeof  ALL_TARGETS ) [ number ] ; 
5151
5252/** 
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  as  readonly  string [ ] ) . includes ( target ) ; 
69- } 
70- 
71- /** 
72-  * Ensure the targets are available for building 
53+  * Ensure the targets are installed into the Rust toolchain 
7354 * We do this up-front because the error message and fix is very unclear from the failure when missing. 
7455 */ 
7556export  function  ensureInstalledTargets ( expectedTargets : Set < TargetName > )  { 
7657  const  installedTargets  =  getInstalledTargets ( ) ; 
77-   const  missingStandardTargets  =  new  Set ( [ 
78-     ...[ ...expectedTargets ] . filter ( 
79-       ( target )  =>  ! installedTargets . has ( target )  &&  ! isTier3Target ( target ) , 
80-     ) , 
58+   const  missingTargets  =  new  Set ( [ 
59+     ...[ ...expectedTargets ] . filter ( ( target )  =>  ! installedTargets . has ( target ) ) , 
8160  ] ) ; 
82-   const  tier3Targets  =  new  Set ( [ 
83-     ...[ ...expectedTargets ] . filter ( ( target )  =>  isTier3Target ( target ) ) , 
84-   ] ) ; 
85- 
86-   // Handle standard targets that can be installed via rustup 
87-   assertFixable ( 
88-     missingStandardTargets . size  ===  0 , 
89-     `You're missing ${ missingStandardTargets . size }  , 
90-     { 
91-       command : `rustup target add ${ [ ...missingStandardTargets ] . join ( " " ) }  , 
92-     } , 
93-   ) ; 
94- 
95-   // Handle tier 3 targets that require build-std setup 
96-   if  ( tier3Targets . size  >  0 )  { 
97-     // For tier 3 targets, check if build-std prerequisites are met 
98-     assertFixable ( 
99-       isBuildStdAvailable ( ) , 
100-       `You're using tier 3 targets (${ [ ...tier3Targets ] . join ( ", " ) }  , 
101-       { 
102-         instructions :
103-           `To set up support for these targets:\n\n`  + 
104-           `1. Install nightly Rust with the rust-src component:\n`  + 
105-           `   ${ chalk . italic ( "rustup toolchain install nightly --component rust-src" ) }   + 
106-           `2. Configure Cargo to use build-std by creating a .cargo/config.toml file:\n`  + 
107-           `   ${ chalk . italic ( "[unstable]" ) }   + 
108-           `   ${ chalk . italic ( 'build-std = ["std", "panic_abort"]' ) }   + 
109-           `3. Set your default toolchain to nightly:\n`  + 
110-           `   ${ chalk . italic ( "rustup default nightly" ) }   + 
111-           `For more information, see:\n`  + 
112-           `- Rust Platform Support: ${ chalk . italic ( "https://doc.rust-lang.org/rustc/platform-support.html" ) }   + 
113-           `- Cargo build-std: ${ chalk . italic ( "https://doc.rust-lang.org/cargo/reference/unstable.html#build-std" ) }  , 
114-       } , 
61+   if  ( missingTargets . size  >  0 )  { 
62+     // TODO: Ask the user if they want to run this 
63+     throw  new  UsageError ( 
64+       `You're missing ${  
65+         missingTargets . size  
66+       }   targets - to fix this, run:\n\n${ chalk . italic ( 
67+         `rustup target add ${ [ ...missingTargets ] . join ( " " ) }  ,  
68+       ) }  `, 
11569    ) ; 
11670  } 
11771} 
0 commit comments