Skip to content

fix(worklets): compilation on iOS #7045

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

Merged
merged 9 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/example-android-build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ jobs:
run: yarn build

- name: Use external worklets
if: ${{ inputs.use-external-worklets == 'true' }}
if: ${{ inputs.use-external-worklets }}
working-directory: ${{ env.COMMON_APP_DIR }}
run: yarn add react-native-worklets@workspace:"*"
- name: Use external worklets
if: ${{ inputs.use-external-worklets }}
working-directory: ${{ env.WORKING_DIRECTORY }}
run: yarn add react-native-worklets@workspace:"*"

- name: Build app
working-directory: ${{ env.WORKING_DIRECTORY }}/android
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/example-ios-build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,20 @@ jobs:
run: yarn build

- name: Use external worklets
if: ${{ inputs.use-external-worklets == 'true' }}
if: ${{ inputs.use-external-worklets }}
working-directory: ${{ env.COMMON_APP_DIR }}
run: yarn add react-native-worklets@workspace:"*"
- name: Use external worklets
if: ${{ inputs.use-external-worklets }}
working-directory: ${{ env.WORKING_DIRECTORY }}
run: yarn add react-native-worklets@workspace:"*"

# TODO: Add caching for node_modules and artifacts that will work with monorepo setup.
- name: Install Pods
working-directory: ${{ env.WORKING_DIRECTORY }}/ios
run: |
bundle install
bundle exec pod install
bundle exec pod update

- name: Build app
working-directory: ${{ env.WORKING_DIRECTORY }}
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/example-macos-build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,19 @@ jobs:
run: yarn build

- name: Use external worklets
if: ${{ inputs.use-external-worklets == 'true' }}
if: ${{ inputs.use-external-worklets }}
working-directory: ${{ env.COMMON_APP_DIR }}
run: yarn add react-native-worklets@workspace:"*"
- name: Use external worklets
if: ${{ inputs.use-external-worklets }}
working-directory: ${{ env.WORKING_DIRECTORY }}
run: yarn add react-native-worklets@workspace:"*"

- name: Install Pods
working-directory: ${{ env.WORKING_DIRECTORY }}/macos
run: |
bundle install
bundle exec pod install
bundle exec pod update

- name: Build app
working-directory: ${{ env.WORKING_DIRECTORY }}
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/example-tvos-build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,19 @@ jobs:
run: yarn build

- name: Use external worklets
if: ${{ inputs.use-external-worklets == 'true' }}
if: ${{ inputs.use-external-worklets }}
working-directory: ${{ env.COMMON_APP_DIR }}
run: yarn add react-native-worklets@workspace:"*"
- name: Use external worklets
if: ${{ inputs.use-external-worklets }}
working-directory: ${{ env.WORKING_DIRECTORY }}
run: yarn add react-native-worklets@workspace:"*"

- name: Install Pods
working-directory: ${{ env.WORKING_DIRECTORY }}/ios
run: |
bundle install
bundle exec pod install
bundle exec pod update

- name: Build app
working-directory: ${{ env.WORKING_DIRECTORY }}/ios
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native-reanimated/RNReanimated.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ Pod::Spec.new do |s|
gcc_debug_definitions << " HERMES_ENABLE_DEBUGGER=1"
end

external_worklets_header_path = $config[:has_external_worklets] ? "\"$(PODS_ROOT)/Headers/Public/RNWorklets\"" : ''

s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"DEFINES_MODULE" => "YES",
Expand All @@ -83,6 +85,7 @@ Pod::Spec.new do |s|
'"$(PODS_ROOT)/DoubleConversion"',
'"$(PODS_ROOT)/Headers/Private/React-Core"',
'"$(PODS_ROOT)/Headers/Private/Yoga"',
external_worklets_header_path,
].join(' '),
"FRAMEWORK_SEARCH_PATHS" => '"${PODS_CONFIGURATION_BUILD_DIR}/React-hermes"',
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
Expand All @@ -98,6 +101,7 @@ Pod::Spec.new do |s|
'"$(PODS_ROOT)/RCT-Folly"',
'"$(PODS_ROOT)/Headers/Public/React-hermes"',
'"$(PODS_ROOT)/Headers/Public/hermes-engine"',
external_worklets_header_path,
"\"$(PODS_ROOT)/#{$config[:react_native_common_dir]}\"",
"\"$(PODS_ROOT)/#{$config[:react_native_reanimated_dir_from_pods_root]}/apple\"",
"\"$(PODS_ROOT)/#{$config[:react_native_reanimated_dir_from_pods_root]}/Common/cpp\"",
Expand Down
20 changes: 18 additions & 2 deletions packages/react-native-worklets/RNWorklets.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
require "json"
require_relative './scripts/worklets_utils'

package = JSON.parse(File.read(File.join(__dir__, "package.json")))
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
$worklets_config = worklets_find_config()
worklets_assert_minimal_react_native_version($worklets_config)

ios_min_version = '13.4'

Pod::Spec.new do |s|
s.name = "RNWorklets"
Expand All @@ -10,7 +14,7 @@ Pod::Spec.new do |s|
s.homepage = "https://github.com/software-mansion/react-native-reanimated"
s.license = package["license"]
s.authors = { "author" => "[email protected]" }
s.platforms = { :ios => min_ios_version_supported }
s.platforms = { :ios => ios_min_version, :tvos => "9.0", :osx => "10.14", :visionos => "1.0" }
s.source = { :git => "https://github.com/software-mansion/react-native-reanimated.git", :tag => "#{s.version}" }

s.source_files = "apple/*.{h,m,mm,cpp}"
Expand Down Expand Up @@ -46,9 +50,21 @@ Pod::Spec.new do |s|
'"$(PODS_ROOT)/DoubleConversion"',
'"$(PODS_ROOT)/Headers/Private/React-Core"',
'"$(PODS_ROOT)/Headers/Private/Yoga"',
"\"$(PODS_ROOT)/#{$worklets_config[:react_native_common_dir]}\"",
].join(' '),
"FRAMEWORK_SEARCH_PATHS" => '"${PODS_CONFIGURATION_BUILD_DIR}/React-hermes"',
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
}
s.xcconfig = {
"HEADER_SEARCH_PATHS" => [
'"$(PODS_ROOT)/boost"',
'"$(PODS_ROOT)/boost-for-react-native"',
'"$(PODS_ROOT)/glog"',
'"$(PODS_ROOT)/RCT-Folly"',
'"$(PODS_ROOT)/Headers/Public/React-hermes"',
'"$(PODS_ROOT)/Headers/Public/hermes-engine"',
"\"$(PODS_ROOT)/#{$worklets_config[:react_native_common_dir]}\"",
].join(' '),
}

end
53 changes: 53 additions & 0 deletions packages/react-native-worklets/scripts/worklets_utils.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
def worklets_try_to_parse_react_native_package_json(node_modules_dir)
react_native_package_json_path = File.join(node_modules_dir, 'react-native/package.json')
if !File.exist?(react_native_package_json_path)
return nil
end
return JSON.parse(File.read(react_native_package_json_path))
end

def worklets_find_config()
result = {
:is_reanimated_example_app => nil,
:react_native_version => nil,
:react_native_minor_version => nil,
:react_native_node_modules_dir => nil,
:react_native_common_dir => nil
}

react_native_node_modules_dir = File.join(File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native/package.json')"`), '..')
react_native_json = worklets_try_to_parse_react_native_package_json(react_native_node_modules_dir)

if react_native_json == nil
# user configuration, just in case
node_modules_dir = ENV["REACT_NATIVE_NODE_MODULES_DIR"]
react_native_json = worklets_try_to_parse_react_native_package_json(node_modules_dir)
end

if react_native_json == nil
raise '[Worklets] Unable to recognize your `react-native` version. Please set environmental variable with `react-native` location: `export REACT_NATIVE_NODE_MODULES_DIR="<path to react-native>" && pod install`.'
end

result[:is_reanimated_example_app] = ENV["REANIMATED_EXAMPLE_APP_NAME"] != nil
result[:react_native_version] = react_native_json['version']
result[:react_native_minor_version] = react_native_json['version'].split('.')[1].to_i
if result[:react_native_minor_version] == 0 # nightly
result[:react_native_minor_version] = 1000
end
result[:react_native_node_modules_dir] = File.expand_path(react_native_node_modules_dir)

pods_root = Pod::Config.instance.project_pods_root
react_native_common_dir_absolute = File.join(react_native_node_modules_dir, 'react-native', 'ReactCommon')
react_native_common_dir_relative = Pathname.new(react_native_common_dir_absolute).relative_path_from(pods_root).to_s
result[:react_native_common_dir] = react_native_common_dir_relative

return result
end

def worklets_assert_minimal_react_native_version(config)
# If you change the minimal React Native version remember to update Compatibility Table in docs
minimalReactNativeVersion = 75
if config[:react_native_minor_version] < minimalReactNativeVersion
raise "[Worklets] Unsupported React Native version. Please use #{minimalReactNativeVersion} or newer."
end
end
Loading