folly icon indicating copy to clipboard operation
folly copied to clipboard

Time.h `typedef redefinition` with iOS 10 set as a deployment target

Open grabbou opened this issue 5 years ago • 19 comments

Hey,

I am working on a Hermes support for React Native and while working on it, I have run into the following issue, when building the React Native project:

Screenshot_2020-10-01_at_11 07 41

React Native has deployment target set to 10.0 for all its parts, including third party pod specs such as RCT-Folly, that it defines to download and compile Folly with pieces that it needs. After changing the deployment target for RCT-Folly specifically from 10.0 to 9.0, the issue goes away.

This is a temporary workaround that we have implemented to unblock the PR.

I believe it is caused by the following code:

#if __MACH__ &&                                                       \
        ((!defined(TARGET_OS_OSX) || TARGET_OS_OSX) &&                \
         (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12)) || \
    (TARGET_OS_IPHONE && (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0))

#ifdef FOLLY_HAVE_CLOCK_GETTIME
#undef FOLLY_HAVE_CLOCK_GETTIME
#endif

#define FOLLY_HAVE_CLOCK_GETTIME 1
#define FOLLY_FORCE_CLOCK_GETTIME_DEFINITION 1

#endif

The way I read it is - when building for iPhone and targeting iOS versions lower than 10.0 (e.g. 9.0), don't define macros. When building for newer iOS release, such as 10.0, define it. Shouldn't it be the opposite, if the purpose was to provide backwards compatibility?

The issue is being brought up from time to time in various projects - that's where I have learnt about the "deployment target" workaround:

  • https://github.com/facebook/react-native/issues/28810
  • https://github.com/facebook/react-native/issues/27845
  • https://github.com/facebook/flipper/issues/834

Here are my questions:

  • What was the original intent behind this particular if condition? Where is the "__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0" requirement coming from?
  • Is the workaround applied in our PR a valid fix?

grabbou avatar Oct 07 '20 15:10 grabbou

In general the fixes for clock_gettime on apple platforms have been a bit complicated, but hopefully @chadaustin has some idea if this would be the right fix for iOS.

Orvid avatar Oct 10 '20 07:10 Orvid

same

hengkx avatar Oct 14 '20 06:10 hengkx

This stuff is always a pain. I'm trying to understand exactly what's going on in your failing case.

We only #define CLOCK_REALTIME if FOLLY_HAVE_CLOCK_GETTIME is 0 (and Apple/Windows).

Would it make sense if https://github.com/facebook/folly/blob/b26907eac594228c1a7e2523e16b44db79a99ace/folly/portability/Time.h#L46 checked FOLLY_FORCE_CLOCK_GETTIME_DEFINITION instead?

Are you asking about the PR that pins back to iOS 9.0? I'd support tweaking these conditions to make them more accurate.

chadaustin avatar Oct 16 '20 18:10 chadaustin

We only #define CLOCK_REALTIME if FOLLY_HAVE_CLOCK_GETTIME is 0 (and Apple/Windows).

Yeah, and this seems to be only valid when __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0 is false. In other words, you define CLOCK_REALTIME on all iOS that are 10.0 or newer.

Is that correct? If yes, why? My gut feeling would be that any backwards compatibility should be run on older releases of iOS, not newer.

Since React Native targets iOS 10.0 by default, I had to manually set Folly project to 9.0 as a deployment target.

grabbou avatar Oct 23 '20 09:10 grabbou

This is still an issue for me in May 2021. Is there a plan to fix?

gaberogan avatar May 06 '21 12:05 gaberogan

This is an issue for me as well after the 12.5 upgrade. Do we have any idea on a fix timeline? I would PR but I don't want the fix to cause issues with older versions of xcode.

jwaldrip avatar May 07 '21 20:05 jwaldrip

set __IPHONE_10_0 to __IPHONE_12_0 inside of Time.h for a temp workaround

fierysolid avatar Sep 01 '21 21:09 fierysolid

Unfortunately setting __IPHONE_12_0 still throws this for me.

kyle-ssg avatar Sep 14 '21 12:09 kyle-ssg

Changing to __IPHONE_12_0 as per @fierysolid's suggestion worked for me.

spencerkitson avatar Sep 25 '21 21:09 spencerkitson

I forced the #if macro to evaluate to true by adding 1 || to the following line:

#if 1 || __MACH__ &&                                                       \
        ((!defined(TARGET_OS_OSX) || TARGET_OS_OSX) &&                \
         (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12)) || \
    (TARGET_OS_IPHONE && (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0))

and it compiled successfully.

emretapci avatar Sep 27 '21 11:09 emretapci

I solved it by adding this to the Podfile:

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['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'FOLLY_HAVE_CLOCK_GETTIME=1']
      end
    end
  end
end

By modifiing GCC_PREPROCESSOR_DEFINITIONS for RCT-Folly you don't have to touch the source (and works with a clean install)

supercranky avatar Oct 14 '21 08:10 supercranky

@supercranky's suggestion worked for me.

atsuya046 avatar Oct 19 '21 13:10 atsuya046

#1688 Might fix this ?

Saadnajmi avatar Dec 22 '21 21:12 Saadnajmi

I solved it by adding this to the Podfile:

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['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'FOLLY_HAVE_CLOCK_GETTIME=1']
      end
    end
  end
end

By modifiing GCC_PREPROCESSOR_DEFINITIONS for RCT-Folly you don't have to touch the source (and works with a clean install)

This solved it for me. Running Xcode 13.1 on a Mac Mini M1 macOS v11.6 with React Native 0.66.2

dennisplucinik avatar Jan 16 '22 23:01 dennisplucinik

We can close this?

Saadnajmi avatar Sep 21 '23 05:09 Saadnajmi

I updated React Native to a version of Folly with the fix in https://github.com/facebook/folly/commit/4a2410fae65afb85e1fec6d922005054b05de59f and we just started seeing the redefinition error again 😅. Going to try to workaround with manually setting FOLLY_HAVE_CLOCK_GETTIME for now...

NickGerleman avatar Oct 04 '23 02:10 NickGerleman

I updated React Native to a version of Folly with the fix and we just started seeing the redefinition error for the first time 😅. Going to try to workaround with manually setting FOLLY_HAVE_CLOCK_GETTIME for now...

Oh :(, you might want to undo my earlier change removing the patch then.

Saadnajmi avatar Oct 04 '23 02:10 Saadnajmi

Let me try manually setting the availability first. Would rather that then the sed style patching to headers happening before. Though, we should maybe try another spin at fixing feature detection.

Afaict, in a stock CocoaPods XCode 15 setup, __CLOCK_AVAILABILITY is not set, so after the change, we fail the new detection.

NickGerleman avatar Oct 04 '23 02:10 NickGerleman