react-native: Compilation error when hermes enabled: 'fmt/compile.h' file not found

Description

I’m trying to enable hermes on iOS, but when I set :hermes_enabled => true in my Podfile I get the following compilation error:

In file included from /Users/guillermodefermin/taxfix/mobile-app-native-deps/ios/Pods/RCT-Folly/folly/Singleton.cpp:35:
/Users/guillermodefermin/taxfix/mobile-app-native-deps/ios/Pods/RCT-Folly/folly/portability/FmtCompile.h:19:10: fatal error: 
      'fmt/compile.h' file not found
#include <fmt/compile.h>
         ^~~~~~~~~~~~~~~
/Users/guillermodefermin/taxfix/mobile-app-native-deps/ios/Pods/RCT-Folly/folly/portability/FmtCompile.h:19:10: note: 
      did not find header 'compile.h' in framework 'fmt' (loaded from
      '/Users/guillermodefermin/Library/Developer/Xcode/DerivedData/Taxfix/Build/Products/Debug-iphonesimulator/fmt')
1 error generated.

My setup:

  • I’m using use_frameworks! :linkage => :static (one of the pods requires it)
  • I’m not using flipper

The same configuration works with no issues when :hermes_enabled => false

Version

0.66.1

Output of react-native info

info Fetching system and libraries information...
(node:95196) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
System:
    OS: macOS 12.0
    CPU: (8) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
    Memory: 342.60 MB / 16.00 GB
    Shell: 3.1.2 - /usr/local/bin/fish
  Binaries:
    Node: 14.15.5 - ~/.nvm/versions/node/v14.15.5/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v14.15.5/bin/yarn
    npm: 6.14.11 - ~/.nvm/versions/node/v14.15.5/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.2 - /Users/guillermodefermin/.asdf/shims/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 15.0, DriverKit 20.4, macOS 11.3, tvOS 15.0, watchOS 8.0
    Android SDK:
      API Levels: 28, 29, 30
      Build Tools: 28.0.3, 29.0.2, 30.0.2, 31.0.0
      System Images: android-30 | Google APIs Intel x86 Atom, android-30 | Google Play Intel x86 Atom, android-31 | Google APIs Intel x86 Atom_64
      Android NDK: Not Found
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5791312
    Xcode: 13.0/13A233 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_275 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: Not Found
    react-native: 0.66.1 => 0.66.1 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

  • Enable hermes by setting: :hermes_enabled => true
  • Run pod install
  • Build with react-native run-ios or from xcode

Snack, code example, screenshot, or link to a repository

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 22
  • Comments: 34 (9 by maintainers)

Most upvoted comments

@wood1986 you could try this solution:

This should solve the RCT-Folly issue.

use_frameworks! :linkage => :static

This solves the fmt.h file not found issue.

    # https://github.com/facebook/react-native/issues/32451
    installer.pods_project.targets.each do |target|
      if target.name == 'RCT-Folly'
        target.build_configurations.each do |config|
          config.build_settings['HEADER_SEARCH_PATHS'] = "$(inherited) ${PODS_ROOT}/fmt/include"
        end
      end
    end

After adding above code to podfile, run pod install and rebuild your project, it’ll be compiled with success.

Same, not able to use RN:0.67.2 with hermes enabled. This RCT-Folly always had compile issues in past couple year. With below fix in Podfile you can solve this particular issue but then it’ll fail at somewhere else if :hermes_enabled => true. Build with using below will success without hermes.

use_flipper!({ 'Flipper' => '0.131.1', 'Flipper-Folly' => '2.6.10', 'Flipper-RSocket' => '1.4.3', 'Flipper-DoubleConversion' => '3.1.7', 'Flipper-PeerTalk' => '0.0.4', 'OpenSSL-Universal' => '1.1.1100' })

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == 'RCT-Folly'
        target.build_configurations.each do |config|
            config.build_settings['HEADER_SEARCH_PATHS'] = "$(inherited) ${PODS_ROOT}/fmt/include"
        end
    end
  end

  react_native_post_install(installer)
  __apply_Xcode_12_5_M1_post_install_workaround(installer)
end

@Kudo 's fix on RN 0.69 seems to fix the issue, thanks Kudo 👍

Just a heads up that 0.69.0 doesn’t containt this fix. We’ll be including it inside 69.1 potentially

This workaround totally worked for me

https://github.com/facebook/react-native/issues/32451#issuecomment-1028835616

    # https://github.com/facebook/react-native/issues/32451
    installer.pods_project.targets.each do |target|
      if target.name == 'RCT-Folly'
        target.build_configurations.each do |config|
          config.build_settings['HEADER_SEARCH_PATHS'] = "$(inherited) ${PODS_ROOT}/fmt/include"
        end
      end
    end
⬇ In case you want to see entire Podfile (clic to unroll) I don't have Flipper enabled, but `use_framework`.

Here is mypodfile for "react-native": "0.67.4"

source 'https://github.com/CocoaPods/Specs.git'

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'

# To avoid "App Tracking Transparency" requirement for iOS 14.5
# (we don't use IDFA)
$RNFirebaseAnalyticsWithoutAdIdSupport = true
# use_frameworks! compatibility
$RNFirebaseAsStaticFramework = true

target 'TARGET' do
  # for a private dependency, use_frameworks is required
  use_frameworks!
  $static_framework = []

  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => false
  )

  # react-native-permissions
  permissions_path = '../node_modules/react-native-permissions/ios'
  pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse"
  pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications"
  # https://github.com/zoontek/react-native-permissions#workaround-for-use_frameworks-issues
  # pre_install do |installer|
  #   Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}

  #   installer.pod_targets.each do |pod|
  #     if pod.name.eql?('RNPermissions') || pod.name.start_with?('Permission-')
  #       def pod.build_type;
  #         # Uncomment the line corresponding to your CocoaPods version
  #         Pod::BuildType.static_library # >= 1.9
  #         # Pod::Target::BuildType.static_library # < 1.9
  #       end
  #     end
  #   end
  # end
  # we use an array since we have multiple static frameworks
  $static_framework += [
    'RNPermissions',
    'Permission-LocationWhenInUse',
    'Permission-Notifications'
  ]

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable the next line.
  # use_flipper!()
  # # https://fbflipper.com/docs/getting-started/ios-native
  # $static_framework += [
  #   'FlipperKit', 'Flipper', 'Flipper-Folly',
  #   'CocoaAsyncSocket', 'ComponentKit', 'Flipper-DoubleConversion',
  #   'Flipper-Glog', 'Flipper-PeerTalk', 'Flipper-RSocket', 'Yoga', 'YogaKit',
  #   'CocoaLibEvent', 'OpenSSL-Universal', 'boost-for-react-native'
  # ]

  # use_frameworks! workaround
  pre_install do |installer|
    Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
    installer.pod_targets.each do |pod|
      if $static_framework.include?(pod.name)
        def pod.build_type;
          # Uncomment the line corresponding to your CocoaPods version
          Pod::BuildType.static_library # >= 1.9
          # Pod::Target::BuildType.static_library # < 1.9
        end
      end
    end
  end

  post_install do |installer|
    react_native_post_install(installer)
    
    # https://github.com/facebook/react-native/issues/32451
    installer.pods_project.targets.each do |target|
      if target.name == 'RCT-Folly'
        target.build_configurations.each do |config|
          config.build_settings['HEADER_SEARCH_PATHS'] = "$(inherited) ${PODS_ROOT}/fmt/include"
        end
      end
    end
    
    # Apple M1 compatibility (beacuse of BookTicket)
    installer.pods_project.build_configurations.each do |config|
      config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
    end
    
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
    
    # Private deps requirement
    # see also ios/fastlane/Fastfile 'compileBitcode' option for fastlane
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['ENABLE_BITCODE'] = 'NO'
      end
    end
  end
end

yeah adding @andac-ozcan’s suggestion fixes the initial issue but then it fails on the next thing:

ld: warning: dylib (/Users/tijs/Library/Developer/Xcode/DerivedData/KubusApp-fdqmmsifozyckxgwovqxkqcnjqwd/Build/Products/Debug-iphonesimulator/fmt/fmt.framework/fmt) was built for newer iOS Simulator version (10.0) than being linked (9.0)
ld: warning: dylib (/Users/tijs/Library/Developer/Xcode/DerivedData/KubusApp-fdqmmsifozyckxgwovqxkqcnjqwd/Build/Products/Debug-iphonesimulator/glog/glog.framework/glog) was built for newer iOS Simulator version (11.0) than being linked (9.0)
ld: warning: dylib (/Users/tijs/Library/Developer/Xcode/DerivedData/KubusApp-fdqmmsifozyckxgwovqxkqcnjqwd/Build/Products/Debug-iphonesimulator/libevent/libevent.framework/libevent) was built for newer iOS Simulator version (10.0) than being linked (9.0)
ld: warning: dylib (/Users/tijs/Library/Developer/Xcode/DerivedData/KubusApp-fdqmmsifozyckxgwovqxkqcnjqwd/Build/Products/Debug-iphonesimulator/DoubleConversion/DoubleConversion.framework/DoubleConversion) was built for newer iOS Simulator version (11.0) than being linked (9.0)
Undefined symbols for architecture x86_64:
  "_jump_fcontext", referenced from:
      folly::fibers::FiberImpl::deactivate() in Fiber.o
      folly::fibers::FiberImpl::activate() in SimpleLoopController.o
  "_make_fcontext", referenced from:
      folly::fibers::FiberImpl::FiberImpl(folly::Function<void ()>, unsigned char*, unsigned long) in Fiber.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Looks like a fix is on the way for RN 0.69 #34030

@Kudo 's fix on RN 0.69 seems to fix the issue, thanks Kudo 👍

If anyone needs to apply this fix to the older versions of RN, adding this to the Podfile does the trick (based on Kudo’s fix on https://github.com/facebook/react-native/pull/34030):

      if target.name == "RCT-Folly"
        target.build_configurations.each do |config|
          config.build_settings['HEADER_SEARCH_PATHS'] = "\"$(PODS_TARGET_SRCROOT)\" \"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/libevent/include/\" \"$(PODS_ROOT)/fmt/include\""
          config.build_settings['OTHER_LDFLAGS'] = "\"-Wl,-U,_jump_fcontext\" \"-Wl,-U,_make_fcontext\""
        end
      end

Looks like a fix is on the way for RN 0.69 #34030

@Kudo 's fix on RN 0.69 seems to fix the issue, thanks Kudo 👍 If anyone needs to apply this fix to the older versions of RN, adding this to the Podfile does the trick (based on Kudo’s fix on #34030):

      if target.name == "RCT-Folly"
        target.build_configurations.each do |config|
          config.build_settings['HEADER_SEARCH_PATHS'] = "\"$(PODS_TARGET_SRCROOT)\" \"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/libevent/include/\" \"$(PODS_ROOT)/fmt/include\""
          config.build_settings['OTHER_LDFLAGS'] = "\"-Wl,-U,_jump_fcontext\" \"-Wl,-U,_make_fcontext\""
        end
      end

‘glog/logging.h’ file not found After using this.

On 0.68.2 with Hermes enabled

If use_frameworks! is used in the Podfile. This configuration will cause bitcode to be unavailable.

"OTHER_LDFLAGS" => "\"-Wl,-U,_jump_fcontext\" \"-Wl,-U,_make_fcontext\""
image
$static_framework =[
    "DoubleConversion",
    "FBLazyVector",
    "FBReactNativeSpec",
    "RCT-Folly",
    "RCTRequired",
    "RCTTypeSafety",
    "RNCAsyncStorage",
    "RNCMaskedView",
    "RNFastImage",
    "RNGestureHandler",
    "RNScreens",
    "React",
    "React-Codegen",
    "React-Core",
    "React-CoreModules",
    "React-RCTActionSheet",
    "React-RCTAnimation",
    "React-RCTBlob",
    "React-RCTImage",
    "React-RCTLinking",
    "React-RCTNetwork",
    "React-RCTSettings",
    "React-RCTText",
    "React-RCTVibration",
    "React-callinvoker",
    "React-cxxreact",
    "React-hermes",
    "React-jsi",
    "React-jsiexecutor",
    "React-jsinspector",
    "React-logger",
    "React-perflogger",
    "React-runtimeexecutor",
    "ReactCommon",
    "Yoga",
    "boost",
    "fmt",
    "glog",
    "hermes-engine",
    "react-native-webview",
  ]

  pre_install do |installer|
    Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
    installer.pod_targets.each do |pod|
        if $static_framework.include?(pod.name)
          def pod.build_type;
            Pod::BuildType.static_library
          end
        end
      end
  end

@passerbyloo

hello guys, I solved this by setting all react native libraries to static library in podfile. NOTICE: all means whether it is a swift library or a oc library, if it depends React or React Core, it should be static compiled.

Same, not able to use RN:0.67.2 with hermes enabled. This RCT-Folly always had compile issues in past couple year. With below fix in Podfile you can solve this particular issue but then it’ll fail at somewhere else.

use_flipper!({ 'Flipper' => '0.131.1', 'Flipper-Folly' => '2.6.10', 'Flipper-RSocket' => '1.4.3', 'Flipper-DoubleConversion' => '3.1.7', 'Flipper-PeerTalk' => '0.0.4', 'OpenSSL-Universal' => '1.1.1100' })

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == 'RCT-Folly'
        target.build_configurations.each do |config|
            config.build_settings['HEADER_SEARCH_PATHS'] = "$(inherited) ${PODS_ROOT}/fmt/include"
        end
    end
  end

  react_native_post_install(installer)
  __apply_Xcode_12_5_M1_post_install_workaround(installer)
end

This works with RN 0.67.2