JaneaSystems / nodejs-mobile

Full-fledged Node.js on Android and iOS
https://code.janeasystems.com/nodejs-mobile
Other
2.57k stars 183 forks source link

Unable to build on M1 Mac (XCFramework has architecture ios-arm64, but not ios-arm64-simulator) #337

Open lufinkey opened 3 years ago

lufinkey commented 3 years ago

Project: nodejs-mobile Version: latest Mobile device: iPhone 12 Pro Max Simulator Mobile OS and version: M1 Macbook 13" Development Node.js: 14.17.5 Development platform: Darwin Nicks-MBP 20.2.0 Darwin Kernel Version 20.2.0: Wed Dec 2 20:40:21 PST 2020; root:xnu-7195.60.75~1/RELEASE_ARM64_T8101 arm64

When building for iOS Simulator in Xcode on an M1 mac, you cannot link directly against NodeMobile.framework. You will get the error building for ios simulator but the linked framework NodeMobile was built for iOS. So you must link against NodeMobile.xcframework.

However, since the iOS simulator is arm64 on an M1 mac, xcode looks for the ios-arm64-simulator slice inside the xcframework. Unfortunately, for some reason, the generated xcframework only contains ios-x86_64-simulator and ios-arm64. I've tried generating a new arm64 simulator framework by copying this line, changing the sdk to iphonesimulator, and building to a different location, but unfortunately xcode detects the libnode (and libuv etc...) architectures as built for iOS, not iOS simulator. So somehow libnode (and libuv and all the rest), need to be built using arm64, but specifically linked against the iOS Simulator SDK, not the iOS SDK.

I would make the change myself, but I don't know enough about cmake and the rest of the build system to do it. But basically all the dependent libraries and NodeMobile just need another architecture slice in the xcframework. As it stands though, supporting this would seem to require switching to building and linking against an xcframework by default.

kewlbear commented 3 years ago

I've made pull request #340 for this.

kewlbear commented 2 years ago

I've also made a Swift package out of this. https://github.com/kewlbear/nodejs-ios