discussions-and-proposals icon indicating copy to clipboard operation
discussions-and-proposals copied to clipboard

Support building react-native apps with BUCK

Open dehlen opened this issue 2 years ago • 3 comments

Introduction

My understanding is that Facebook uses Buck internally, it would be great if external developers had an example Buck configuration for React Native. I currently work on a hybrid mobile application. We have multiple native screens written in Swift/Kotlin and a lot of JS/TS code for shared react-native components. Since we have several native features/screens in our app the native part changes frequently which causes rebuilding all the native dependencies (also RN). This ultimately leads to 2 main problems:

  1. We experience pretty long build times due to the fact that we have to rebuild the whole project pretty much every time, on CI, when changing branches, etc.
  2. All developers need to manage a native build setup locally. This does not only include working on a Mac and downloading Xcode but also to familiarize themselves with Ruby, Cocoapods, Bundler, iOS and Android Native tooling. This results in broken builds, increased support requests, broken builds and a bad developer experience especially for newcomers to the project or people working very infrequent on the project.

Details

My understanding is that

  1. Facebook already uses BUCK internally f.e to build the RNTester app on CI
  2. BUCK, being a hermetic build system with options to remotely cache build artifacts could definitely help in speeding up the build as well as replacing a lot of the toolchain with a single buck build command.

As I see in the current GitHub repo a lot of the used BUCK rules are Facebook internal-only and are currently implemented with a simple "pass" command.

Discussion points

I would like to discuss whether it is possible for BUCK to be supported for third party developers and if not why this is the case and if there are solutions to our problems apart from this.

dehlen avatar Apr 19 '22 13:04 dehlen

Exactly Buck's used internally for testing our Android app on Ubuntu 20.04 (x86_64) along with Gradle during these parts of our CircleCI workflow:

  • test_android
    • mkdir -p ./reports/{buck,build,junit,outputs}
    • Restoring Buck cache
      • otherwise git clone https://github.com/uber/okbuck.git ~/okbuck --depth=1
    • Saving Buck cache, Validating Buck cache
    • Downloading deps
    • Building our Android app
      • buck build ReactAndroid/src/main/java/com/facebook/react
      • buck build ReactAndroid/src/main/java/com/facebook/react/shell
    • Then compiling native libs for unit and integration tests
      • ./gradlew :ReactAndroid:packageReactNdkLibsForBuck
        • ... > Task :ReactAndroid:packageReactNdkDebugLibsForBuck, > Task :ReactAndroid:packageReactNdkLibsForBuck
    • Running unit tests
      • buck test ReactAndroid/src/test/... --xml ./reports/buck/all-results-raw.xml
    • Running instrumentation tests
    • Collecting test results
  • test_android_rntester
    • ./gradlew :packages:rn-tester:android:app:assembleDebug
      • ... > Task :ReactAndroid:packageReactNdkDebugLibsForBuck ...

Officially supporting more build tools on top of Gradle is more bandwidth than Facebook are still currently prepared for

We haven't done any work on supporting Buck in React Native apps and won't have time to look into it very soon. If someone had bandwidth to do that check out this SO question: http://stackoverflow.com/questions/34997158/how-can-i-use-buck-to-build-react-native-apps-for-both-ios-and-android I'll close this issue as it's more of a discussion / feature request than a bug. We can continue discussing on Product Pains though

But yes, its been 6 years... We're in a similar situation with FastLane:

  • https://github.com/fastlane/fastlane/issues/7990

It's been 5 years since requested too, so I'm considering getting it working in my template, then building the FastLane Buck plugin there for us too

leotm avatar Apr 19 '22 15:04 leotm

Exactly I saw these issues/posts as well but wanted to discuss this further since it has been several years since then. I think the community would greatly benefit from the feature set BUCK offers as well as having an alternative to the currently maintained tooling. Of course I understand that this comes with more maintenance and support requests. I found https://github.com/rockwotj/prebuilt-rn on GitHub which builds an xcframework to use react-native in a Bazel build. This might be a good starting point (at least for the iOS build).

dehlen avatar Apr 20 '22 07:04 dehlen

@dehlen Thanks for raising this.

Officially supporting more build tools on top of Gradle is more bandwidth than Facebook are still currently prepared for

That's essentially the point of the whole discussion.

You're right in saying that we're currently using BUCK internally to build RN apps. However, we're not actively supporting building with BUCK in the OSS space. We strive to provide a setup that is as close as possible to the tools that are familiar to each ecosystem (Gradle for Android, Cocoapods for iOS, etc).

What I mean by this is that we're testing on CI and during our release process only the Gradle/CocoaPods setup. You can use BUCK and the BUCK files we publish alongside, but we don't offer any support on those.

Moreover, using BUCK for Android in OSS is getting harder as you'll need a binary which is compatible with Java 11 (as it's now a requirement for Android) while the published versions of BUCK are not. This would force our users to compile BUCK from source, which is something we'd like to avoid (but we have to do on our CI https://github.com/react-native-community/docker-android/blob/616d29a069c02fce2084f9d0855757e5c0a6ad14/Dockerfile#L1-L16).

Hope this clarifies.

We experience pretty long build times due to the fact that we have to rebuild the whole project pretty much every time, on CI, when changing branches, etc.

This is something we're aware of. Please take a look at this guide that addresses those problems specifically https://reactnative.dev/docs/build-speed

All developers need to manage a native build setup locally. This does not only include working on a Mac and downloading Xcode but also to familiarize themselves with Ruby, Cocoapods, Bundler, iOS and Android Native tooling.

We're working on making the build layer as thin as possible so you won't have to handle Gradle/Cocoapods code at all.

BUCK, being a hermetic build system with options to remotely cache build artifacts could definitely help in speeding up the build

At least for Android, you can use the Remote Build cache for Gradle as well. https://docs.gradle.org/current/userguide/build_cache.html

cortinico avatar May 04 '22 09:05 cortinico