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

fix(hermes): change logic in build scripts for Apple to use the right version #34710

Closed
wants to merge 9 commits into from

Conversation

kelset
Copy link
Contributor

@kelset kelset commented Sep 16, 2022

Summary

Within the hermes-engine.podspec contained in the RN repo (at react-native/main/sdks/hermes-engine/), there's a bit of logic that triggers ./utils/build-ios-framework.sh and ./utils/build-mac-framework.sh .

The issue is that we all thought that that  ./utils/build-ios-framework.sh would invoke the React native version of the scripts (since the podspec file lives right next to the utils folder) but, in reality, it doesn't. It just so happens that the Hermes repo has a root level utils folder which is (you guessed it) where the Hermes variation of those build scripts live.
So, when running the pod install command in a react-native project (build from source), it will go and download the hermes source code (since the source[:git] gets set) but then it will use the hermes variation of the build-*.sh scripts.

Read more here.

This PR is taking @Kudo's proposed patch here - props for the fix go to him.

Changelog

[iOS] [Fixed] - Change hermes logic in build scripts for Apple to use the correct files

Test Plan

Tested by @Kudo in his work, and in my PR locally - see here.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Contributor A React Native contributor. p: Microsoft Partner: Microsoft Partner labels Sep 16, 2022
@kelset kelset added Tool: CocoaPods Tech: Hermes Hermes Engine: https://hermesengine.dev/ labels Sep 16, 2022
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Sep 16, 2022
@cortinico
Copy link
Contributor

Code looks fine on my end 👍 @cipolleschi has more context than me on this change

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

sdks/hermes-engine/utils/build-apple-framework.sh Outdated Show resolved Hide resolved
sdks/hermes-engine/utils/build-apple-framework.sh Outdated Show resolved Hide resolved
sdks/hermes-engine/utils/build-apple-framework.sh Outdated Show resolved Hide resolved
}

