11import { chalk , UsageError , assertFixable } from "@react-native-node-api/cli-utils" ;
2- import { getInstalledTargets } from "./rustup.js" ;
2+ import { getInstalledTargets , isBuildStdAvailable } from "./rustup.js" ;
33
44export const ANDROID_TARGETS = [
55 "aarch64-linux-android" ,
@@ -69,7 +69,7 @@ export function isTier3Target(target: TargetName): boolean {
6969}
7070
7171/**
72- * Ensure the targets are installed into the Rust toolchain
72+ * Ensure the targets are available for building
7373 * We do this up-front because the error message and fix is very unclear from the failure when missing.
7474 */
7575export function ensureInstalledTargets ( expectedTargets : Set < TargetName > ) {
@@ -93,29 +93,27 @@ export function ensureInstalledTargets(expectedTargets: Set<TargetName>) {
9393 ) ;
9494
9595 // Handle tier 3 targets that require build-std setup
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 :
106- `To set up support for these targets:\n\n` +
107- `1. Install nightly Rust with the rust-src component:\n` +
108- ` ${ chalk . italic ( "rustup toolchain install nightly --component rust-src" ) } \n\n` +
109- `2. Configure Cargo to use build-std by creating a .cargo/config.toml file:\n` +
110- ` ${ chalk . italic ( "[unstable]" ) } \n` +
111- ` ${ chalk . italic ( 'build-std = ["std", "panic_abort"]' ) } \n\n` +
112- `3. Set your default toolchain to nightly:\n` +
113- ` ${ chalk . italic ( "rustup default nightly" ) } \n\n` +
114- `For more information, see:\n` +
115- `- Rust Platform Support: ${ chalk . italic ( "https://doc.rust-lang.org/rustc/platform-support.html" ) } \n` +
116- `- Cargo build-std: ${ chalk . italic ( "https://doc.rust-lang.org/cargo/reference/unstable.html#build-std" ) } ` ,
117- } ,
118- ) ;
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 ( ", " ) } ) that require building the standard library from source` ,
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" ) } \n\n` +
106+ `2. Configure Cargo to use build-std by creating a .cargo/config.toml file:\n` +
107+ ` ${ chalk . italic ( "[unstable]" ) } \n` +
108+ ` ${ chalk . italic ( 'build-std = ["std", "panic_abort"]' ) } \n\n` +
109+ `3. Set your default toolchain to nightly:\n` +
110+ ` ${ chalk . italic ( "rustup default nightly" ) } \n\n` +
111+ `For more information, see:\n` +
112+ `- Rust Platform Support: ${ chalk . italic ( "https://doc.rust-lang.org/rustc/platform-support.html" ) } \n` +
113+ `- Cargo build-std: ${ chalk . italic ( "https://doc.rust-lang.org/cargo/reference/unstable.html#build-std" ) } ` ,
114+ } ,
115+ ) ;
116+ }
119117}
120118
121119export function isAndroidTarget (
0 commit comments