Skip to content

Commit

Permalink
ios: native modules support
Browse files Browse the repository at this point in the history
Adds run scripts phases to the XCode project to build and sign
npm native modules. These can be activated by setting the
environment variable 'NODEJS_MOBILE_BUILD_NATIVE_MODULES' to 1.
  • Loading branch information
jaimecbernardo committed Feb 12, 2018
1 parent af82e39 commit 62c2670
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions scripts/module-postlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,49 @@ if ( detectedConfigs && detectedConfigs.ios && detectedConfigs.ios.pbxprojPath)
'ENABLE_BITCODE','NO','Release'
);

//Adds a build phase to rebuild native modules
var rebuildNativeModulesBuildPhaseName = 'Build NodeJS Mobile Native Modules';
var rebuildNativeModulesBuildPhaseScript = `
if [ "1" != "$NODEJS_MOBILE_BUILD_NATIVE_MODULES" ]; then exit 0; fi
set -e
NODEJS_HEADERS_DIR="$( cd "$PROJECT_DIR" && cd ../node_modules/nodejs-mobile-react-native/ios/libnode/ && pwd )"
pushd $CODESIGNING_FOLDER_PATH/nodejs-project/
if [ "$PLATFORM_NAME" == "iphoneos" ]
then
GYP_DEFINES="OS=ios" npm_config_nodedir="$NODEJS_HEADERS_DIR" npm_config_platform="ios" npm_config_node_engine="chakracore" npm_config_arch="arm64" npm --verbose rebuild --build-from-source
else
GYP_DEFINES="OS=ios" npm_config_nodedir="$NODEJS_HEADERS_DIR" npm_config_platform="ios" npm_config_node_engine="chakracore" npm_config_arch="x64" npm --verbose rebuild --build-from-source
fi
popd
`
var rebuildNativeModulesBuildPhase = xcodeProject.buildPhaseObject('PBXShellScriptBuildPhase', rebuildNativeModulesBuildPhaseName, firstTargetUUID);
if (!(rebuildNativeModulesBuildPhase)) {
xcodeProject.addBuildPhase(
[],
'PBXShellScriptBuildPhase',
rebuildNativeModulesBuildPhaseName,
firstTargetUUID,
{ shellPath: '/bin/sh', shellScript: rebuildNativeModulesBuildPhaseScript }
);
}

//Adds a build phase to sign native modules
var signNativeModulesBuildPhaseName = 'Sign NodeJS Mobile Native Modules';
var signNativeModulesBuildPhaseScript = `
if [ "1" != "$NODEJS_MOBILE_BUILD_NATIVE_MODULES" ]; then exit 0; fi
/usr/bin/codesign --force --sign $EXPANDED_CODE_SIGN_IDENTITY --preserve-metadata=identifier,entitlements,flags --timestamp=none $(find "$CODESIGNING_FOLDER_PATH/nodejs-project/" -type f -name "*.node")
`
var signNativeModulesBuildPhase = xcodeProject.buildPhaseObject('PBXShellScriptBuildPhase', signNativeModulesBuildPhaseName, firstTargetUUID);
if (!(signNativeModulesBuildPhase)) {
xcodeProject.addBuildPhase(
[],
'PBXShellScriptBuildPhase',
signNativeModulesBuildPhaseName,
firstTargetUUID,
{ shellPath: '/bin/sh', shellScript: signNativeModulesBuildPhaseScript }
);
}

//Writes the updated .pbx file
fs.writeFileSync(pbxProjectPath,xcodeProject.writeSync(),'utf-8');
});
Expand Down

0 comments on commit 62c2670

Please sign in to comment.