Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update XCFramework setup to work with React Native 0.71.11 (#5924)
* Update Gutenberg reference * Update script for generating React-Codegen The method we used to generate React-Codegen (get_react_codegen_spec) was moved to a different file in newer versions of React Native. We need to update the script for generating it accordingly. * Update third-party podspecs to target 0.71.11 * Update FBReactNativeSpec.podspec.json with hash * Apply bundle changes * Manually add React-bridging.podspec.json The file was automatically deleted via the generate-podspecs.sh script. It has been manually added as a temporary measure, to enable further testing. * Revert "Manually add React-bridging.podspec.json" This reverts commit 9707305. * Update list of dependencies in Podfile for iOS * Add tag to Hermes podspec to workaround error This is intended as a temporary workaround, we should implement a more robust fix before merging. * Update dependency versions in Podfile.lock * [Temporary] Add React Native as a dependency * Revert "[Temporary] Add React Native as a dependency" This reverts commit 21a4fbe. * Update Gutenberg ref * Update Gutenberg ref * Point RNReanimated to a custom branch to work around 2.17.0 issue The issue is due to RNReanimated looking for react-native in the node_modules relative to its location, which is how most projects would be setup. Unfortunately, our projects is not standard. When running `pod install` or `pod update`, we'd get: ``` Installing RNReanimated 2.17.0 (was 2.9.1-wp-4) internal/modules/cjs/loader.js:934 throw err; ^ Error: Cannot find module 'react-native/package.json' Require stack: - /Users/gio/Developer/a8c/gutenberg-mobile/ios-xcframework/[eval] at Function.Module._resolveFilename (internal/modules/cjs/loader.js:931:15) at Function.resolve (internal/modules/cjs/helpers.js:113:19) at [eval]:1:9 at Script.runInThisContext (vm.js:134:12) at Object.runInThisContext (vm.js:310:38) at internal/process/execution.js:81:19 at [eval]-wrapper:6:22 at evalScript (internal/process/execution.js:80:60) at internal/main/eval_string.js:27:3 { code: 'MODULE_NOT_FOUND', requireStack: [ '/Users/gio/Developer/a8c/gutenberg-mobile/ios-xcframework/[eval]' ] } [!] Invalid `RNReanimated.podspec` file: no implicit conversion of nil into String. # from /var/folders/dq/cdqxvx3s5ps75564rpmb_dc00000gn/T/d20230627-89428-abwplk/RNReanimated.podspec:5 # ------------------------------------------- # reanimated_package_json = JSON.parse(File.read(File.join(__dir__, "package.json"))) > config = find_config() # assert_no_multiple_instances(config) # ------------------------------------------- ``` * Print message during `pod install` about `REACT_NATIVE_NODE_MODULES_DIR` * Setup NVM and node modules for RNReanimated in XCFramework CI step * Apply bundle changes * Switch to using `use_react_native!` in XCFramework `Podfile` Using only our custom specs, the build failed with ``` Multiple commands produce '/Users/gio/Developer/a8c/gutenberg-mobile/ios-xcframework/DerivedData/XCFrameworkScaffold/Build/Products/Debug-iphonesimulator/ReactCommon/ReactCommon.framework/Headers/CallbackWrapper.h' - Target 'ReactCommon' (project 'Pods') has copy command from '/Users/gio/Developer/a8c/gutenberg-mobile/ios-xcframework/Pods/ReactCommon/react/bridging/CallbackWrapper.h' to '/Users/gio/Developer/a8c/gutenberg-mobile/ios-xcframework/DerivedData/XCFrameworkScaffold/Build/Products/Debug-iphonesimulator/ReactCommon/ReactCommon.framework/Headers/CallbackWrapper.h' - Target 'ReactCommon' (project 'Pods') has copy command from '/Users/gio/Developer/a8c/gutenberg-mobile/ios-xcframework/Pods/ReactCommon/react/nativemodule/core/ReactCommon/CallbackWrapper.h' to '/Users/gio/Developer/a8c/gutenberg-mobile/ios-xcframework/DerivedData/XCFrameworkScaffold/Build/Products/Debug-iphonesimulator/ReactCommon/ReactCommon.framework/Headers/CallbackWrapper.h' ``` However, with this setup the build fails with: ``` /Users/gio/Developer/a8c/gutenberg-mobile/ios-xcframework/Pods/../../gutenberg/node_modules/react-native/React/FBReactNativeSpec/../../scripts/xcode/with-environment.sh: line 35: .xcode.env: command not found /Users/gio/Developer/a8c/gutenberg-mobile/ios-xcframework/Pods/../../gutenberg/node_modules/react-native/React/FBReactNativeSpec/../../scripts/xcode/with-environment.sh: line 35: node: command not found [Warning] You need to configure your node path in the environment. You can set it up quickly by running: echo 'export NODE_BINARY=' > .xcode.env in the ios folder. This is needed by React Native to work correctly. We fallback to the DEPRECATED behavior of finding . This will be REMOVED in a future version. You can read more about this here: https://reactnative.dev/docs/environment-setup#optional-configuring-your-environment /Users/gio/Developer/a8c/gutenberg-mobile/ios-xcframework/Pods/../../gutenberg/node_modules/react-native/React/FBReactNativeSpec/../../scripts/xcode/with-environment.sh: line 41: /scripts/find-node-for-xcode.sh: No such file or directory [Error] Could not find node. It looks like that the .xcode.env or .xcode.env.local ``` * Add React Native `post_install` hook * Use `.xcode.env` instead of `.xcode.env.local` This way, users can override what CocoaPods does without modifying the codebase via the `.local` file. * Bump XCFramework deployment target to iOS 15.0 * Use Xcode 14.3.1 in CI, like WordPress iOS does Otherwise, we're getting a compilation failure. See wordpress-mobile/WordPress-iOS@eadad98#commitcomment-119894859 * Disable Hermes when building XCFramework * Refine messaging when setting `REACT_NATIVE_NODE_MODULES_DIR` env var * Set `SKIP_INSTALL = NO` at the `xcconfig` level, too * Switch an `unless !=` to `if ==` * Add workaround to setup Hermes correctly in XCFramework They will take place if the process runs with `HERMES_ENABLED` true. * Enable building XCFramework with Hermes * Embed Hermes XCFramework in Gutenberg XCFramework This is so that, at runtime, apps can find it. Otherwise, the build will run but the app will fail at runtime with: ``` dyld[99988]: Library not loaded: @rpath/hermes.framework/hermes Referenced from: <931F58EC-3AC7-39DE-BEB7-1D44D8A5CF15> /Users/gio/Library/Developer/CoreSimulator/Devices/90F54127-B854-4ED8-93FA-D58167331941/data/Containers/Bundle/Application/3DA26EC7-B308-4029-9974-426839535542/WordPress.app/Frameworks/Gutenberg.framework/Gutenberg ``` * Prevent XCFramework build script from deleting RN-code-generated files * Update Gutenberg ref * Set `REACT_NATIVE_NODE_MODULES_DIR` env var before fetching Reanimated pod * Update `Podfile.lock` file * Add `.xcode.env` file with dynamic node binary path --------- Co-authored-by: Siobhan <[email protected]> Co-authored-by: Carlos Garcia <[email protected]>
- Loading branch information