@@ -17,11 +17,11 @@ import { isSupportedTriplet } from "react-native-node-api";
1717import { getWeakNodeApiVariables } from "./weak-node-api.js" ;
1818import {
1919 platforms ,
20- allTargets ,
21- findPlatformForTarget ,
22- platformHasTarget ,
20+ allTriplets as allTriplets ,
21+ findPlatformForTriplet ,
22+ platformHasTriplet ,
2323} from "./platforms.js" ;
24- import { BaseOpts , TargetContext , Platform } from "./platforms/types.js" ;
24+ import { BaseOpts , TripletContext , Platform } from "./platforms/types.js" ;
2525
2626// We're attaching a lot of listeners when spawning in parallel
2727EventEmitter . defaultMaxListeners = 100 ;
@@ -43,25 +43,28 @@ const configurationOption = new Option("--configuration <configuration>")
4343 . choices ( [ "Release" , "Debug" ] as const )
4444 . default ( "Release" ) ;
4545
46- // TODO: Derive default targets
46+ // TODO: Derive default build triplets
4747// This is especially important when driving the build from within a React Native app package.
4848
49- const { CMAKE_RN_TARGETS } = process . env ;
49+ const { CMAKE_RN_TRIPLETS } = process . env ;
5050
51- const defaultTargets = CMAKE_RN_TARGETS ? CMAKE_RN_TARGETS . split ( "," ) : [ ] ;
51+ const defaultTriplets = CMAKE_RN_TRIPLETS ? CMAKE_RN_TRIPLETS . split ( "," ) : [ ] ;
5252
53- for ( const target of defaultTargets ) {
53+ for ( const triplet of defaultTriplets ) {
5454 assert (
55- ( allTargets as string [ ] ) . includes ( target ) ,
56- `Unexpected target in CMAKE_RN_TARGETS : ${ target } ` ,
55+ ( allTriplets as string [ ] ) . includes ( triplet ) ,
56+ `Unexpected triplet in CMAKE_RN_TRIPLETS : ${ triplet } ` ,
5757 ) ;
5858}
5959
60- const targetOption = new Option ( "--target <target...>" , "Targets to build for" )
61- . choices ( allTargets )
60+ const tripletOption = new Option (
61+ "--triplet <triplet...>" ,
62+ "Triplets to build for" ,
63+ )
64+ . choices ( allTriplets )
6265 . default (
63- defaultTargets ,
64- "CMAKE_RN_TARGETS environment variable split by ','" ,
66+ defaultTriplets ,
67+ "CMAKE_RN_TRIPLETS environment variable split by ','" ,
6568 ) ;
6669
6770const buildPathOption = new Option (
@@ -111,7 +114,7 @@ const noWeakNodeApiLinkageOption = new Option(
111114
112115let program = new Command ( "cmake-rn" )
113116 . description ( "Build React Native Node API modules with CMake" )
114- . addOption ( targetOption )
117+ . addOption ( tripletOption )
115118 . addOption ( verboseOption )
116119 . addOption ( sourcePathOption )
117120 . addOption ( buildPathOption )
@@ -132,7 +135,7 @@ for (const platform of platforms) {
132135}
133136
134137program = program . action (
135- wrapAction ( async ( { target : requestedTargets , ...baseOptions } ) => {
138+ wrapAction ( async ( { triplet : requestedTriplets , ...baseOptions } ) => {
136139 assertFixable (
137140 fs . existsSync ( path . join ( baseOptions . source , "CMakeLists.txt" ) ) ,
138141 `No CMakeLists.txt found in source directory: ${ chalk . dim ( baseOptions . source ) } ` ,
@@ -145,34 +148,34 @@ program = program.action(
145148 if ( baseOptions . clean ) {
146149 await fs . promises . rm ( buildPath , { recursive : true , force : true } ) ;
147150 }
148- const targets = new Set < string > ( requestedTargets ) ;
151+ const triplets = new Set < string > ( requestedTriplets ) ;
149152
150153 for ( const platform of Object . values ( platforms ) ) {
151154 // Forcing the types a bit here, since the platform id option is dynamically added
152155 if ( ( baseOptions as Record < string , unknown > ) [ platform . id ] ) {
153- for ( const target of platform . targets ) {
154- targets . add ( target ) ;
156+ for ( const triplet of platform . triplets ) {
157+ triplets . add ( triplet ) ;
155158 }
156159 }
157160 }
158161
159- if ( targets . size === 0 ) {
162+ if ( triplets . size === 0 ) {
160163 for ( const platform of Object . values ( platforms ) ) {
161164 if ( platform . isSupportedByHost ( ) ) {
162- for ( const target of await platform . defaultTargets ( ) ) {
163- targets . add ( target ) ;
165+ for ( const triplet of await platform . defaultTriplets ( ) ) {
166+ triplets . add ( triplet ) ;
164167 }
165168 }
166169 }
167- if ( targets . size === 0 ) {
170+ if ( triplets . size === 0 ) {
168171 throw new Error (
169- "Found no default targets : Install some platform specific build tools" ,
172+ "Found no default build triplets : Install some platform specific build tools" ,
170173 ) ;
171174 } else {
172175 console . error (
173176 chalk . yellowBright ( "ℹ" ) ,
174- "Using default targets " ,
175- chalk . dim ( "(" + [ ...targets ] . join ( ", " ) + ")" ) ,
177+ "Using default build triplets " ,
178+ chalk . dim ( "(" + [ ...triplets ] . join ( ", " ) + ")" ) ,
176179 ) ;
177180 }
178181 }
@@ -181,38 +184,40 @@ program = program.action(
181184 baseOptions . out = path . join ( buildPath , baseOptions . configuration ) ;
182185 }
183186
184- const targetContexts = [ ...targets ] . map ( ( target ) => {
185- const platform = findPlatformForTarget ( target ) ;
186- const targetBuildPath = getTargetBuildPath ( buildPath , target ) ;
187+ const tripletContexts = [ ...triplets ] . map ( ( triplet ) => {
188+ const platform = findPlatformForTriplet ( triplet ) ;
189+ const tripletBuildPath = getTripletBuildPath ( buildPath , triplet ) ;
187190 return {
188- target ,
191+ triplet ,
189192 platform,
190- buildPath : targetBuildPath ,
191- outputPath : path . join ( targetBuildPath , "out" ) ,
193+ buildPath : tripletBuildPath ,
194+ outputPath : path . join ( tripletBuildPath , "out" ) ,
192195 options : baseOptions ,
193196 } ;
194197 } ) ;
195198
196199 // Configure every triplet project
197- const targetsSummary = chalk . dim ( `(${ getTargetsSummary ( targetContexts ) } )` ) ;
200+ const tripletsSummary = chalk . dim (
201+ `(${ getTripletsSummary ( tripletContexts ) } )` ,
202+ ) ;
198203 await oraPromise (
199204 Promise . all (
200- targetContexts . map ( ( { platform, ...context } ) =>
205+ tripletContexts . map ( ( { platform, ...context } ) =>
201206 configureProject ( platform , context , baseOptions ) ,
202207 ) ,
203208 ) ,
204209 {
205- text : `Configuring projects ${ targetsSummary } ` ,
210+ text : `Configuring projects ${ tripletsSummary } ` ,
206211 isSilent : baseOptions . verbose ,
207- successText : `Configured projects ${ targetsSummary } ` ,
212+ successText : `Configured projects ${ tripletsSummary } ` ,
208213 failText : ( { message } ) => `Failed to configure projects: ${ message } ` ,
209214 } ,
210215 ) ;
211216
212217 // Build every triplet project
213218 await oraPromise (
214219 Promise . all (
215- targetContexts . map ( async ( { platform, ...context } ) => {
220+ tripletContexts . map ( async ( { platform, ...context } ) => {
216221 // Delete any stale build artifacts before building
217222 // This is important, since we might rename the output files
218223 await fs . promises . rm ( context . outputPath , {
@@ -232,36 +237,36 @@ program = program.action(
232237
233238 // Perform post-build steps for each platform in sequence
234239 for ( const platform of platforms ) {
235- const relevantTargets = targetContexts . filter ( ( { target } ) =>
236- platformHasTarget ( platform , target ) ,
240+ const relevantTriplets = tripletContexts . filter ( ( { triplet } ) =>
241+ platformHasTriplet ( platform , triplet ) ,
237242 ) ;
238- if ( relevantTargets . length == 0 ) {
243+ if ( relevantTriplets . length == 0 ) {
239244 continue ;
240245 }
241246 await platform . postBuild (
242247 {
243248 outputPath : baseOptions . out || baseOptions . source ,
244- targets : relevantTargets ,
249+ triplets : relevantTriplets ,
245250 } ,
246251 baseOptions ,
247252 ) ;
248253 }
249254 } ) ,
250255) ;
251256
252- function getTargetsSummary (
253- targetContexts : { target : string ; platform : Platform } [ ] ,
257+ function getTripletsSummary (
258+ tripletContexts : { triplet : string ; platform : Platform } [ ] ,
254259) {
255- const targetsPerPlatform : Record < string , string [ ] > = { } ;
256- for ( const { target , platform } of targetContexts ) {
257- if ( ! targetsPerPlatform [ platform . id ] ) {
258- targetsPerPlatform [ platform . id ] = [ ] ;
260+ const tripletsPerPlatform : Record < string , string [ ] > = { } ;
261+ for ( const { triplet , platform } of tripletContexts ) {
262+ if ( ! tripletsPerPlatform [ platform . id ] ) {
263+ tripletsPerPlatform [ platform . id ] = [ ] ;
259264 }
260- targetsPerPlatform [ platform . id ] . push ( target ) ;
265+ tripletsPerPlatform [ platform . id ] . push ( triplet ) ;
261266 }
262- return Object . entries ( targetsPerPlatform )
263- . map ( ( [ platformId , targets ] ) => {
264- return `${ platformId } : ${ targets . join ( ", " ) } ` ;
267+ return Object . entries ( tripletsPerPlatform )
268+ . map ( ( [ platformId , triplets ] ) => {
269+ return `${ platformId } : ${ triplets . join ( ", " ) } ` ;
265270 } )
266271 . join ( " / " ) ;
267272}
@@ -272,24 +277,24 @@ function getBuildPath({ build, source }: BaseOpts) {
272277}
273278
274279/**
275- * Namespaces the output path with a target name
280+ * Namespaces the output path with a triplet name
276281 */
277- function getTargetBuildPath ( buildPath : string , target : unknown ) {
278- assert ( typeof target === "string" , "Expected target to be a string" ) ;
279- return path . join ( buildPath , target . replace ( / ; / g, "_" ) ) ;
282+ function getTripletBuildPath ( buildPath : string , triplet : unknown ) {
283+ assert ( typeof triplet === "string" , "Expected triplet to be a string" ) ;
284+ return path . join ( buildPath , triplet . replace ( / ; / g, "_" ) ) ;
280285}
281286
282287async function configureProject < T extends string > (
283288 platform : Platform < T [ ] , Record < string , unknown > > ,
284- context : TargetContext < T > ,
289+ context : TripletContext < T > ,
285290 options : BaseOpts ,
286291) {
287- const { target , buildPath, outputPath } = context ;
292+ const { triplet , buildPath, outputPath } = context ;
288293 const { verbose, source, weakNodeApiLinkage } = options ;
289294
290295 const nodeApiDefinitions =
291- weakNodeApiLinkage && isSupportedTriplet ( target )
292- ? getWeakNodeApiVariables ( target )
296+ weakNodeApiLinkage && isSupportedTriplet ( triplet )
297+ ? getWeakNodeApiVariables ( triplet )
293298 : // TODO: Make this a part of the platform definition
294299 { } ;
295300
@@ -311,17 +316,17 @@ async function configureProject<T extends string>(
311316 ] ,
312317 {
313318 outputMode : verbose ? "inherit" : "buffered" ,
314- outputPrefix : verbose ? chalk . dim ( `[${ target } ] ` ) : undefined ,
319+ outputPrefix : verbose ? chalk . dim ( `[${ triplet } ] ` ) : undefined ,
315320 } ,
316321 ) ;
317322}
318323
319324async function buildProject < T extends string > (
320325 platform : Platform < T [ ] , Record < string , unknown > > ,
321- context : TargetContext < T > ,
326+ context : TripletContext < T > ,
322327 options : BaseOpts ,
323328) {
324- const { target , buildPath } = context ;
329+ const { triplet , buildPath } = context ;
325330 const { verbose, configuration } = options ;
326331 await spawn (
327332 "cmake" ,
@@ -335,7 +340,7 @@ async function buildProject<T extends string>(
335340 ] ,
336341 {
337342 outputMode : verbose ? "inherit" : "buffered" ,
338- outputPrefix : verbose ? chalk . dim ( `[${ target } ] ` ) : undefined ,
343+ outputPrefix : verbose ? chalk . dim ( `[${ triplet } ] ` ) : undefined ,
339344 } ,
340345 ) ;
341346}
0 commit comments