@@ -33,6 +33,7 @@ import {
3333 createXCframework ,
3434 determineXCFrameworkFilename ,
3535} from "react-native-node-api" ;
36+ import { getCcacheVersion } from "./ccache.js" ;
3637
3738// We're attaching a lot of listeners when spawning in parallel
3839EventEmitter . defaultMaxListeners = 100 ;
@@ -109,6 +110,11 @@ const xcframeworkExtensionOption = new Option(
109110 "Don't rename the xcframework to .apple.node"
110111) . default ( false ) ;
111112
113+ const noCcacheOption = new Option (
114+ "--no-ccache" ,
115+ "Don't detect and use ccache to speed up builds"
116+ ) ;
117+
112118export const program = new Command ( "cmake-rn" )
113119 . description ( "Build React Native Node API modules with CMake" )
114120 . addOption ( verboseOption )
@@ -120,13 +126,24 @@ export const program = new Command("cmake-rn")
120126 . addOption ( buildPathOption )
121127 . addOption ( outPathOption )
122128 . addOption ( cleanOption )
129+ . addOption ( noCcacheOption )
123130 . addOption ( ndkVersionOption )
124131 . addOption ( androidSdkVersionOption )
125132 . addOption ( noAutoLinkOption )
126133 . addOption ( noWeakNodeApiLinkageOption )
127134 . addOption ( xcframeworkExtensionOption )
128135 . action ( async ( { triplet : tripletValues , ...globalContext } ) => {
129136 try {
137+ const ccacheVersion = globalContext . ccache
138+ ? getCcacheVersion ( )
139+ : undefined ;
140+ if ( ccacheVersion ) {
141+ console . log ( "⚡️Using ccache" , chalk . dim ( `(${ ccacheVersion } )` ) ) ;
142+ } else {
143+ // Disable ccache if not found
144+ globalContext . ccache = false ;
145+ }
146+
130147 const buildPath = getBuildPath ( globalContext ) ;
131148 if ( globalContext . clean ) {
132149 await fs . promises . rm ( buildPath , { recursive : true , force : true } ) ;
@@ -364,19 +381,21 @@ function getTripletConfigureCmakeArgs(
364381 {
365382 ndkVersion,
366383 androidSdkVersion,
384+ ccache,
367385 } : Pick <
368386 GlobalContext ,
369- "ndkVersion" | "androidSdkVersion" | "weakNodeApiLinkage"
387+ "ndkVersion" | "androidSdkVersion" | "weakNodeApiLinkage" | "ccache"
370388 >
371389) {
372390 if ( isAndroidTriplet ( triplet ) ) {
373391 return getAndroidConfigureCmakeArgs ( {
374392 triplet,
375393 ndkVersion,
376394 sdkVersion : androidSdkVersion ,
395+ ccache,
377396 } ) ;
378397 } else if ( isAppleTriplet ( triplet ) ) {
379- return getAppleConfigureCmakeArgs ( { triplet } ) ;
398+ return getAppleConfigureCmakeArgs ( { triplet, ccache } ) ;
380399 } else {
381400 throw new Error ( `Support for '${ triplet } ' is not implemented yet` ) ;
382401 }
@@ -398,6 +417,7 @@ async function configureProject(context: TripletScopedContext) {
398417 triplet,
399418 tripletBuildPath,
400419 source,
420+ ccache,
401421 ndkVersion,
402422 androidSdkVersion,
403423 weakNodeApiLinkage,
@@ -411,6 +431,7 @@ async function configureProject(context: TripletScopedContext) {
411431 tripletBuildPath ,
412432 ...getVariablesArgs ( getVariables ( context ) ) ,
413433 ...getTripletConfigureCmakeArgs ( triplet , {
434+ ccache,
414435 ndkVersion,
415436 weakNodeApiLinkage,
416437 androidSdkVersion,
0 commit comments