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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[META] Upgrading Folly #20302

Closed
hramos opened this issue Jul 19, 2018 · 15 comments
Closed

[META] Upgrading Folly #20302

hramos opened this issue Jul 19, 2018 · 15 comments
Labels
Help Wanted :octocat: Issues ideal for external contributors. Resolution: Locked This issue was locked by the bot. Type: Discussion Long running discussion.

Comments

@hramos
Copy link
Contributor

hramos commented Jul 19, 2018

For Discussion

The Folly version used in open source is very old. We're looking for volunteers interested in making the necessary changes to upgrade Folly in React Native.

Known Incompatibilities

This is in no way an exhaustive list, but be aware you'll need to tackle the following when upgrading Folly:

  • folly::Optional's has_value() doesn't exist
  • No template named 'Optional' in namespace 'folly' stuff
@hramos hramos added Help Wanted :octocat: Issues ideal for external contributors. Type: Discussion Long running discussion. labels Jul 19, 2018
@fkgozali
Copy link
Contributor

to upgrade Folly in React Native

Ideally, we'd want to pull the latest folly directly from https://github.com/facebook/folly - or at least use the latest version for each RN release - automatically.

This will involve updating/changing the integration with CocoaPods + gradle that react-native repo has today, e.g. making them run the build scripts already provided by folly repo, instead of making their own wrapper scripts / build steps.

@dulmandakh
Copy link
Contributor

I would like to volunteer to upgrade Folly in Android, and I think this experience will help me better learn C++.

Also it might be better to prepare RN for Clang and libc++ support, as it'll be the only compiler and STL in next NDK release. I tried to build RN with Clang and got many warnings, errors in Folly. So I think that it might be better to upgrade C++ or native tools beforehand, maybe merge #20357 which would land latest Android NDK version.

@dulmandakh
Copy link
Contributor

maybe it's better to switch to CMake to build jni code on Android, because boost, glob and folly supports it, but also many C++ libraries.

@gengjiawen
Copy link
Contributor

@dulmandakh Good idea. And with it we can also have better IDE support.

@yinhangfeng
Copy link

I have tried building with cmake
https://github.com/yinhangfeng/react-native/blob/0.53-stable-cmake/ReactAndroid/CMakeLists.txt
maybe have some reference value
i don't understand c++ but this does work.

for the convenience of testing I put all the libraries in ReactAndroid/third-party-ndk
Folly version 2018.02.05.00

problem:

  1. c++_shared conflict with jsc-android-buildscripts
    https://github.com/yinhangfeng/react-native/blob/0.53-stable-cmake/ReactAndroid/build.gradle#L255
  2. JSC_JSGlobalContextEnableDebugger does not exist https://github.com/yinhangfeng/react-native/blob/0.53-stable-cmake/ReactCommon/cxxreact/JSCExecutor.cpp#L224

@dulmandakh
Copy link
Contributor

@yinhangfeng could you please try to build master with CMake as is, or without bumping libraries. Once finished it will be easy to bump libraries to latest versions. Thank you.

@Kudo
Copy link
Contributor

Kudo commented Oct 19, 2018

I am going to upgrade folly and build the code with clang.
So far the build is passed with folly's patch facebook/folly#953.
But there is still a bottleneck for runtime crash, that current prebuilt android-jsc (libjsc.so and libicu_common.so) are still built by GCC.
Both original JSC on jcenter and current upstream one are linked to libgnustl_shared.so.

It seems that the community maintained android-jsc builder could build JSC with clang.
I would clarify if there are any plans to upgrade android-jsc that built by clang.
or maybe @gengjiawen could share the steps that how you build the android-jsc at #18754.

@dulmandakh
Copy link
Contributor

dulmandakh commented Oct 19, 2018 via email

@Kudo
Copy link
Contributor

Kudo commented Oct 19, 2018

I've tried before and the old folly does not support NDK with clang build.
This issue relates to this facebook/folly#75.
That's why I upgrade folly directly.

@Kudo
Copy link
Contributor

Kudo commented Oct 19, 2018

Just create #21863 to show my changes in case if someone has interests.

facebook-github-bot pushed a commit to facebook/folly that referenced this issue Oct 19, 2018
Summary:
According to this android/ndk#647,
  posix_memalign may not exist on Android API 16.
  From Android NDK r17c, the API exists for Android API 17+.
```
    #if __ANDROID_API__ >= 17
    int posix_memalign(void** __memptr, size_t __alignment, size_t __size) __INTRODUCED_IN(17);
    #endif /* __ANDROID_API__ >= 17 */
```
  Change the code to use posix_memalign only after Android API 17+.
  This would also fix issue for OSS React Native to pack latest folly and building with clang.
  See: facebook/react-native#20302 and facebook/react-native#20342
Pull Request resolved: #953

Reviewed By: yfeldblum

Differential Revision: D10469757

Pulled By: Orvid

fbshipit-source-id: c63838f3f6e723ef3de77187f39597a4063043db
facebook-github-bot pushed a commit that referenced this issue Oct 29, 2018
Summary:
Fixes #20302 (For iOS)

Note:
------

1. Checked the changes did not break CocoaPods integration.
2. The change for glog copying header into exported/ is to prevent build break for folly.
    `folly/detail/Demangle.h` will try to use libstdc++'s demangle.h. Unfortunately, glog also has a demangle.h in source code. So I copy exported headers and only search headers in exported/ folder during build.
Pull Request resolved: #21976

Reviewed By: hramos

Differential Revision: D12818131

Pulled By: fkgozali

fbshipit-source-id: b3c637d09d1b3adde0ea15c82eb56e28f846885b
@fkgozali
Copy link
Contributor

