Skip to content

Commit

Permalink
Add iOS Support (#63)
Browse files Browse the repository at this point in the history
* ios: upgrade Node to v18.7.1

* ios: Fix scripts for cordova-ios 7+

* ios: reenable ios support
  • Loading branch information
ManWithBear authored Jan 20, 2024
1 parent 02b37e6 commit 6fc6b05
Show file tree
Hide file tree
Showing 839 changed files with 133,925 additions and 81,249 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store

# Created by https://www.toptal.com/developers/gitignore/api/node
# Edit at https://www.toptal.com/developers/gitignore?templates=node

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- Cordova 12.x or higher
- Android API 24 or higher
- iOS 11 or higher

When building an application for the Android platform, make sure you have the [Android NDK](https://developer.android.com/ndk/index.html) installed and the environment variable `ANDROID_NDK_HOME` set, for example:

Expand All @@ -20,6 +21,7 @@ When building an application for the Android platform, make sure you have the [A
## Supported Platforms

- Android (ARMv7a, ARM64)
- iOS (arm64)

## Reporting Issues

Expand Down
46 changes: 39 additions & 7 deletions install/hooks/ios/after-plugin-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = function(context) {
// Require the iOS platform Api to get the Xcode .pbxproj path.
var iosPlatformPath = path.join(context.opts.projectRoot, 'platforms', 'ios');
var iosAPI = require(path.join(iosPlatformPath, 'cordova', 'Api'));
var iosAPIInstance = new iosAPI();
var iosAPIInstance = new iosAPI('ios', iosPlatformPath);
var pbxprojPath = iosAPIInstance.locations.pbxproj;

// Read the Xcode project and get the target.
Expand All @@ -19,6 +19,15 @@ module.exports = function(context) {
var rebuildNativeModulesBuildPhaseName = 'Build Node.js Mobile Native Modules';
var rebuildNativeModulesBuildPhaseScript = `
set -e
# On M1 macs homebrew is located outside /usr/local/bin
if [[ ! $PATH =~ /opt/homebrew/bin: ]]; then
PATH="/opt/homebrew/bin/:/opt/homebrew/sbin:$PATH"
fi
# Xcode executes script build phases in independant shell environment.
# Force load users configuration file
[ -f "$ZDOTDIR"/.zshrc ] && source "$ZDOTDIR"/.zshrc
if [ -z "$NODEJS_MOBILE_BUILD_NATIVE_MODULES" ]; then
# If build native modules preference is not set, look for it in the project's
# www/NODEJS_MOBILE_BUILD_NATIVE_MODULES_VALUE.txt
Expand Down Expand Up @@ -66,13 +75,27 @@ NODEJS_HEADERS_DIR="$( cd "$( dirname "$PRODUCT_SETTINGS_PATH" )" && cd Plugins/
if [ -d "$PROJECT_DIR/../../www/nodejs-project/node_modules/.bin/" ]; then
PATH="$PROJECT_DIR/../../www/nodejs-project/node_modules/.bin/:$PATH"
fi
pushd $CODESIGNING_FOLDER_PATH/www/nodejs-project/
if [ "$PLATFORM_NAME" == "iphoneos" ]
then
GYP_DEFINES="OS=ios" npm_config_nodedir="$NODEJS_HEADERS_DIR" npm_config_node_gyp="$NODEJS_MOBILE_GYP_BIN_FILE" npm_config_platform="ios" npm_config_format="make-ios" npm_config_node_engine="chakracore" npm_config_arch="arm64" npm --verbose rebuild --build-from-source
export GYP_DEFINES="OS=ios"
export npm_config_nodedir="$NODEJS_HEADERS_DIR"
export npm_config_node_gyp="$NODEJS_MOBILE_GYP_BIN_FILE"
export npm_config_format="make-ios"
export npm_config_node_engine="chakracore"
export NODEJS_MOBILE_GYP="$NODEJS_MOBILE_GYP_BIN_FILE"
export npm_config_platform="ios"
if [[ "$PLATFORM_NAME" == "iphoneos" ]]; then
export npm_config_arch="arm64"
else
GYP_DEFINES="OS=ios" npm_config_nodedir="$NODEJS_HEADERS_DIR" npm_config_node_gyp="$NODEJS_MOBILE_GYP_BIN_FILE" npm_config_platform="ios" npm_config_format="make-ios" npm_config_node_engine="chakracore" npm_config_arch="x64" npm --verbose rebuild --build-from-source
if [[ "$HOST_ARCH" == "arm64" ]] ; then # M1 mac
export GYP_DEFINES="OS=ios iossim=true"
export npm_config_arch="arm64"
else
export npm_config_arch="x64"
fi
fi
npm --verbose rebuild --build-from-source
popd
`
var rebuildNativeModulesBuildPhase = xcodeProject.buildPhaseObject('PBXShellScriptBuildPhase', rebuildNativeModulesBuildPhaseName, firstTargetUUID);
Expand All @@ -82,14 +105,23 @@ popd
'PBXShellScriptBuildPhase',
rebuildNativeModulesBuildPhaseName,
firstTargetUUID,
{ shellPath: '/bin/sh', shellScript: rebuildNativeModulesBuildPhaseScript }
{ shellPath: '/bin/zsh', shellScript: rebuildNativeModulesBuildPhaseScript }
);
}

// Adds a build phase to sign native modules.
var signNativeModulesBuildPhaseName = 'Sign Node.js Mobile Native Modules';
var signNativeModulesBuildPhaseScript = `
set -e
# On M1 macs homebrew is located outside /usr/local/bin
if [[ ! $PATH =~ /opt/homebrew/bin: ]]; then
PATH="/opt/homebrew/bin/:/opt/homebrew/sbin:$PATH"
fi
# Xcode executes script build phases in independant shell environment.
# Force load users configuration file
[ -f "$ZDOTDIR"/.zshrc ] && source "$ZDOTDIR"/.zshrc
if [ -z "$NODEJS_MOBILE_BUILD_NATIVE_MODULES" ]; then
# If build native modules preference is not set, look for it in the project's
# www/NODEJS_MOBILE_BUILD_NATIVE_MODULES_VALUE.txt
Expand Down Expand Up @@ -143,7 +175,7 @@ find "$CODESIGNING_FOLDER_PATH/www/nodejs-project/" -name "*.framework" -type d
'PBXShellScriptBuildPhase',
signNativeModulesBuildPhaseName,
firstTargetUUID,
{ shellPath: '/bin/sh', shellScript: signNativeModulesBuildPhaseScript }
{ shellPath: '/bin/zsh', shellScript: signNativeModulesBuildPhaseScript }
);
}

Expand Down
2 changes: 1 addition & 1 deletion install/hooks/ios/before-plugin-uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = function(context) {
// Require the iOS platform Api to get the Xcode .pbxproj path.
var iosPlatformPath = path.join(context.opts.projectRoot, 'platforms', 'ios');
var iosAPI = require(path.join(iosPlatformPath, 'cordova', 'Api'));
var iosAPIInstance = new iosAPI();
var iosAPIInstance = new iosAPI('ios', iosPlatformPath);
var pbxprojPath = iosAPIInstance.locations.pbxproj;

// Read the Xcode project and get the target.
Expand Down
4 changes: 2 additions & 2 deletions install/hooks/ios/fix-xcframework-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ module.exports = function(context) {
// Require the iOS platform Api to get the Xcode .pbxproj path.
var iosPlatformPath = path.join(context.opts.projectRoot, 'platforms', 'ios');
var iosAPI = require(path.join(iosPlatformPath, 'cordova', 'Api'));
var iosAPIInstance = new iosAPI();
var iosAPIInstance = new iosAPI('ios', iosPlatformPath);
var pbxprojPath = iosAPIInstance.locations.pbxproj;
var rootIosProjDir = iosAPIInstance.locations.root;
var cordovaProjPath = iosAPIInstance.locations.xcodeCordovaProj;
var xcFrameworkPath = path.join(cordovaProjPath, 'Plugins', 'nodejs-mobile-cordova', 'NodeMobile.xcframework');
var xcFrameworkPath = path.join(cordovaProjPath, 'Plugins', '@red-mobile', 'nodejs-mobile-cordova', 'NodeMobile.xcframework');
var relativeXcFrameworkPath = path.relative(rootIosProjDir, xcFrameworkPath);

// Patch the project file to fix a .xcframework include error.
Expand Down
Binary file modified libs/ios/nodemobile/NodeMobile.xcframework.tar.zip
Binary file not shown.
Loading

0 comments on commit 6fc6b05

Please sign in to comment.