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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 'folly/Optional.h' file not found on Xcode version 12.5 #195

Closed
1 task
vsyw opened this issue Jun 10, 2021 · 11 comments 路 Fixed by #273
Closed
1 task

馃悰 'folly/Optional.h' file not found on Xcode version 12.5 #195

vsyw opened this issue Jun 10, 2021 · 11 comments 路 Fixed by #273
Labels
馃悰 bug Something isn't working

Comments

@vsyw
Copy link

vsyw commented Jun 10, 2021

What

Can't run on Xcode v12.5, it shows 'folly/Optional.h' file not found.
Not sure if it's related to facebook/flipper#2215

Logs

Screen Shot 2021-06-11 at 12 00 33 AM

Reproducable sample

  1. Create a new react native project
  2. Install react-native-vision-camera
  3. Build and run on Xcode v12.5

Environment

  • Platform(s):
    • [V] iOS
    • Android
  • react-native version: 0.63.4
  • react-native-vision-camera version: 2.3.0
  • react-native-reanimated version: N/A
@vsyw vsyw added the 馃悰 bug Something isn't working label Jun 10, 2021
@mrousavy
Copy link
Owner

This might be related to the following line: https://github.com/cuvent/react-native-vision-camera/blob/26cf21ff5f79d98c37b80e4e488ae01d02248448/VisionCamera.podspec#L46

could you try removing it, running pod install, and then seeing if that fixes it for you? There might be some additional imports missing which you have to the Podfile, for example React-callinvoker.

@LupulescuAlexandru
Copy link

LupulescuAlexandru commented Jun 12, 2021

I have the same problem as OP and after removing that line and running pod install I got this error:
image
I also followed the troubleshooting steps in the documentation.

My Podfile:

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '11.0'

target 'Project' do
  config = use_native_modules!  
  use_react_native!(:path => config["reactNativePath"])
  target 'ProjectTests' do
    inherit! :complete
    # Pods for testing
  end
  permissions_path = '../node_modules/react-native-permissions/ios'
  pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
  pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary"
  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable these next few lines.
#  use_flipper!({ 'Flipper-Folly' => '2.3.0' })
#  post_install do |installer|
#    flipper_post_install(installer)
#  end
end

target 'Project-tvOS' do

  target 'Project-tvOSTests' do
    inherit! :search_paths
    # Pods for testing
  end
end

@mrousavy
Copy link
Owner

mrousavy commented Jul 9, 2021

You could try editing node_modules/react-native-vision-camera/VisionCamera.podspec, and make the following change:

-  s.dependency "React"
+  s.dependency 'ReactCommon/turbomodule/core'
+  s.dependency 'Folly'

then in your own Podfile add

use_modular_headers!

to the top. Here's an example podspec that should work. Let me know if that fixes the issue for you because I cannot reproduce it.

@axeldelafosse
Copy link

I was able to make it work but I had to set "DEFINES_MODULE" => "YES" in ReactCommon.podspec and Folly.podspec

react-native-vision-camera+2.4.2-beta.9.patch

diff --git a/node_modules/react-native-vision-camera/VisionCamera.podspec b/node_modules/react-native-vision-camera/VisionCamera.podspec
index 8cfe1c6..6cddd88 100644
--- a/node_modules/react-native-vision-camera/VisionCamera.podspec
+++ b/node_modules/react-native-vision-camera/VisionCamera.podspec
@@ -2,6 +2,11 @@ require "json"
 
 package = JSON.parse(File.read(File.join(__dir__, "package.json")))
 
+folly_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1'
+folly_compiler_flags = folly_flags + ' ' + '-Wno-comma -Wno-shorten-64-to-32'
+folly_version = '2020.01.13.00'
+boost_compiler_flags = '-Wno-documentation'
+
 Pod::Spec.new do |s|
   s.name         = "VisionCamera"
   s.version      = package["version"]
@@ -19,6 +24,12 @@ Pod::Spec.new do |s|
     "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_TARGET_SRCROOT)\" \"$(PODS_ROOT)/Headers/Private/React-Core\" \"$(PODS_ROOT)/Headers/Public/React-hermes\" \"$(PODS_ROOT)/Headers/Public/hermes-engine\""
   }
   s.requires_arc = true
+  s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags
+  s.xcconfig = {
+    "CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
+    "HEADER_SEARCH_PATHS" => "$(inherited) \"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/glog\" \"$(PODS_ROOT)/Folly\" \"${PODS_ROOT}/Headers/Public/React-hermes\" \"${PODS_ROOT}/Headers/Public/hermes-engine\"",
+    "OTHER_CFLAGS" => "$(inherited)" + " " + folly_flags
+  }
 
   # All source files that should be publicly visible
   # Note how this does not include headers, since those can nameclash.
@@ -43,6 +54,7 @@ Pod::Spec.new do |s|
   ]
 
   s.dependency "React-callinvoker"
-  s.dependency "React"
   s.dependency "React-Core"
+  s.dependency "ReactCommon/turbomodule/core"
+  s.dependency "Folly", folly_version
 end
diff --git a/node_modules/react-native-vision-camera/ios/React Utils/JSIUtils.mm b/node_modules/react-native-vision-camera/ios/React Utils/JSIUtils.mm
index ccd0476..2c64c69 100644
--- a/node_modules/react-native-vision-camera/ios/React Utils/JSIUtils.mm	
+++ b/node_modules/react-native-vision-camera/ios/React Utils/JSIUtils.mm	
@@ -191,7 +191,7 @@ RCTResponseSenderBlock convertJSIFunctionToCallback(jsi::Runtime &runtime, const
     wrapperWasCalled = YES;
   };
 
-  if (RCTTurboModuleBlockCopyEnabled()) {
+  if (RCTTurboModuleEnabled()) {
     return [callback copy];
   }
 

react-native+0.63.4.patch

diff --git a/node_modules/react-native/ReactCommon/ReactCommon.podspec b/node_modules/react-native/ReactCommon/ReactCommon.podspec
index 765ec10..9499ba0 100644
--- a/node_modules/react-native/ReactCommon/ReactCommon.podspec
+++ b/node_modules/react-native/ReactCommon/ReactCommon.podspec
@@ -32,7 +32,8 @@ Pod::Spec.new do |s|
   s.source                 = source
   s.header_dir             = "ReactCommon" # Use global header_dir for all subspecs for use_frameworks! compatibility
   s.compiler_flags         = folly_compiler_flags + ' ' + boost_compiler_flags
-  s.pod_target_xcconfig    = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/Folly\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/Headers/Private/React-Core\"",
+  s.pod_target_xcconfig    = { "DEFINES_MODULE" => "YES",
+                               "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/Folly\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/Headers/Private/React-Core\"",
                                "USE_HEADERMAP" => "YES",
                                "CLANG_CXX_LANGUAGE_STANDARD" => "c++14" }
 
diff --git a/node_modules/react-native/scripts/.packager.env b/node_modules/react-native/scripts/.packager.env
new file mode 100644
index 0000000..361f5fb
--- /dev/null
+++ b/node_modules/react-native/scripts/.packager.env
@@ -0,0 +1 @@
+export RCT_METRO_PORT=8081
diff --git a/node_modules/react-native/third-party-podspecs/Folly.podspec b/node_modules/react-native/third-party-podspecs/Folly.podspec
index 35a0522..8d2706c 100644
--- a/node_modules/react-native/third-party-podspecs/Folly.podspec
+++ b/node_modules/react-native/third-party-podspecs/Folly.podspec
@@ -52,7 +52,8 @@ Pod::Spec.new do |spec|
                         'folly/net/detail/*.h',
                         'folly/portability/*.h'
   spec.libraries           = "stdc++"
-  spec.pod_target_xcconfig = { "USE_HEADERMAP" => "NO",
+  spec.pod_target_xcconfig = { "DEFINES_MODULE" => "YES",
+                               "USE_HEADERMAP" => "NO",
                                "CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
                                "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)\" \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/DoubleConversion\"" }
 

@matheusmatos
Copy link

Playing around solution suggested by @axeldelafosse I was able to build it without touching RN codebase.

To make work with RN 0.63

We need to do two changes in the module. First one in VisionCamera.podspec:

# filename: VisionCamera.podspec

+ folly_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1'
+ folly_compiler_flags = folly_flags + ' ' + '-Wno-comma -Wno-shorten-64-to-32'
+ folly_version = '2020.01.13.00'
+ boost_compiler_flags = '-Wno-documentation'

...

s.requires_arc = true
+ s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags
+ s.xcconfig = {
+   "CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
+   "HEADER_SEARCH_PATHS" => "$(inherited) \"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/glog\" \"$(PODS_ROOT)/Folly\" \"${PODS_ROOT}/Headers/Public/React-hermes\" \"${PODS_ROOT}/Headers/Public/hermes-engine\"",
+   "OTHER_CFLAGS" => "$(inherited)" + " " + folly_flags
+ }

...

- s.dependency "React-callinvoker"
- s.dependency "React"
- s.dependency "React-Core"
+ s.dependency "React-callinvoker"
+ s.dependency "React-Core"
+ s.dependency "ReactCommon/turbomodule/core"
+ s.dependency "Folly", folly_version

Also this simple change in ios/React Utils/JSIUtils.mm:

- if (RCTTurboModuleBlockCopyEnabled()) {
+ if (RCTTurboModuleEnabled()) {

Then in your main Podfile:

- config = use_native_modules!
- use_react_native!(:path => config["reactNativePath"])
+ config = use_native_modules!
+ reactNativePath = config["reactNativePath"] ||= "../node_modules/react-native"
+ use_react_native!(:path => reactNativePath)

...

+ pod 'ReactCommon/turbomodule/core', :path => "#{reactNativePath}/ReactCommon", :modular_headers => true
+ pod 'Folly', :podspec => "#{reactNativePath}/third-party-podspecs/Folly.podspec", :modular_headers => true

P.S: The fixed Folly version is extracted from RN0.63 release notes. I just kept it based on @axeldelafosse suggestion and RNReanimated podscec.

To make work with RN 0.64 using changes above 馃憜馃徎

Basically we just need to change Folly to RCT-Folly:

# filename: VisionCamera.podspec

- "HEADER_SEARCH_PATHS" => "$(inherited) \"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/glog\" \"$(PODS_ROOT)/Folly\" \"${PODS_ROOT}/Headers/Public/React-hermes\" \"${PODS_ROOT}/Headers/Public/hermes-engine\"",
+ "HEADER_SEARCH_PATHS" => "$(inherited) \"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(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\"",

...

- s.dependency "Folly", folly_version
+ s.dependency "RCT-Folly", folly_version

Also in your main Podfile:

- pod 'Folly', :podspec => "#{reactNativePath}/third-party-podspecs/Folly.podspec", :modular_headers => true
+ pod 'RCT-Folly', :podspec => "#{reactNativePath}/third-party-podspecs/RCT-Folly.podspec", :modular_headers => true

馃憠馃徎 ...However I believe that we don't have problem now with 0.64 version. I"ll update the PR #273 to make these changes only in 0.63 version. What you guys think?

PS: I don't understand why we need to switch from Folly to RTC-Folly as I didn't find anything in the release notes. But it works.

To make work with Expo 42 as a Config Plugin in Managed Workflow

Expo 42 uses RN 0.63. Using expo prebuild I tested the solution above and it works. Now we just need to add a mod to the expo-plugin/withVisionCamera to insert these two lines in main Podfile (after updating the RNVisionCamera module) - I"ll open a PR for that.

That's it! If anyone still has problems just share it!

鉁岋笍

@mrousavy
Copy link
Owner

Wow, amazing research @matheusmatos and @axeldelafosse! 馃槻馃ぉ

I'll research a bit more on what those Modular Headers are exactly and if there's any workaround because I can't sleep good at night if we patch the user's Podfile like that (adjusting RN pods), but if not we'll use those changes!

mrousavy added a commit to mrousavy/react-native that referenced this issue Jul 14, 2021
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` doesn't do this yet and therefore breaks in a few libraries of mine, for example see this issue: mrousavy/react-native-vision-camera#195.

If I were to include `ReactCommon` 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` podspec since it now exports modular headers.
@mrousavy
Copy link
Owner

Maybe this fixes things for the future: facebook/react-native#31858

@mrousavy
Copy link
Owner

So as far as I know, Expo 43 will come with React Native 0.64, which fixes all those build issues.
I think I will not merge your change @matheusmatos, so that VisionCamera only works on Expo 43 and above, just for the sake of simplicity (the VisionCamera.podspec would be very messy and users are required to edit their Podfile which is bad DX).
As for non-expo users, most of them are already on RN 0.64 anyways.
Thank you for providing a workaround people can use until then, as well as for your detailed research. 鉁岋笍

@mrousavy
Copy link
Owner

Just found a commit that fixes this issue (I believe) and it made it to RN 0.65! facebook/react-native@8aea930

@pke
Copy link

pke commented Nov 10, 2021

Gosh this is all so fragile in the build process :(

QSuraj added a commit to QSuraj/react-native-vision-camera that referenced this issue Jul 29, 2022
@kranthi1216
Copy link

After updating React Native to 0.73.4, I am seeing the following: 'Pods/Headers/Public/RCT-Folly/folly/Optional'.h:474:36 Binary expression ('const bool' and 'const std::nullopt_t') has invalid operands.can help in resolving.

cipolleschi pushed a commit to cipolleschi/react-native that referenced this issue Mar 5, 2024
facebook#31858)

Summary:
<!-- 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: facebook#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)

Differential Revision: D54539127

Pulled By: cipolleschi
facebook-github-bot pushed a commit to facebook/react-native that referenced this issue Mar 5, 2024
#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
cipolleschi pushed a commit to facebook/react-native that referenced this issue May 1, 2024
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
馃悰 bug Something isn't working
Projects
None yet
7 participants