I've merged both #21976 and #21977 - this should get us moving for the time being. However, I'd like to see if we can come up with a more scalable/automated way of upgrading Folly. For instance, right now we list out relevant files manually like so:

https://github.com/facebook/react-native/pull/21977/files#diff-ae2383f344153a01ce1b6130b453a8e1R5

This list usually changes release by release (not always, tho). I think to make it more maintainable (e.g. if we decide to upgrade it again 1 year from now), it would be great if somehow we can use whatever configuration folly repo already has. Perhaps there's no specific cmake/config for mobile builds atm, but maybe that's one way to approach this:

  • introduce mobile-only folly build config in folly repo
  • adjust gradle/cocoapods/xcode to execute such build script in the build step
  • all RN configs need to do is to point to a specific folly release

This will make upgrades much easier in the future. Thoughts?

@fkgozali fkgozali reopened this Oct 29, 2018
@fkgozali
Copy link
Contributor

Btw @Kudo, thank you for the PRs! They should unblock us for making Fabric C++ code compilable with gradle/cocoapods/xcode.

@Kudo
Copy link
Contributor

Kudo commented Oct 30, 2018

@fkgozali Thank you for the review and landing.

Just for your information, in the Android PR, I wrote a folly patch in gradle to support gcc 4.9.
The patch works due to RN only includes partial folly library.
Unfortunately, folly does not support gcc 4.9 now and NDK only support gcc to 4.9.
We should use clang to support folly build, in case if we are going to import other parts of folly.

I am working on #21863 and hopefully we could use clang build soon.

@hramos hramos changed the title Upgrade Folly [META] Upgrading Folly Dec 19, 2018
sandraiser pushed a commit to sandraiser/folly that referenced this issue Mar 4, 2019
Summary:
According to this android/ndk#647,
  posix_memalign may not exist on Android API 16.
  From Android NDK r17c, the API exists for Android API 17+.
```
    #if __ANDROID_API__ >= 17
    int posix_memalign(void** __memptr, size_t __alignment, size_t __size) __INTRODUCED_IN(17);
    #endif /* __ANDROID_API__ >= 17 */
```
  Change the code to use posix_memalign only after Android API 17+.
  This would also fix issue for OSS React Native to pack latest folly and building with clang.
  See: facebook/react-native#20302 and facebook/react-native#20342
Pull Request resolved: facebook#953

Reviewed By: yfeldblum

Differential Revision: D10469757

Pulled By: Orvid

fbshipit-source-id: c63838f3f6e723ef3de77187f39597a4063043db
@cpojer
Copy link
Contributor

cpojer commented Mar 19, 2019

Just wanted to ask what is the status of this issue? Are we still looking for somebody to figure out a way to make folly upgrades easier in the future or are we alright with the current state of things?

@gengjiawen
Copy link
Contributor

@cpojer I think you can close it for now. Folly has been upgraded. Upgrade easier or migrate to CMake is another issue.

@cpojer cpojer closed this as completed Mar 19, 2019
t-nanava pushed a commit to microsoft/react-native-macos that referenced this issue Jun 17, 2019
Summary:
Fixes facebook#20302 (For Android)

Note:
------
1. New folly will have build break for a gcc-4.9 and gcc-4.9 seems to be deprecated for latest folly.
    As we only use partial folly implementations, I just fixed the build break part.
    To support building RN on Windows, the patches are written by gradle ReplaceTokens.

2. The change for glog copying header into exported/ is to prevent build break for folly.
    `folly/detail/Demangle.h` will try to use libstdc++'s demangle.h. Unfortunately, glog also has a demangle.h in source code. So I copy exported headers and only search headers in exported/ folder during build.
Pull Request resolved: facebook#21977

Reviewed By: hramos

Differential Revision: D12818133

Pulled By: fkgozali

fbshipit-source-id: 2c1f6f012663204581a86141d0c9ed0eb9d8c698
t-nanava pushed a commit to microsoft/react-native-macos that referenced this issue Jun 17, 2019
Summary:
Fixes facebook#20302 (For iOS)

Note:
------

1. Checked the changes did not break CocoaPods integration.
2. The change for glog copying header into exported/ is to prevent build break for folly.
    `folly/detail/Demangle.h` will try to use libstdc++'s demangle.h. Unfortunately, glog also has a demangle.h in source code. So I copy exported headers and only search headers in exported/ folder during build.
Pull Request resolved: facebook#21976

Reviewed By: hramos

Differential Revision: D12818131

Pulled By: fkgozali

fbshipit-source-id: b3c637d09d1b3adde0ea15c82eb56e28f846885b
@facebook facebook locked as resolved and limited conversation to collaborators Mar 19, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Mar 19, 2020
KusStar pushed a commit to KusStar/react-native that referenced this issue Oct 28, 2020
Summary:
Fixes facebook#20302 (For Android)

Note:
------
1. New folly will have build break for a gcc-4.9 and gcc-4.9 seems to be deprecated for latest folly.
    As we only use partial folly implementations, I just fixed the build break part.
    To support building RN on Windows, the patches are written by gradle ReplaceTokens.

2. The change for glog copying header into exported/ is to prevent build break for folly.
    `folly/detail/Demangle.h` will try to use libstdc++'s demangle.h. Unfortunately, glog also has a demangle.h in source code. So I copy exported headers and only search headers in exported/ folder during build.
Pull Request resolved: facebook#21977

Reviewed By: hramos

Differential Revision: D12818133

Pulled By: fkgozali

fbshipit-source-id: 2c1f6f012663204581a86141d0c9ed0eb9d8c698
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Help Wanted :octocat: Issues ideal for external contributors. Resolution: Locked This issue was locked by the bot. Type: Discussion Long running discussion.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants