@@ -17,11 +17,11 @@ import { isSupportedTriplet } from "react-native-node-api";
17
17
import { getWeakNodeApiVariables } from "./weak-node-api.js" ;
18
18
import {
19
19
platforms ,
20
- allTargets ,
21
- findPlatformForTarget ,
22
- platformHasTarget ,
20
+ allTriplets as allTriplets ,
21
+ findPlatformForTriplet ,
22
+ platformHasTriplet ,
23
23
} from "./platforms.js" ;
24
- import { BaseOpts , TargetContext , Platform } from "./platforms/types.js" ;
24
+ import { BaseOpts , TripletContext , Platform } from "./platforms/types.js" ;
25
25
26
26
// We're attaching a lot of listeners when spawning in parallel
27
27
EventEmitter . defaultMaxListeners = 100 ;
@@ -43,25 +43,28 @@ const configurationOption = new Option("--configuration <configuration>")
43
43
. choices ( [ "Release" , "Debug" ] as const )
44
44
. default ( "Release" ) ;
45
45
46
- // TODO: Derive default targets
46
+ // TODO: Derive default build triplets
47
47
// This is especially important when driving the build from within a React Native app package.
48
48
49
- const { CMAKE_RN_TARGETS } = process . env ;
49
+ const { CMAKE_RN_TRIPLETS } = process . env ;
50
50
51
- const defaultTargets = CMAKE_RN_TARGETS ? CMAKE_RN_TARGETS . split ( "," ) : [ ] ;
51
+ const defaultTriplets = CMAKE_RN_TRIPLETS ? CMAKE_RN_TRIPLETS . split ( "," ) : [ ] ;
52
52
53
- for ( const target of defaultTargets ) {
53
+ for ( const triplet of defaultTriplets ) {
54
54
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 } ` ,
57
57
) ;
58
58
}
59
59
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 )
62
65
. default (
63
- defaultTargets ,
64
- "CMAKE_RN_TARGETS environment variable split by ','" ,
66
+ defaultTriplets ,
67
+ "CMAKE_RN_TRIPLETS environment variable split by ','" ,
65
68
) ;
66
69
67
70
const buildPathOption = new Option (
@@ -111,7 +114,7 @@ const noWeakNodeApiLinkageOption = new Option(
111
114
112
115
let program = new Command ( "cmake-rn" )
113
116
. description ( "Build React Native Node API modules with CMake" )
114
- . addOption ( targetOption )
117
+ . addOption ( tripletOption )
115
118
. addOption ( verboseOption )
116
119
. addOption ( sourcePathOption )
117
120
. addOption ( buildPathOption )
@@ -132,7 +135,7 @@ for (const platform of platforms) {
132
135
}
133
136
134
137
program = program . action (
135
- wrapAction ( async ( { target : requestedTargets , ...baseOptions } ) => {
138
+ wrapAction ( async ( { triplet : requestedTriplets , ...baseOptions } ) => {
136
139
assertFixable (
137
140
fs . existsSync ( path . join ( baseOptions . source , "CMakeLists.txt" ) ) ,
138
141
`No CMakeLists.txt found in source directory: ${ chalk . dim ( baseOptions . source ) } ` ,
@@ -145,34 +148,34 @@ program = program.action(
145
148
if ( baseOptions . clean ) {
146
149
await fs . promises . rm ( buildPath , { recursive : true , force : true } ) ;
147
150
}
148
- const targets = new Set < string > ( requestedTargets ) ;
151
+ const triplets = new Set < string > ( requestedTriplets ) ;
149
152
150
153
for ( const platform of Object . values ( platforms ) ) {
151
154
// Forcing the types a bit here, since the platform id option is dynamically added
152
155
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 ) ;
155
158
}
156
159
}
157
160
}
158
161
159
- if ( targets . size === 0 ) {
162
+ if ( triplets . size === 0 ) {
160
163
for ( const platform of Object . values ( platforms ) ) {
161
164
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 ) ;
164
167
}
165
168
}
166
169
}
167
- if ( targets . size === 0 ) {
170
+ if ( triplets . size === 0 ) {
168
171
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" ,
170
173
) ;
171
174
} else {
172
175
console . error (
173
176
chalk . yellowBright ( "ℹ" ) ,
174
- "Using default targets " ,
175
- chalk . dim ( "(" + [ ...targets ] . join ( ", " ) + ")" ) ,
177
+ "Using default build triplets " ,
178
+ chalk . dim ( "(" + [ ...triplets ] . join ( ", " ) + ")" ) ,
176
179
) ;
177
180
}
178
181
}
@@ -181,38 +184,40 @@ program = program.action(
181
184
baseOptions . out = path . join ( buildPath , baseOptions . configuration ) ;
182
185
}
183
186
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 ) ;
187
190
return {
188
- target ,
191
+ triplet ,
189
192
platform,
190
- buildPath : targetBuildPath ,
191
- outputPath : path . join ( targetBuildPath , "out" ) ,
193
+ buildPath : tripletBuildPath ,
194
+ outputPath : path . join ( tripletBuildPath , "out" ) ,
192
195
options : baseOptions ,
193
196
} ;
194
197
} ) ;
195
198
196
199
// Configure every triplet project
197
- const targetsSummary = chalk . dim ( `(${ getTargetsSummary ( targetContexts ) } )` ) ;
200
+ const tripletsSummary = chalk . dim (
201
+ `(${ getTripletsSummary ( tripletContexts ) } )` ,
202
+ ) ;
198
203
await oraPromise (
199
204
Promise . all (
200
- targetContexts . map ( ( { platform, ...context } ) =>
205
+ tripletContexts . map ( ( { platform, ...context } ) =>
201
206
configureProject ( platform , context , baseOptions ) ,
202
207
) ,
203
208
) ,
204
209
{
205
- text : `Configuring projects ${ targetsSummary } ` ,
210
+ text : `Configuring projects ${ tripletsSummary } ` ,
206
211
isSilent : baseOptions . verbose ,
207
- successText : `Configured projects ${ targetsSummary } ` ,
212
+ successText : `Configured projects ${ tripletsSummary } ` ,
208
213
failText : ( { message } ) => `Failed to configure projects: ${ message } ` ,
209
214
} ,
210
215
) ;
211
216
212
217
// Build every triplet project
213
218
await oraPromise (
214
219
Promise . all (
215
- targetContexts . map ( async ( { platform, ...context } ) => {
220
+ tripletContexts . map ( async ( { platform, ...context } ) => {
216
221
// Delete any stale build artifacts before building
217
222
// This is important, since we might rename the output files
218
223
await fs . promises . rm ( context . outputPath , {
@@ -232,36 +237,36 @@ program = program.action(
232
237
233
238
// Perform post-build steps for each platform in sequence
234
239
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 ) ,
237
242
) ;
238
- if ( relevantTargets . length == 0 ) {
243
+ if ( relevantTriplets . length == 0 ) {
239
244
continue ;
240
245
}
241
246
await platform . postBuild (
242
247
{
243
248
outputPath : baseOptions . out || baseOptions . source ,
244
- targets : relevantTargets ,
249
+ triplets : relevantTriplets ,
245
250
} ,
246
251
baseOptions ,
247
252
) ;
248
253
}
249
254
} ) ,
250
255
) ;
251
256
252
- function getTargetsSummary (
253
- targetContexts : { target : string ; platform : Platform } [ ] ,
257
+ function getTripletsSummary (
258
+ tripletContexts : { triplet : string ; platform : Platform } [ ] ,
254
259
) {
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 ] = [ ] ;
259
264
}
260
- targetsPerPlatform [ platform . id ] . push ( target ) ;
265
+ tripletsPerPlatform [ platform . id ] . push ( triplet ) ;
261
266
}
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 ( ", " ) } ` ;
265
270
} )
266
271
. join ( " / " ) ;
267
272
}
@@ -272,24 +277,24 @@ function getBuildPath({ build, source }: BaseOpts) {
272
277
}
273
278
274
279
/**
275
- * Namespaces the output path with a target name
280
+ * Namespaces the output path with a triplet name
276
281
*/
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, "_" ) ) ;
280
285
}
281
286
282
287
async function configureProject < T extends string > (
283
288
platform : Platform < T [ ] , Record < string , unknown > > ,
284
- context : TargetContext < T > ,
289
+ context : TripletContext < T > ,
285
290
options : BaseOpts ,
286
291
) {
287
- const { target , buildPath, outputPath } = context ;
292
+ const { triplet , buildPath, outputPath } = context ;
288
293
const { verbose, source, weakNodeApiLinkage } = options ;
289
294
290
295
const nodeApiDefinitions =
291
- weakNodeApiLinkage && isSupportedTriplet ( target )
292
- ? getWeakNodeApiVariables ( target )
296
+ weakNodeApiLinkage && isSupportedTriplet ( triplet )
297
+ ? getWeakNodeApiVariables ( triplet )
293
298
: // TODO: Make this a part of the platform definition
294
299
{ } ;
295
300
@@ -311,17 +316,17 @@ async function configureProject<T extends string>(
311
316
] ,
312
317
{
313
318
outputMode : verbose ? "inherit" : "buffered" ,
314
- outputPrefix : verbose ? chalk . dim ( `[${ target } ] ` ) : undefined ,
319
+ outputPrefix : verbose ? chalk . dim ( `[${ triplet } ] ` ) : undefined ,
315
320
} ,
316
321
) ;
317
322
}
318
323
319
324
async function buildProject < T extends string > (
320
325
platform : Platform < T [ ] , Record < string , unknown > > ,
321
- context : TargetContext < T > ,
326
+ context : TripletContext < T > ,
322
327
options : BaseOpts ,
323
328
) {
324
- const { target , buildPath } = context ;
329
+ const { triplet , buildPath } = context ;
325
330
const { verbose, configuration } = options ;
326
331
await spawn (
327
332
"cmake" ,
@@ -335,7 +340,7 @@ async function buildProject<T extends string>(
335
340
] ,
336
341
{
337
342
outputMode : verbose ? "inherit" : "buffered" ,
338
- outputPrefix : verbose ? chalk . dim ( `[${ target } ] ` ) : undefined ,
343
+ outputPrefix : verbose ? chalk . dim ( `[${ triplet } ] ` ) : undefined ,
339
344
} ,
340
345
) ;
341
346
}
0 commit comments