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

feat: ship codegen-generated specs #566

Merged
merged 23 commits into from
Aug 16, 2024
Merged

feat: ship codegen-generated specs #566

merged 23 commits into from
Aug 16, 2024

Conversation

atlj
Copy link
Collaborator

@atlj atlj commented Jun 14, 2024

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. You can check codegen - javaPackageName is ignored with includesGeneratedCode and react-native codegen facebook/react-native#45079 to see more.

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
Copy link
Collaborator Author

atlj commented Jun 14, 2024

move the codegen script and codegen patching into bob.

@atlj atlj force-pushed the @atlj/ship-codegen-specs branch 3 times, most recently from 70dc19f to 3425532 Compare July 5, 2024 18:03
@atlj atlj force-pushed the @atlj/ship-codegen-specs branch from 2aa76c8 to d0b1ad2 Compare July 5, 2024 18:14
@mfazekas
Copy link

mfazekas commented Jul 5, 2024

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.

@atlj atlj enabled auto-merge August 16, 2024 14:01
@atlj atlj added this pull request to the merge queue Aug 16, 2024
Merged via the queue into main with commit a90142f Aug 16, 2024
29 checks passed
@atlj atlj deleted the @atlj/ship-codegen-specs branch August 16, 2024 14:03
@atlj atlj mentioned this pull request Aug 21, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants