Skip to content

Commit

Permalink
Allow ReactCommon/Folly to be used in Swift libraries (DEFINES_MODULE) (
Browse files Browse the repository at this point in the history
#43327)

Summary:
Pull Request resolved: #43327

<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please provide enough information so that others can review your pull request. The three fields below are mandatory. -->

## Summary

Swift Pods require the use of [modular headers](https://blog.cocoapods.org/CocoaPods-1.5.0/) to be statically linked. To interop with Objective-C modules, you need to make the Objective-C module "define a Module", that is modular header export.

This is already the case for a few podspecs so they can be consumed in Swift libraries, but `ReactCommon` and `RCT-Folly` don't do this yet and therefore this breaks in a few libraries of mine, for example see this issue: mrousavy/react-native-vision-camera#195.

If I were to include `ReactCommon` or `RCT-Folly` in my Swift library's podspec, the following error arises:

```
[!] The following Swift pods cannot yet be integrated as static libraries:

The Swift pod `VisionCamera` depends upon `RCT-Folly`, which does 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.
```

So this PR fixes this issue by allowing Swift libraries to consume the `ReactCommon` and `RCT-Folly` podspecs since they now export modular headers.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[General] [Fixed] - Expose Modular Headers for `ReactCommon` podspec
[General] [Fixed] - Expose Modular Headers for `RCT-Folly` podspec

Pull Request resolved: #31858

Test Plan: * Add s.dependency "ReactCommon" or RCT-Folly to a Swift pod and see what happens. (See mrousavy/react-native-vision-camera#273)

Reviewed By: dmytrorykun

Differential Revision: D54539127

Pulled By: cipolleschi

fbshipit-source-id: 2291cc0c8d6675521b220b02ef0c3c6a3e73be38
  • Loading branch information
mrousavy authored and facebook-github-bot committed Mar 5, 2024
1 parent cdb2ff9 commit 8769245
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/react-native/ReactCommon/ReactCommon.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Pod::Spec.new do |s|
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\" \"$(PODS_ROOT)/fmt/include\" \"$(PODS_ROOT)/Headers/Private/React-Core\"",
"USE_HEADERMAP" => "YES",
"DEFINES_MODULE" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
"GCC_WARN_PEDANTIC" => "YES" }
if ENV['USE_FRAMEWORKS']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Pod::Spec.new do |spec|
'folly/system/*.h',
spec.libraries = "c++abi" # NOTE Apple-only: Keep c++abi here due to https://github.com/react-native-community/releases/issues/251
spec.pod_target_xcconfig = { "USE_HEADERMAP" => "NO",
"DEFINES_MODULE" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)\" \"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/fmt/include\"",
# In dynamic framework (use_frameworks!) mode, ignore the unused and undefined boost symbols when generating the library.
Expand Down

0 comments on commit 8769245

Please sign in to comment.