function get_mac_deployment_target {
ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').deployment_target('osx')"
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above. Do we always have MAC_DEPLOYMENT_TARGET?

sdks/hermes-engine/utils/build-ios-framework.sh Outdated Show resolved Hide resolved
sdks/hermes-engine/utils/build-mac-framework.sh Outdated Show resolved Hide resolved
@@ -16,15 +16,15 @@ REACT_NATIVE_PATH=${REACT_NATIVE_PATH:-$PWD/../..}
JSI_PATH="$REACT_NATIVE_PATH/ReactCommon/jsi"

function get_release_version {
ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').version"
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure that in CI, where we invoke the build-ios-framework and the build-mac-framework we have the RELEASE_VERSION, IOS_DEPLOYMENT_TARGET and MAC_DEPLOYMENT_TARGET properly set?
In this case we are not going through the hermes-engine.podspec, so it could be that these variables are not set...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, I guess we need to modify the CircleCI config to set them up too, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for following up the change. when i first proposed the change, i just want to keep it shorter. ideally we could add some if/else check.

for example,

function get_release_version {
  if [[ -n "${RELEASE_VERSION}" ]]; then
    echo "${RELEASE_VERSION}"
  else
    ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').deployment_target('ios')"
  fi
}

or

function get_release_version {
  if [[ -z "${RELEASE_VERSION}" ]]; then
    echo "RELEASE_VERSION is not defined."
    exit 1
  fi
  echo "${RELEASE_VERSION}"
}

please feel free to change the code that makes sense to you.

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@cipolleschi
Copy link
Contributor

@kelset @Kudo I updated the script with your suggestions (and a bit of refactoring). Can you give it a shot and see if it works properly for you (hoping that the CI does not break!)

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@Kudo Kudo left a comment

Choose a reason for hiding this comment

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

nit changes 😅

sdks/hermes-engine/utils/build-apple-framework.sh Outdated Show resolved Hide resolved
sdks/hermes-engine/utils/build-apple-framework.sh Outdated Show resolved Hide resolved
@cipolleschi
Copy link
Contributor

Thanks @Kudo, I should have fixed those! :D

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

2 similar comments
@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@analysis-bot
Copy link

analysis-bot commented Sep 23, 2022

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 5d2a400
Branch: main

@analysis-bot
Copy link

analysis-bot commented Sep 23, 2022

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,725,527 +0
android hermes armeabi-v7a 7,128,411 +0
android hermes x86 8,032,083 +0
android hermes x86_64 8,005,366 +0
android jsc arm64-v8a 9,595,873 +0
android jsc armeabi-v7a 8,362,168 +0
android jsc x86 9,540,083 +0
android jsc x86_64 10,132,493 +0

Base commit: 5d2a400
Branch: main

@cipolleschi cipolleschi force-pushed the kelset/fix-hermes-build-scripts branch 3 times, most recently from db71a89 to d7a4c14 Compare September 23, 2022 18:24
@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.


# Set HERMES_OVERRIDE_HERMESC_PATH if pre-built HermesC is available
#{File.exist?(import_hermesc_file) ? "export HERMES_OVERRIDE_HERMESC_PATH=#{import_hermesc_file}" : ""}
#{File.exist?(import_hermesc_file) ? "echo \"Overriding HermesC path...\"" : ""}

# Build iOS framework
./utils/build-ios-framework.sh
#{hermes_utils_path}/build-ios-framework.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

could you double confirm the generated Pods/Local Podspecs/hermes-engine.podspec.json doesn't contain the absolute path? in my case, it will have /Users/kudo, e.g.
"prepare_command": "export BUILD_TYPE=Debug\nexport RELEASE_VERSION=\"1000.0.0\"\nexport IOS_DEPLOYMENT_TARGET=\"12.4\"\nexport MAC_DEPLOYMENT_TARGET=\"10.13\"\nexport JSI_PATH=\"/Users/kudo/react-native/sdks/hermes/../../ReactCommon/jsi\"\n\n# Set HERMES_OVERRIDE_HERMESC_PATH if pre-built HermesC is available\n\n\n\n# Build iOS framework\n/Users/kudo/react-native/sdks/hermes/../../sdks/hermes-engine/utils/build-ios-framework.sh\n\n# Build Mac framework\n/Users/kudo/react-native/sdks/hermes/../../sdks/hermes-engine/utils/build-mac-framework.sh"

that would make the checksum in Podfile.lock unstable between each environments. that's why previously i proposed environment variables approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

You are right! I have full path too... I'm updating the PR to use the env variable.

Copy link
Contributor

Choose a reason for hiding this comment

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

it looks good now, thanks @cipolleschi!

@cipolleschi cipolleschi force-pushed the kelset/fix-hermes-build-scripts branch 3 times, most recently from 3683fa7 to 37985a2 Compare September 24, 2022 10:14
@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @kelset in cc13b02.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Sep 26, 2022
@kelset kelset deleted the kelset/fix-hermes-build-scripts branch September 26, 2022 09:23
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
… version (facebook#34710)

Summary:
Within the `hermes-engine.podspec` contained in the RN repo (at `react-native/main/sdks/hermes-engine/`), there's a bit of logic that triggers `./utils/build-ios-framework.sh` and `./utils/build-mac-framework.sh` .

The issue is that we all thought that that  `./utils/build-ios-framework.sh` would invoke the React native version of the scripts (since the podspec file lives right next to the `utils` folder) but, in reality, it doesn't. It just so happens that the Hermes repo has a root level `utils` folder which is (you guessed it) where the Hermes variation of those build scripts live.
So, when running the pod install command in a react-native project (build from source), it will go and download the hermes source code (since the `source[:git]` gets set) but then it will use the **hermes** variation of the `build-*.sh` scripts.

[Read more here](facebook#34513 (comment)).

This PR is taking kudo's proposed [patch here](reactwg/react-native-new-architecture#68 (reply in thread)) - props for the fix go to him.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[iOS] [Fixed] -  Change hermes logic in build scripts for Apple to use the correct files

Pull Request resolved: facebook#34710

Test Plan: Tested by kudo in his work, and in my PR locally - [see here](facebook#34513 (comment)).

Reviewed By: cortinico

Differential Revision: D39647057

Pulled By: cipolleschi

fbshipit-source-id: 6520e248801a307ca2f8886a3853dd1ff4af193d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Contributor A React Native contributor. Merged This PR has been merged. p: Microsoft Partner: Microsoft Partner Platform: iOS iOS applications. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. Tech: Hermes Hermes Engine: https://hermesengine.dev/ Tool: CocoaPods
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants