From 7a4ae799b8a385a1db6171ea573d9705aeec4699 Mon Sep 17 00:00:00 2001 From: louiszawadzki Date: Fri, 30 Jun 2023 03:07:59 -0700 Subject: [PATCH] Fix pod install for swift libs using new arch (#38121) Summary: This fixes a bug that started with React Native 0.72.0 when using the new architecture and installing a native lib that has Swift code (in my case, `datadog/mobile-react-native`). Running `pod install` errors with the following output (`DatadogSDKReactNative` is the pod containing the Swift code): ``` [...] Analyzing dependencies Downloading dependencies Installing DatadogSDKReactNative 1.8.0-rc0 [!] The following Swift pods cannot yet be integrated as static libraries: The Swift pod `DatadogSDKReactNative` depends upon `React-Fabric`, `React-graphics`, `React-utils`, and `React-debug`, which do not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set `use_modular_headers!` globally in your Podfile, or specify `:modular_headers => true` for particular dependencies. ``` Indeed, this pods were added as dependencies in `packages/react-native/scripts/cocoapods/new_architecture.rb` but do not define modules contrary to the other pods in the list. This PR is solving a problem that already occured in the past and was solved here: https://github.com/facebook/react-native/pull/33743 It's a new implementation for the PR initially opened here: https://github.com/facebook/react-native/pull/38039 ## Changelog: [IOS] [FIXED] - Fix pod install for libraries using Swift code when the new architecture is enabled Pull Request resolved: https://github.com/facebook/react-native/pull/38121 Test Plan: 1. Clone [this](https://github.com/louiszawadzki/react-native) repo 2. From `main`, add a Swift file to the `MyNativeView` native module in the RN tester app (see inspiration from [this commit](https://github.com/fortmarek/react-native/commit/26958fccf4b4ac90d0bf9bb3699f12760a6b2b58)) 3. Try to run `RCT_NEW_ARCH_ENABLED=1 USE_HERMES=0 bundle exec pod install` inside the `packages/rn-tester` 4. Observe errors 5. Apply [the commit](https://github.com/facebook/react-native/commit/7b7c3ff530cae07daccc5b5ea6b72d239f913be0) from this PR 6. Both pod install and the subsequent build should succeed. 7. Revert the changes and repeat steps 2 to 6 with `RCT_NEW_ARCH_ENABLED=1 USE_HERMES=1 bundle exec pod install` Reviewed By: cortinico Differential Revision: D47127854 Pulled By: cipolleschi fbshipit-source-id: bf7f65e0d126195a76a0fafbe2f3172f00d5adc1 # Conflicts: # packages/react-native/ReactCommon/react/renderer/debug/React-rendererdebug.podspec --- packages/react-native/ReactCommon/React-Fabric.podspec | 3 ++- packages/react-native/ReactCommon/jsi/React-jsi.podspec | 3 ++- .../ReactCommon/react/debug/React-debug.podspec | 3 ++- .../react/renderer/graphics/React-graphics.podspec | 4 +++- .../ReactCommon/react/utils/React-utils.podspec | 6 +++--- packages/react-native/scripts/react_native_pods.rb | 2 +- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/react-native/ReactCommon/React-Fabric.podspec b/packages/react-native/ReactCommon/React-Fabric.podspec index 0644c97ba22b5c..f6a9217ff62e12 100644 --- a/packages/react-native/ReactCommon/React-Fabric.podspec +++ b/packages/react-native/ReactCommon/React-Fabric.podspec @@ -33,7 +33,8 @@ Pod::Spec.new do |s| s.source = source s.source_files = "dummyFile.cpp" s.pod_target_xcconfig = { "USE_HEADERMAP" => "YES", - "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" } + "CLANG_CXX_LANGUAGE_STANDARD" => "c++17", + "DEFINES_MODULE" => "YES" } if ENV['USE_FRAMEWORKS'] s.header_mappings_dir = './' diff --git a/packages/react-native/ReactCommon/jsi/React-jsi.podspec b/packages/react-native/ReactCommon/jsi/React-jsi.podspec index e7c49d2f133cc9..d46aca1ed27f31 100644 --- a/packages/react-native/ReactCommon/jsi/React-jsi.podspec +++ b/packages/react-native/ReactCommon/jsi/React-jsi.podspec @@ -36,7 +36,8 @@ Pod::Spec.new do |s| s.header_dir = "jsi" s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags - s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/RCT-Folly\" \"$(PODS_ROOT)/DoubleConversion\"" } + s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/RCT-Folly\" \"$(PODS_ROOT)/DoubleConversion\"", + "DEFINES_MODULE" => "YES" } s.dependency "boost", "1.76.0" s.dependency "DoubleConversion" diff --git a/packages/react-native/ReactCommon/react/debug/React-debug.podspec b/packages/react-native/ReactCommon/react/debug/React-debug.podspec index dab4a31652edfa..7c2d0d65ae64f1 100644 --- a/packages/react-native/ReactCommon/react/debug/React-debug.podspec +++ b/packages/react-native/ReactCommon/react/debug/React-debug.podspec @@ -27,7 +27,8 @@ Pod::Spec.new do |s| s.source = source s.source_files = "**/*.{cpp,h}" s.header_dir = "react/debug" - s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" } + s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++17", + "DEFINES_MODULE" => "YES" } if ENV['USE_FRAMEWORKS'] s.module_name = "React_debug" diff --git a/packages/react-native/ReactCommon/react/renderer/graphics/React-graphics.podspec b/packages/react-native/ReactCommon/react/renderer/graphics/React-graphics.podspec index 19cc4ea84a7acf..193f0217d8dc9d 100644 --- a/packages/react-native/ReactCommon/react/renderer/graphics/React-graphics.podspec +++ b/packages/react-native/ReactCommon/react/renderer/graphics/React-graphics.podspec @@ -49,7 +49,9 @@ Pod::Spec.new do |s| header_search_paths = header_search_paths + ["\"$(PODS_TARGET_SRCROOT)/platform/ios\""] end - s.pod_target_xcconfig = { "USE_HEADERMAP" => "NO", "HEADER_SEARCH_PATHS" => header_search_paths.join(" ") } + s.pod_target_xcconfig = { "USE_HEADERMAP" => "NO", + "HEADER_SEARCH_PATHS" => header_search_paths.join(" "), + "DEFINES_MODULE" => "YES" } s.dependency "glog" s.dependency "RCT-Folly/Fabric", folly_version diff --git a/packages/react-native/ReactCommon/react/utils/React-utils.podspec b/packages/react-native/ReactCommon/react/utils/React-utils.podspec index d262c559241052..795be868379d61 100644 --- a/packages/react-native/ReactCommon/react/utils/React-utils.podspec +++ b/packages/react-native/ReactCommon/react/utils/React-utils.podspec @@ -42,9 +42,9 @@ Pod::Spec.new do |s| s.compiler_flags = folly_compiler_flags s.header_dir = "react/utils" s.exclude_files = "tests" - s.pod_target_xcconfig = { - "CLANG_CXX_LANGUAGE_STANDARD" => "c++17", - "HEADER_SEARCH_PATHS" => header_search_paths.join(' ')} + s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++17", + "HEADER_SEARCH_PATHS" => header_search_paths.join(' '), + "DEFINES_MODULE" => "YES" } if ENV['USE_FRAMEWORKS'] s.module_name = "React_utils" diff --git a/packages/react-native/scripts/react_native_pods.rb b/packages/react-native/scripts/react_native_pods.rb index 653385ed12eaeb..dced66e38f20dc 100644 --- a/packages/react-native/scripts/react_native_pods.rb +++ b/packages/react-native/scripts/react_native_pods.rb @@ -139,7 +139,7 @@ def use_react_native! ( pod 'Yoga', :path => "#{prefix}/ReactCommon/yoga", :modular_headers => true pod 'DoubleConversion', :podspec => "#{prefix}/third-party-podspecs/DoubleConversion.podspec" - pod 'glog', :podspec => "#{prefix}/third-party-podspecs/glog.podspec" + pod 'glog', :podspec => "#{prefix}/third-party-podspecs/glog.podspec", :modular_headers => true pod 'boost', :podspec => "#{prefix}/third-party-podspecs/boost.podspec" pod 'RCT-Folly', :podspec => "#{prefix}/third-party-podspecs/RCT-Folly.podspec", :modular_headers => true