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

Apple M1 chip: ARM64 simulator build fails / CocoaLibEvent #1758

Closed
andreialecu opened this issue Dec 12, 2020 · 21 comments
Closed

Apple M1 chip: ARM64 simulator build fails / CocoaLibEvent #1758

andreialecu opened this issue Dec 12, 2020 · 21 comments

Comments

@andreialecu
Copy link

andreialecu commented Dec 12, 2020

🐛 Bug Report

The PR #1735 fixes part of the issue with building Flipper for the Arm64 iOS simulator used on M1 Macs.

Even though the fix above is not yet released, I was able to test it via the mechanism described in this post:
facebook/react-native#30543 (comment)

However, linking now fails with this error:

in .../ios/Pods/CocoaLibEvent/lib/libevent.a(buffer.o), building for iOS Simulator, but linking in object file built for iOS, file '.../ios/Pods/CocoaLibEvent/lib/libevent.a' for architecture arm64

See:

spec.dependency 'CocoaLibEvent', '~> 1.0'

https://github.com/e314521/CocoaLibEvent

That library seems pretty obscure and doesn't seem maintained at all.

To Reproduce

Use an M1 mac, replace use_flipper! with use_flipper!('Flipper-Folly' => { :podspec => 'https://raw.githubusercontent.com/facebook/flipper/master/iOS/Podspecs/Flipper-Folly.podspec' } ). Run build in XCode, see above error.

Environment

MacOS Big Sur 11.0.1
Mac Mini with M1 chip

@andreialecu
Copy link
Author

I was able to find this script:
https://github.com/e314521/ios-lib/blob/fa1246cbaa0ea664ee285690aedf551ff7753f85/build-libevent.sh

It seems to be what builds libevent.a and the other artefacts.

Forking the library and updating the build script to also build for the iPhoneSimulator-arm64 target might be an option.

@andreialecu
Copy link
Author

I spent some time looking into what it would take to update the binaries to be compatible and here are my findings:

I worked on an updated script that will build libevent correctly for all targets, including arm64 iPhoneSimulator:
https://gist.github.com/andreialecu/2cc00a5e7212bf3b935afd015d693877

However, lipo cannot be used to merge both the iOS and simulator arm64 slice into the same output file:

fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: /Users/andreialecu/Work/contrib/libevent-builder/build/built/iPhoneSimulator-arm64.sdk/lib/libevent.a and /Users/andreialecu/Work/contrib/libevent-builder/build/built/iPhoneOS-arm64.sdk/lib/libevent.a have the same architectures (arm64) and can't be in the same fat output file

What this means is that they need to be converted into an xcframework with separate outputs similar to what OpenSSL-Universal does:

https://github.com/krzyzanowskim/OpenSSL/blob/5fe27f6accc02fb666175f65b83c1552030f3669/scripts/create-frameworks.sh
https://github.com/krzyzanowskim/OpenSSL/tree/5fe27f6accc02fb666175f65b83c1552030f3669/Frameworks

Hopefully someone can take over this work. It was a fun experiment. In the mean time I'll resort to disabling Flipper until this is resolved.

@betoharres
Copy link

betoharres commented Dec 12, 2020

I think I got the same error a few hours ago too, I just checked Xcode to run in Rosetta 2 and it worked :)
EDIT: sorry I didn't realized you were actually trying to fix this error; my mistake ;)

@imWildCat
Copy link
Contributor

Fixing this issue also helps Catalyst.

IMO, we should use XCframework rather than a .a file.

@hsavit1
Copy link

hsavit1 commented Jan 28, 2021

Any updates here?

@mweststrate
Copy link
Contributor

@hsavit1 it doesn't look like the base library didn't receive an update yet (https://github.com/e314521/CocoaLibEvent), once it does, we can bump our dep. I assume that the Folly project in general won't be compatible with M1 yet for the same reason. But as far as I can see M1 isn't officially support by React Native yet? So until that is the case I guess this one is pending :)

@andreialecu
Copy link
Author

Doesn't seem likely that the base library will ever be updated by the looks of it.

I posted steps on how to fix it above, someone needs to step up. I'd do it but I'm not familiar enough with the native mac development intricacies.

@mweststrate
Copy link
Contributor

mweststrate commented Jan 28, 2021 via email

@andreialecu
Copy link
Author

RN works on M1.

I have several projects using it natively on M1 with native arm64 compilation (no need to use Rosetta)

It only works with Flipper disabled though. See react-native-community/discussions-and-proposals#295 (comment) and other comments in that issue.

@mweststrate
Copy link
Contributor

mweststrate commented Jan 28, 2021 via email

@mweststrate
Copy link
Contributor

mweststrate commented Jan 28, 2021 via email

@hsavit1
Copy link

hsavit1 commented Jan 28, 2021

it's a discussion in the react native discussion group, not an issue on react native itself

@hsavit1
Copy link

hsavit1 commented Jan 28, 2021

yes it does work out of the box, but flipper does not. I've kept the issue open because flipper does not work

@andreialecu
Copy link
Author

With Flipper being enabled by default and part of the official RN documentation, it seems like RN isn't going to advertise Apple Silicon support until Flipper works.

So RN is blocked on this issue itself.

@mweststrate
Copy link
Contributor

mweststrate commented Jan 28, 2021 via email

@mweststrate
Copy link
Contributor

Small update: we are currently looking into it. So hopefully we will be able to address it this week or next week. It might be the case that we can address it only in the next RN release, not sure about that yet.

@mweststrate
Copy link
Contributor

See #1892

@imWildCat
Copy link
Contributor

Better if we can leverage source code instead of pre-built binary. CocoaLibEvent is a binary.

@hsavit1
Copy link

hsavit1 commented Feb 11, 2021

When I upgraded my Podfiles with

  use_flipper!({ 'Flipper' => '0.75.0' })

I get this error after building the project

dyld: Library not loaded: @rpath/OpenSSL.framework/OpenSSL

@hsavit1
Copy link

hsavit1 commented Feb 12, 2021

more specifically,

dyld: dependent dylib '@rpath/OpenSSL.framework/OpenSSL' not found for '/private/var/folders/dj/7qqc0gpn6m9cwbnf0ztxs6qc0000gn/X/8435F332-4636-56B5-9086-0A79F18EB13B/d/Wrapper/Debug MyApp.app/Debug MyApp'. could not use '/Users/XXX/Library/Developer/Xcode/DerivedData/my_app-cyrdziywztcwbiakcqkhovpxhvfy/Build/Products/Debug-iphoneos/OpenSSL.framework/OpenSSL' because it was not built for platform iOS

@mweststrate
Copy link
Contributor

Since the original issue has been solved and an update is released. Closing this issue. For any further questions / fallout, please open a fresh issue.

@facebook facebook locked and limited conversation to collaborators Feb 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants