Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update XCFramework setup to work with React Native 0.71.11 #5924

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
cfe592e
Update Gutenberg reference
Jun 21, 2023
e7bf780
Update script for generating React-Codegen
Jun 22, 2023
17e4705
Update third-party podspecs to target 0.71.11
Jun 22, 2023
2aca7ac
Update FBReactNativeSpec.podspec.json with hash
Jun 22, 2023
165d681
Apply bundle changes
Jun 22, 2023
9707305
Manually add React-bridging.podspec.json
Jun 22, 2023
30b052f
Revert "Manually add React-bridging.podspec.json"
Jun 23, 2023
c89ef2a
Update list of dependencies in Podfile for iOS
Jun 25, 2023
819d005
Add tag to Hermes podspec to workaround error
Jun 25, 2023
64bf6d7
Update dependency versions in Podfile.lock
Jun 25, 2023
21a4fbe
[Temporary] Add React Native as a dependency
Jun 26, 2023
6d1a1a3
Revert "[Temporary] Add React Native as a dependency"
Jun 26, 2023
76fde7c
Update Gutenberg ref
fluiddot Jun 30, 2023
edf1e8c
Merge branch 'upgrade/react-native-0.71.8' into upgrade/react-native-…
fluiddot Jun 30, 2023
3b9f2cf
Update Gutenberg ref
fluiddot Jun 30, 2023
f0ce4ed
Point RNReanimated to a custom branch to work around 2.17.0 issue
mokagio Jun 27, 2023
6632ac8
Print message during `pod install` about `REACT_NATIVE_NODE_MODULES_DIR`
mokagio Jun 27, 2023
74e82b6
Setup NVM and node modules for RNReanimated in XCFramework CI step
mokagio Jun 27, 2023
5582572
Apply bundle changes
Jun 27, 2023
d065553
Switch to using `use_react_native!` in XCFramework `Podfile`
mokagio Jun 27, 2023
fbd6161
Add React Native `post_install` hook
mokagio Jun 27, 2023
c7e2dd1
Use `.xcode.env` instead of `.xcode.env.local`
mokagio Jun 28, 2023
8f74c77
Bump XCFramework deployment target to iOS 15.0
mokagio Jun 28, 2023
28afd7f
Use Xcode 14.3.1 in CI, like WordPress iOS does
mokagio Jun 28, 2023
5919506
Disable Hermes when building XCFramework
mokagio Jun 28, 2023
1d6fd0a
Refine messaging when setting `REACT_NATIVE_NODE_MODULES_DIR` env var
mokagio Jun 29, 2023
e3326ab
Set `SKIP_INSTALL = NO` at the `xcconfig` level, too
mokagio Jun 29, 2023
df511f2
Switch an `unless !=` to `if ==`
mokagio Jun 29, 2023
f2d999d
Add workaround to setup Hermes correctly in XCFramework
mokagio Jun 29, 2023
00052f5
Enable building XCFramework with Hermes
mokagio Jun 29, 2023
b275a9d
Embed Hermes XCFramework in Gutenberg XCFramework
mokagio Jul 3, 2023
ec0c7fa
Prevent XCFramework build script from deleting RN-code-generated files
mokagio Jul 4, 2023
17eae86
Merge branch 'upgrade/react-native-0.71.8' into mokagio/support-rn-0.…
fluiddot Jul 4, 2023
3bbb8b7
Update Gutenberg ref
fluiddot Jul 4, 2023
630b737
Set `REACT_NATIVE_NODE_MODULES_DIR` env var before fetching Reanimate…
fluiddot Jul 5, 2023
73249ba
Update `Podfile.lock` file
fluiddot Jul 5, 2023
bdd6ab1
Add `.xcode.env` file with dynamic node binary path
fluiddot Jul 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ steps:
agents:
queue: mac
env:
IMAGE_ID: xcode-14.3
IMAGE_ID: xcode-14.3.1
15 changes: 15 additions & 0 deletions .buildkite/publish-react-native-ios-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
echo "--- :arrow_down: Download iOS JS bundle"
buildkite-agent artifact download bundle/ios/App.js .

echo '--- :node: Setup node_modules for RNReanimated'
echo '--- :node: 1. Install nvm'
brew install nvm

echo '--- :node: 2. Load nvm in the current shell'
export NVM_DIR="$HOME/.nvm"
mkdir -p "$NVM_DIR"
[ -s "$HOMEBREW_PREFIX/opt/nvm/nvm.sh" ] && \. "$HOMEBREW_PREFIX/opt/nvm/nvm.sh" --install

echo '--- :node: 3. Install node version from .nvmrc'
nvm install "$(cat .nvmrc)" && nvm use

echo '--- :node: 4. nmp ci'
npm ci

echo "--- :rubygems: Setting up Gems"
cd ./ios-xcframework

Expand Down
4 changes: 4 additions & 0 deletions ios-xcframework/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ fastlane/report.xml

# XCFramework build process intermediate and output artifacts
build

# This file takes precedence over .xcode.env.
# Developers can use it to set a custom value without having to update .xcode.env after every `pod install`
.xcode.env.local
1 change: 1 addition & 0 deletions ios-xcframework/.xcode.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export NODE_BINARY=$(command -v node)
11 changes: 8 additions & 3 deletions ios-xcframework/Config/Gutenberg-Shared.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ INSTALL_PATH = $(LOCAL_LIBRARY_DIR)/Frameworks
// Code will load on this and later versions of iOS. Framework APIs that are unavailable
// in earlier versions will be weak-linked; your code should check for null function
// pointers or specific system versions before calling newer APIs.
IPHONEOS_DEPLOYMENT_TARGET = 14.0
//
// At the moment, this needs to be the same value as what's used by the consumer (Jetpack and WordPress iOS)
// See https://github.com/wordpress-mobile/WordPress-iOS/commit/eadad98d81c8970144707d8967f8c9f06a6ada38#commitcomment-119894859
IPHONEOS_DEPLOYMENT_TARGET = 15.0
LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/Frameworks @loader_path/Frameworks
// Marketing Version
//
Expand All @@ -78,7 +81,6 @@ MTL_FAST_MATH = YES
PRODUCT_BUNDLE_IDENTIFIER = org.wordpress.Gutenberg
PRODUCT_NAME = $(TARGET_NAME:c99extidentifier)
SDKROOT = iphoneos
SKIP_INSTALL = YES
SWIFT_EMIT_LOC_STRINGS = YES
// Swift Language Version
//
Expand All @@ -87,12 +89,15 @@ SWIFT_VERSION = 5.0
TARGETED_DEVICE_FAMILY = 1,2
VERSION_INFO_PREFIX =
VERSIONING_SYSTEM = apple-generic
// This should be unnecessary because the script that builds the project should set it.
// These should be unnecessary because the script that builds the project should set it.
//
// But I'm getting the following error after switching from Xcode 14.3 to 14.3.1:
//
// > Failed to build module 'Gutenberg'; this SDK is not supported by the compiler
// > (the SDK is built with 'Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)',
// > while this compiler is 'Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)').
// > Please select a toolchain which matches the SDK.
//
// See also https://github.com/facebook/facebook-ios-sdk/issues/2180#issuecomment-1485846511
BUILD_LIBRARY_FOR_DISTRIBUTION = YES
SKIP_INSTALL = NO
99 changes: 62 additions & 37 deletions ios-xcframework/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,25 @@

require 'xcodeproj'

REACT_NATIVE_PATH = '../gutenberg/node_modules/react-native'
require_relative File.join(REACT_NATIVE_PATH, 'scripts', 'react_native_pods')

# We are still trying to decide whether to adopt Hermes or not.
#
# This switch allows us to switch between approaches on the go.
HERMES_ENABLED = ENV.fetch('HERMES_ENABLED', true)
Comment on lines +8 to +11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could leave this open until we confirm that Hermes works as expected on iOS through testing.


puts "[Gutenberg] Installing pods with Hermes #{HERMES_ENABLED ? 'enabled' : 'disabled'}"

# Note that the pods in this array might seem unused if you look for
# `import` statements in this codebase. However, make sure to also check
# whether they are used in the gutenberg-mobile and Gutenberg projects.
#
# Also notice that these are not all the dependencies the project uses.
# Later in the config, we call use_react_native! which fetches more.
#
# See https://github.com/wordpress-mobile/gutenberg-mobile/issues/5025
DEPENDENCIES = %w[
FBLazyVector
React
ReactCommon
RCTRequired
RCTTypeSafety
React-Core
React-CoreModules
React-RCTActionSheet
React-RCTAnimation
React-RCTBlob
React-RCTImage
React-RCTLinking
React-RCTNetwork
React-RCTSettings
React-RCTText
React-RCTVibration
React-callinvoker
React-cxxreact
React-jsinspector
React-jsi
React-jsiexecutor
React-logger
React-perflogger
React-runtimeexecutor
boost
Yoga
RCT-Folly
glog
react-native-safe-area
react-native-safe-area-context
react-native-video
Expand All @@ -51,21 +36,31 @@ DEPENDENCIES = %w[
RNCMaskedView
RNCClipboard
RNFastImage
React-Codegen
React-jsc
React-hermes
].freeze

def gutenberg_dependencies
podspec_prefix = '..'

# FBReactNativeSpec needs special treatment because of react-native-codegen code generation
pod 'FBReactNativeSpec',
podspec: "#{podspec_prefix}/third-party-podspecs/FBReactNativeSpec/FBReactNativeSpec.podspec.json"
computed_dependencies = DEPENDENCIES.dup

# Use a custom RNReanimated version while we coordinate a fix upstream
computed_dependencies.delete('RNReanimated')

DEPENDENCIES.each do |pod_name|
computed_dependencies.delete('React-jsc') unless HERMES_ENABLED

computed_dependencies.each do |pod_name|
pod pod_name, podspec: "#{podspec_prefix}/third-party-podspecs/#{pod_name}.podspec.json"
end

# This is required to workaround an issue with RNReanimated after upgrading to version 2.17.0
rn_node_modules = File.join(Dir.pwd, '..', 'gutenberg', 'node_modules')
raise "Could not find node modules at given path #{rn_node_modules}" unless File.exist? rn_node_modules
ENV['REACT_NATIVE_NODE_MODULES_DIR'] = rn_node_modules
puts "[Gutenberg] Set REACT_NATIVE_NODE_MODULES_DIR env var for RNReanimated to #{rn_node_modules}"

# Use a custom RNReanimated version while we coordinate a fix upstream
pod 'RNReanimated', git: 'https://github.com/wordpress-mobile/react-native-reanimated', branch: 'wp-fork-2.17.0'
end

VERSION_XCCONFIG_PATH = File.join(File.expand_path(__dir__), 'Config', 'Gutenberg-Shared.xcconfig')
Expand All @@ -74,21 +69,51 @@ APP_IOS_DEPLOYMENT_TARGET = Gem::Version.new(Xcodeproj::Config.new(VERSION_XCCON

platform :ios, APP_IOS_DEPLOYMENT_TARGET.version

target 'Gutenberg' do
use_frameworks! linkage: :static
# It's important to call use_frameworks! before use_react_native!
#
# See https://github.com/facebook/react-native/issues/36120#issuecomment-1425892304
use_frameworks! linkage: :static
use_react_native! path: REACT_NATIVE_PATH, hermes_enabled: HERMES_ENABLED

target 'Gutenberg' do
pod 'RNTAztecView', path: '..'
gutenberg_dependencies
end

post_install do |installer|
react_native_post_install(installer, REACT_NATIVE_PATH)

installer.pods_project.targets.each do |target|
# Work around issue with embedding the Hermes XCFramework
#
# See https://github.com/facebook/react-native/issues/35863
if HERMES_ENABLED && target.name == 'hermes-engine'
installer.pods_project.files.each do |fileref|
next unless fileref.path.end_with? 'hermes.xcframework'

plist_buddy = '/usr/libexec/PlistBuddy'

raise "[Gutenberg] Could not find PlistBuddy at #{plist_buddy}." unless File.exist?(plist_buddy)

hermes_plist_file = "#{fileref.real_path}/Info.plist"

# Patch Hermes to remove the debug symbols entry from the Info.plist (as it's not shipped with it)
# This might be removed once Hermes starts to ship with Debug symbols or we remove our
# direct dependency from the Main iOS target on "hermes.xcframework"
Open3.capture3(plist_buddy, '-c', 'Delete :AvailableLibraries:0:DebugSymbolsPath', hermes_plist_file)
Open3.capture3(plist_buddy, '-c', 'Delete :AvailableLibraries:1:DebugSymbolsPath', hermes_plist_file)
Open3.capture3(plist_buddy, '-c', 'Delete :AvailableLibraries:2:DebugSymbolsPath', hermes_plist_file)

puts '[Gutenberg] Removed Hermes dSYMs references from its XCFramework'
end
end

# Let Pods targets inherit deployment target from the app
# See https://github.com/CocoaPods/CocoaPods/issues/4859
#
# Exclude RCT-Folly as it requires explicit deployment target
# See https://git.io/JPb73
next unless target.name != 'RCT-Folly'
next if target.name == 'RCT-Folly'

target.build_configurations.each do |configuration|
pod_ios_deployment_target = Gem::Version.new(configuration.build_settings[IOS_VERSION_KEY])
Expand Down