1- import { chalk , UsageError } from "@react-native-node-api/cli-utils" ;
1+ import { chalk , UsageError , assertFixable } from "@react-native-node-api/cli-utils" ;
22import { getInstalledTargets } from "./rustup.js" ;
33
44export const ANDROID_TARGETS = [
@@ -65,7 +65,7 @@ export const TIER_3_TARGETS: readonly TargetName[] = [
6565 * Check if a target is a tier 3 target that requires build-std
6666 */
6767export function isTier3Target ( target : TargetName ) : boolean {
68- return TIER_3_TARGETS . includes ( target ) ;
68+ return ( TIER_3_TARGETS as readonly string [ ] ) . includes ( target ) ;
6969}
7070
7171/**
@@ -84,20 +84,25 @@ export function ensureInstalledTargets(expectedTargets: Set<TargetName>) {
8484 ] ) ;
8585
8686 // Handle standard targets that can be installed via rustup
87- if ( missingStandardTargets . size > 0 ) {
88- throw new UsageError (
89- `You're missing ${
90- missingStandardTargets . size
91- } targets - to fix this, run:\n\n${ chalk . italic (
92- `rustup target add ${ [ ...missingStandardTargets ] . join ( " " ) } ` ,
93- ) } `,
94- ) ;
95- }
87+ assertFixable (
88+ missingStandardTargets . size === 0 ,
89+ `You're missing ${ missingStandardTargets . size } targets` ,
90+ {
91+ command : `rustup target add ${ [ ...missingStandardTargets ] . join ( " " ) } ` ,
92+ } ,
93+ ) ;
9694
9795 // 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 ( ", " ) } ) that require building the standard library from source.\n\n` +
96+ // Check if tier 3 targets are properly configured (included in installedTargets means they're available)
97+ const missingTier3Targets = new Set ( [
98+ ...[ ...tier3Targets ] . filter ( ( target ) => ! installedTargets . has ( target ) ) ,
99+ ] ) ;
100+
101+ assertFixable (
102+ missingTier3Targets . size === 0 ,
103+ `You're using tier 3 targets (${ [ ...missingTier3Targets ] . join ( ", " ) } ) that require building the standard library from source` ,
104+ {
105+ instructions :
101106 `To set up support for these targets:\n\n` +
102107 `1. Install nightly Rust with the rust-src component:\n` +
103108 ` ${ chalk . italic ( "rustup toolchain install nightly --component rust-src" ) } \n\n` +
@@ -109,8 +114,8 @@ export function ensureInstalledTargets(expectedTargets: Set<TargetName>) {
109114 `For more information, see:\n` +
110115 `- Rust Platform Support: ${ chalk . italic ( "https://doc.rust-lang.org/rustc/platform-support.html" ) } \n` +
111116 `- Cargo build-std: ${ chalk . italic ( "https://doc.rust-lang.org/cargo/reference/unstable.html#build-std" ) } ` ,
112- ) ;
113- }
117+ } ,
118+ ) ;
114119}
115120
116121export function isAndroidTarget (
0 commit comments