react-native-builder-bob icon indicating copy to clipboard operation
react-native-builder-bob copied to clipboard

feat: ship codegen-generated specs

Open atlj opened this issue 1 year ago • 1 comments

Summary

So far with the new architecture-supported templates, we've been generating libraries that didn't ship their codegen-generated specs. This means the library's users had to build the codegen specs on their end (this was done implicitly). With this, the codegen-generated specs are generated at the build time and they are shipped with the library.

I've followed this guide from the React Native new arch working group.

Making sure example app builds are triggering codegen

An important problem to figure out was to make sure the codegen-generated specs were being built with each native build of the example app. To do that,create-react-native-library now modifies non-legacy example apps and adds:

  1. A new task to example/android/build.gradle that's triggered before each native build.
  2. A prebuild action to the XCode build schema.
  3. A pre_install hook to example/ios/Podfile that's triggered when user calls pod install.

These modifications make sure yarn codegen is called on the repo root to generate the codegen specs.

Notes

  1. There is an important problem with React Native itself right now. When react-native codegen is called, the generated Java code doesn't follow the codegenConfig.android.javaPackageName property in the package.json. This means the generated Java files are stored in a default location with the wrong package name. To fix it, I've added a script that moves the codegen-generated files into the correct place.

Test plan

Test if Android builds trigger codegen

  1. Create a non-legacy library using create-react-native-library
  2. Install the dependencies and build the example app on Android
  3. Make sure the build passes, and there are files under android/generated.

Test if installing pods triggers codegen

  1. Create a non-legacy library using create-react-native-library
  2. Install the dependencies and run pod install in example/ios
  3. Make sure the pods are installed and there are files under ios/generated.

Test if iOS builds trigger codegen

  1. Create a non-legacy library using create-react-native-library
  2. Install the dependencies and run pod install in example/ios
  3. Remove the codegen generated code from ios/generated since that's generated by the pod install step
  4. Build the app for iOS
  5. Make sure there are files in ios/generated.

Test if building the library triggers codegen

  1. Run yarn prepare to emulate the library release process
  2. Run yarn pack
  3. Extract the files from the generated package.tgz
  4. Make sure there are files under ios/generated, and android/generated in the generated package.

atlj avatar Jun 14 '24 06:06 atlj

move the codegen script and codegen patching into bob.

atlj avatar Jun 14 '24 09:06 atlj

So far with the new architecture-supported templates, we've been generating libraries that didn't ship their codegen-generated specs. This means the library's users had to build the codegen specs on their end (this was done implicitly). With this, the codegen-generated specs are generated at the build time and they are shipped with the library.

I think it would be great to explain the advantages (or disadvantages) of this approach. My understand for example if you want to make android side work with old arch, the codgen generated interfaces, delegates can be usefull to be shipped with the project.

mfazekas avatar Jul 05 '24 18:07 mfazekas