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

arm64 simulators & catalyst support #475

Closed
wants to merge 4 commits into from

Conversation

Arkkeeper
Copy link

Summary

Edits build scripts to allow merging architectures into .xcframework instead of using lipo for building fat framework.
Adds compatibility with arm64 iOS Simulators on Apple M1 Macs and allows using Hermes with RN apps built for Mac Catalyst.

Fixes #460 and #468

@facebook-github-bot
Copy link
Contributor

Hi @Arkkeeper!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Mar 20, 2021
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@Huxpro
Copy link
Contributor

Huxpro commented Mar 22, 2021

@Arkkeeper Thanks for contributing! While cc-ing @grabbou to review this, I noticed that test-apple-runtime in CircleCI is failing. Could you also take care of that?

The test-apple-runtime is setup here: https://github.com/facebook/hermes/blob/master/.circleci/config.yml#L202

@@ -20,13 +20,13 @@ Pod::Spec.new do |spec|
# The podspec would be serialized to JSON and people will download prebuilt binaries instead of the source.
# TODO(use the hash field as a validation mechanism when the process is stable)
spec.source = ENV['hermes-artifact-url'] ? { http: ENV['hermes-artifact-url'] } : { git: "https://github.com/facebook/hermes.git", tag: "v#{spec.version}" }
spec.platforms = { :osx => "10.13", :ios => "10.0" }
spec.platforms = { :osx => "11.0", :ios => "10.0" }
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe because of this version bump?

Copy link
Author

Choose a reason for hiding this comment

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

I reverted that bump, I don't think that it's essential for Catalyst support.
Now CircleCI fails on Android tests, but my commits have nothing to do with the android part of code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah do not worry about the Android tests. The android emulator image is somehow missing.

@andreialecu
Copy link

Friendly ping @grabbou

For context why this is extremely important:

RN 0.64 now ships with iOS Hermes support, but lack of support for iOS Simulator arm64 arch makes it impossible to work with it.

Additionally, react-native-reanimated v2 has been released, which uses JSI/turbo modules.

RN apps using turbo modules can only be debugged with Flipper's Hermes Debugger.

@andreialecu
Copy link

andreialecu commented Apr 8, 2021

@Arkkeeper is there any easy way to use this PR before it's merged?

@Arkkeeper
Copy link
Author

Arkkeeper commented Apr 10, 2021

You have to patch react-native/scripts/react_native_pods.rb.

First, add a variable to check whether it's ARM Mac, like:
is_arm = '/usr/sbin/sysctl -n hw.optional.arm64 2>&1'.to_i

Then modify definition of hermes-engine and refer to repo with my PR:

if is_arm == 1 then
pod 'hermes-engine', :git => 'https://github.com/Arkkeeper/hermes.git'
else
pod 'hermes-engine', '~> 0.7.2'
end

Make sure that you have cmake and ninja installed with homebrew.

Then run yarn and prepare to wait about 15-20 minutes. Building hermes-engine from sources for several archs is rather tedious.

@andreialecu
Copy link

Thank you. Some notes regarding your instructions, in case it helps others:

Ran into fatal: repository 'Arkkeeper/hermes.git' does not exist so I had to add it as:
pod 'hermes-engine', :git => 'git@github.com:Arkkeeper/hermes.git'.

Also, detecting arm64 didn't work in my case because I can only run cocoapods using arch -x86_64, due to other issues with it. So I just had to hardcode it without the check.

Copy link
Contributor

@alloy alloy left a comment

Choose a reason for hiding this comment

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

Awesome, I didn’t know somebody had already done this work! Most importantly we should make sure it still works for macOS too.

local catalyst="false"
local platform=$1

