Skip to content

Conversation

kitten
Copy link
Contributor

@kitten kitten commented Oct 6, 2025

Summary:

An earlier change (0.79 and onwards, I believe?) runs the iOS artifacts code generator script in Xcode as well as from Cocoapods. This duplication runs it twice, but the second step isn't able to load the new autolinking.json correctly; See: #53503

This PR "double" fixes this by:

  • simply passing the "real" output directory to the artifacts generator in (script_phases.sh) where it's called by Xcode, rather than a temporary directory
  • preferring $RCT_SCRIPT_OUTPUT_DIR if it's set as an environment variable in the artifacts generator (which it is by script_phases.sh)

While this is technically redundant, future changes here make this feel like a safer option, since both conventions overlap in these two places, and the double fix may prevent a regression here in the shortterm and convey what this path is supposed to be in both places.

Changelog:

[IOS] [FIXED] - Fix autolinking-generated react-native-config output not being used in ReactCodegen script phase due to temp output directory

Test Plan:

  • Prefer $RCT_SCRIPT_OUTPUT_DIR env var for finding build/generated/autolinking/autolinking.json
  • Always use real $RCT_SCRIPT_OUTPUT_DIR as output in withCodegenDiscovery in react_native_pods_utils/script_phases.sh (which is called by Xcode rather than Cocoapods to invoke the artifacts generator) since the temporary output directory isn't necessary

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 6, 2025
@facebook-github-bot facebook-github-bot added p: Expo Partner: Expo Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Oct 6, 2025
@kitten kitten force-pushed the @kitten/fix/codegen-run-in-xcode branch 2 times, most recently from 87f82c4 to 79a1ca4 Compare October 6, 2025 15:09
@kitten kitten force-pushed the @kitten/fix/codegen-run-in-xcode branch from 79a1ca4 to d08506e Compare October 6, 2025 16:43
…pt_phases.sh

Avoid ending up in in derive data output folder to be able to discover
`autolinking.json` generated in Cocoapods step in all cases, regardless
of if the script checks `RCT_SCRIPT_OUTPUT_DIR` itself.
@kitten kitten force-pushed the @kitten/fix/codegen-run-in-xcode branch from d08506e to b464256 Compare October 6, 2025 16:48
chrfalch added a commit to expo/expo that referenced this pull request Oct 6, 2025
An earlier change (0.79 and onwards, I believe?) runs the iOS artifacts code generator script in Xcode as well as from Cocoapods. This duplication runs it twice, but the second step isn't able to load the new autolinking.json correctly; See: #53503

This has been fixed upstream here: facebook/react-native#54066

Untill this one is merged, released and available to Expo, we need a workaround.

Added build phase script for a workaround to autolinking-generated react-native-config output not being used in ReactCodegen script phase due to temp output directory.
@cipolleschi
Copy link
Contributor

The change is much earlier. We always run codegen in xcode. This allows users to write native modules and native components locally in their app, without having to reinstall cocopods everytime they change the specs of those custom modules/components.

Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall the changes make sense to me and I'm positive in supporting them. I don't like the approach of looping over some outputPatchCandidates... Cn we find a way not to have that loop?

moveOutputs
describe "Generating codegen artifacts"
pushd "$RCT_SCRIPT_RN_DIR" >/dev/null || exit 1
"$NODE_BINARY" "scripts/generate-codegen-artifacts.js" --path "$RCT_SCRIPT_APP_PATH" --outputPath "$RCT_SCRIPT_OUTPUT_DIR" --targetPlatform "ios"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of RCT_SCRIPT_OUTPUT_DIR is always RCT_SCRIPT_POD_INSTALLATION_ROOT, which is set to be

pushd "$PODS_ROOT/../" > /dev/null
RCT_SCRIPT_POD_INSTALLATION_ROOT=$(pwd)

So it will always be Pods/.., which is where we want codegen to be generated.
Just adding the comment for the future.

@kitten kitten force-pushed the @kitten/fix/codegen-run-in-xcode branch from 90bc77f to bb178a4 Compare October 6, 2025 19:06
@kitten kitten force-pushed the @kitten/fix/codegen-run-in-xcode branch from bb178a4 to d5955f2 Compare October 6, 2025 19:09
@kitten kitten requested a review from cipolleschi October 6, 2025 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Expo Partner: Expo Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants