Skip to content

Commit a4a0655

Browse files
louiszawadzkifacebook-github-bot
louiszawadzki
authored andcommitted
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: #33743 It's a new implementation for the PR initially opened here: #38039 ## Changelog: [IOS] [FIXED] - Fix pod install for libraries using Swift code when the new architecture is enabled Pull Request resolved: #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](fortmarek@26958fc)) 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](7b7c3ff) 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
1 parent 80a2b8e commit a4a0655

File tree

7 files changed

+16
-9
lines changed

7 files changed

+16
-9
lines changed

packages/react-native/ReactCommon/React-Fabric.podspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ Pod::Spec.new do |s|
3333
s.source = source
3434
s.source_files = "dummyFile.cpp"
3535
s.pod_target_xcconfig = { "USE_HEADERMAP" => "YES",
36-
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17" }
36+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
37+
"DEFINES_MODULE" => "YES" }
3738

3839
if ENV['USE_FRAMEWORKS']
3940
s.header_mappings_dir = './'

packages/react-native/ReactCommon/jsi/React-jsi.podspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ Pod::Spec.new do |s|
3636

3737
s.header_dir = "jsi"
3838
s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags
39-
s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/RCT-Folly\" \"$(PODS_ROOT)/DoubleConversion\"" }
39+
s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/RCT-Folly\" \"$(PODS_ROOT)/DoubleConversion\"",
40+
"DEFINES_MODULE" => "YES" }
4041

4142
s.dependency "boost", "1.76.0"
4243
s.dependency "DoubleConversion"

packages/react-native/ReactCommon/react/debug/React-debug.podspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ Pod::Spec.new do |s|
2727
s.source = source
2828
s.source_files = "**/*.{cpp,h}"
2929
s.header_dir = "react/debug"
30-
s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" }
30+
s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
31+
"DEFINES_MODULE" => "YES" }
3132

3233
if ENV['USE_FRAMEWORKS']
3334
s.module_name = "React_debug"

packages/react-native/ReactCommon/react/renderer/debug/React-rendererdebug.podspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ Pod::Spec.new do |s|
4545
s.exclude_files = "tests"
4646
s.pod_target_xcconfig = {
4747
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
48-
"HEADER_SEARCH_PATHS" => header_search_paths.join(' ')}
48+
"HEADER_SEARCH_PATHS" => header_search_paths.join(' '),
49+
"DEFINES_MODULE" => "YES"
50+
}
4951

5052
if ENV['USE_FRAMEWORKS']
5153
s.module_name = "React_rendererdebug"

packages/react-native/ReactCommon/react/renderer/graphics/React-graphics.podspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ Pod::Spec.new do |s|
4949
header_search_paths = header_search_paths + ["\"$(PODS_TARGET_SRCROOT)/platform/ios\""]
5050
end
5151

52-
s.pod_target_xcconfig = { "USE_HEADERMAP" => "NO", "HEADER_SEARCH_PATHS" => header_search_paths.join(" ") }
52+
s.pod_target_xcconfig = { "USE_HEADERMAP" => "NO",
53+
"HEADER_SEARCH_PATHS" => header_search_paths.join(" "),
54+
"DEFINES_MODULE" => "YES" }
5355

5456
s.dependency "glog"
5557
s.dependency "RCT-Folly/Fabric", folly_version

packages/react-native/ReactCommon/react/utils/React-utils.podspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ Pod::Spec.new do |s|
4242
s.compiler_flags = folly_compiler_flags
4343
s.header_dir = "react/utils"
4444
s.exclude_files = "tests"
45-
s.pod_target_xcconfig = {
46-
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
47-
"HEADER_SEARCH_PATHS" => header_search_paths.join(' ')}
45+
s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
46+
"HEADER_SEARCH_PATHS" => header_search_paths.join(' '),
47+
"DEFINES_MODULE" => "YES" }
4848

4949
if ENV['USE_FRAMEWORKS']
5050
s.module_name = "React_utils"

packages/react-native/scripts/react_native_pods.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def use_react_native! (
139139
pod 'Yoga', :path => "#{prefix}/ReactCommon/yoga", :modular_headers => true
140140

141141
pod 'DoubleConversion', :podspec => "#{prefix}/third-party-podspecs/DoubleConversion.podspec"
142-
pod 'glog', :podspec => "#{prefix}/third-party-podspecs/glog.podspec"
142+
pod 'glog', :podspec => "#{prefix}/third-party-podspecs/glog.podspec", :modular_headers => true
143143
pod 'boost', :podspec => "#{prefix}/third-party-podspecs/boost.podspec"
144144
pod 'RCT-Folly', :podspec => "#{prefix}/third-party-podspecs/RCT-Folly.podspec", :modular_headers => true
145145

0 commit comments

Comments
 (0)