if [[ $1 == iphoneos || $1 == catalyst ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps also replace further use of $1 with the $platform alias here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would actually not use $platform here. Further explanation on line 62.

@@ -56,11 +59,16 @@ function configure_apple_framework {
else
build_cli_tools="false"
fi
if [[ $1 == catalyst ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

This comment was marked as resolved.

for platform in "${@:2}"; do
rm -r "$platform"
done
xcodebuild -create-xcframework -framework iphoneos/hermes.framework -framework iphonesimulator/hermes.framework -framework macosx/hermes.framework -output iphoneos/hermes.xcframework
Copy link
Contributor

Choose a reason for hiding this comment

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

The output should not assume the framework is just for iOS here, it should theoretically also be able to contain the macOS slices, no?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. Also, it should also get the platforms from the platforms, like the lipo did, without hardcoding them. I just think it's nicer and doesn't require manual rm of every folder, like it's currently done on line 112-114.


for i in "${!platforms[@]}"; do
platforms[$i]="${platforms[$i]}/hermes.framework/hermes"
done

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

@grabbou
Copy link
Contributor

grabbou commented Apr 27, 2021

Thanks for the PR! I left some comments to further optimise the scripts and the way we handle Catalyst, but I'd consider them minor tweaks, since overall, everything seems to be fine.

@Arkkeeper
Copy link
Author

Thank you for your suggestions! I've pushed some optimizations for the build scripts. I hope that my PR won't delay Hermes 0.8.1 and RN 0.65.

@garrylachman
Copy link

Building hermes-engine from sources for several archs is rather tedious.

Building third time in row, over 1 hour each time. not cool :(

@umang-simform
Copy link

@Arkkeeper Any timeline on how soon it can get merged?

@kelset
Copy link

kelset commented Jun 17, 2021

cc @grabbou remember to check this one ;)

Copy link
Contributor

@grabbou grabbou left a comment

Choose a reason for hiding this comment

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

Thank you for addressing my previous comments. The PR looks really good! Rather than two tiny issues, it is good to go.

I will give it a shot and test it tomorrow, and if everything runs smoothly, I will merge it, reverting the deleted lines on top of your PR.

# Once all was linked into a single framework, clean destroot
# from unused frameworks
for platform in "${@:2}"; do
rm -r "$platform"
Copy link
Contributor

Choose a reason for hiding this comment

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

Any particular reason why this has been removed? This should be reverted. We need to clean up destroot to only contain the artifacts that are used in production.

This is because CircleCI will package the entire destroot folder into a tarball that is distributed along the npm package. If we don't clean it up, we are going to ship one xcframework and every platform separately as well.

Copy link
Author

Choose a reason for hiding this comment

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

OK, I've reverted that removal

done

lipo -info "${platforms[0]}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Any particular reason why this has been removed? I think this is a good add-on for debugging purposes on the CI.

Copy link
Author

Choose a reason for hiding this comment

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

Because lipo -info fails on xcframework with a fatal error:
can't map input file: iphoneos (Invalid argument)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok

@grabbou
Copy link
Contributor

grabbou commented Jun 29, 2021

Code wise, it looks good. However, I just noticed that test-apple-runtime is currently failing.

Testing failed:
Undefined symbol: facebook::hermes::makeHermesRuntime(hermes::vm::RuntimeConfig const&)
Undefined symbol: facebook::hermes::HermesRuntime::debugJavaScript(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, facebook::hermes::HermesRuntime::DebugFlags const&)
Testing cancelled because the build failed.

@facebook-github-bot
Copy link
Contributor

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

Huxpro pushed a commit to Huxpro/hermes that referenced this pull request Jun 30, 2021
Summary:
Edits build scripts to allow merging architectures into .xcframework instead of using lipo for building fat framework.
Adds compatibility with arm64 iOS Simulators on Apple M1 Macs and allows using Hermes with RN apps built for Mac Catalyst.

Fixes facebook#460 and facebook#468

Pull Request resolved: facebook#475

Differential Revision: D29465045

Pulled By: Huxpro

fbshipit-source-id: 6291aac9ee47db83d6f78822767019ec0277a899
@TheSavior
Copy link
Member

I believe we should be closing this one in favor of #546. Thanks for the work so far!

@TheSavior TheSavior closed this Jul 8, 2021
facebook-github-bot pushed a commit that referenced this pull request Jul 9, 2021
Summary:
This PR is #475 with adjustments
to folder names. It also fixes caches and CI issues.

Pull Request resolved: #546

Test Plan: CircleCI

Reviewed By: mhorowitz

Differential Revision: D29597379

Pulled By: Huxpro

fbshipit-source-id: f278f9c5503965cb998872993a1ce38cfcdaadcc
Huxpro pushed a commit that referenced this pull request Jul 12, 2021
Summary:
This PR is #475 with adjustments
to folder names. It also fixes caches and CI issues.

Pull Request resolved: #546

Test Plan: CircleCI

Reviewed By: mhorowitz

Differential Revision: D29597379

Pulled By: Huxpro

fbshipit-source-id: f278f9c5503965cb998872993a1ce38cfcdaadcc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for Mac Catalyst
10 participants