Skip to content

feat: ship codegen-generated specs - #566

Merged
atlj merged 23 commits into
mainfrom
@atlj/ship-codegen-specs
Aug 16, 2024
Merged

atlj merged 23 commits into
mainfrom
@atlj/ship-codegen-specs

Conversation

@atlj

@atlj atlj commented Jun 14, 2024 •

Copy link
Copy Markdown
Collaborator

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 react/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

atlj commented Jun 14, 2024

Copy link
Copy Markdown
Collaborator Author

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

mfazekas commented Jul 5, 2024

Copy link
Copy Markdown

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.

Comment thread packages/react-native-builder-bob/src/utils/patchCodegen.ts Outdated
Comment thread packages/react-native-builder-bob/src/targets/codegen.ts Outdated
Comment thread packages/react-native-builder-bob/src/targets/codegen.ts Outdated
Comment thread packages/react-native-builder-bob/src/index.ts Outdated
Comment thread packages/create-react-native-library/src/utils/patchExampleAppCodegen.ts Outdated
Comment thread packages/react-native-builder-bob/src/targets/codegen.ts Outdated
Comment thread packages/react-native-builder-bob/src/targets/codegen.ts Outdated
@atlj
atlj force-pushed the @atlj/ship-codegen-specs branch from 72c5efe to 07df18c Compare August 11, 2024 13:40
@atlj
atlj force-pushed the @atlj/ship-codegen-specs branch from d1e0764 to 39d2a07 Compare August 16, 2024 11:53
@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
@atlj
atlj deleted the @atlj/ship-codegen-specs branch August 16, 2024 14:03
@atlj atlj mentioned this pull request Aug 21, 2024
1 of 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