fix(ios) fix for building for simulator on M1

Backport of: a1c445a39c
This commit is contained in:
Saúl Ibarra Corretgé 2022-02-25 13:57:59 +01:00 committed by Saúl Ibarra Corretgé
parent be152b12d7
commit d018d19874
5 changed files with 113 additions and 6 deletions

View File

@ -40,7 +40,6 @@ post_install do |installer|
config.build_settings['ENABLE_BITCODE'] = 'YES'
config.build_settings['SUPPORTS_MACCATALYST'] = 'NO'
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = ""
end
end
# https://github.com/facebook/react-native/blob/d7f748a944a9a9324e485ccbe214098e6c8645fc/scripts/react_native_pods.rb#L630

View File

@ -712,6 +712,6 @@ SPEC CHECKSUMS:
RNWatch: 99637948ec9b5c9ec5a41920642594ad5ba07e80
Yoga: e7dc4e71caba6472ff48ad7d234389b91dadc280
PODFILE CHECKSUM: e41212a6ae973769a62da680119065bfc370819c
PODFILE CHECKSUM: 7fafb3480e45473da539aa09d06374868b021f90
COCOAPODS: 1.11.2

View File

@ -981,7 +981,7 @@
ENABLE_BITCODE = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 ";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
@ -1042,7 +1042,7 @@
ENABLE_BITCODE = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 ";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;

View File

@ -518,7 +518,7 @@
ENABLE_BITCODE = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 ";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
@ -581,7 +581,7 @@
ENABLE_BITCODE = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 ";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;

View File

@ -31,3 +31,111 @@ index 70f0543..d43a4be 100644
- (void)stopTimers
{
if (_inBackground) {
diff --git a/node_modules/react-native/scripts/react_native_pods.rb b/node_modules/react-native/scripts/react_native_pods.rb
index df31139..061ded9 100644
--- a/node_modules/react-native/scripts/react_native_pods.rb
+++ b/node_modules/react-native/scripts/react_native_pods.rb
@@ -125,20 +125,49 @@ def exclude_architectures(installer)
.uniq{ |p| p.path }
.push(installer.pods_project)
- arm_value = `/usr/sbin/sysctl -n hw.optional.arm64 2>&1`.to_i
-
# Hermes does not support `i386` architecture
excluded_archs_default = has_pod(installer, 'hermes-engine') ? "i386" : ""
projects.each do |project|
project.build_configurations.each do |config|
- if arm_value == 1 then
- config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = excluded_archs_default
- else
- config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64 " + excluded_archs_default
+ config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = excluded_archs_default
+ end
+
+ project.save()
+ end
+end
+
+def fix_library_search_paths(installer)
+ def fix_config(config)
+ lib_search_paths = config.build_settings["LIBRARY_SEARCH_PATHS"]
+ if lib_search_paths
+ if lib_search_paths.include?("$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)") || lib_search_paths.include?("\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"")
+ # $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME) causes problem with Xcode 12.5 + arm64 (Apple M1)
+ # since the libraries there are only built for x86_64 and i386.
+ lib_search_paths.delete("$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)")
+ lib_search_paths.delete("\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"")
+ if !(lib_search_paths.include?("$(SDKROOT)/usr/lib/swift") || lib_search_paths.include?("\"$(SDKROOT)/usr/lib/swift\""))
+ # however, $(SDKROOT)/usr/lib/swift is required, at least if user is not running CocoaPods 1.11
+ lib_search_paths.insert(0, "$(SDKROOT)/usr/lib/swift")
+ end
end
end
+ end
+
+ projects = installer.aggregate_targets
+ .map{ |t| t.user_project }
+ .uniq{ |p| p.path }
+ .push(installer.pods_project)
+ projects.each do |project|
+ project.build_configurations.each do |config|
+ fix_config(config)
+ end
+ project.native_targets.each do |target|
+ target.build_configurations.each do |config|
+ fix_config(config)
+ end
+ end
project.save()
end
end
@@ -149,6 +178,7 @@ def react_native_post_install(installer)
end
exclude_architectures(installer)
+ fix_library_search_paths(installer)
end
def use_react_native_codegen!(spec, options={})
@@ -218,36 +248,8 @@ end
# See https://github.com/facebook/react-native/issues/31480#issuecomment-902912841 for more context.
# Actual fix was authored by https://github.com/mikehardy.
# New app template will call this for now until the underlying issue is resolved.
+#
+# It's not needed anymore and will be removed later
def __apply_Xcode_12_5_M1_post_install_workaround(installer)
- # Apple Silicon builds require a library path tweak for Swift library discovery to resolve Swift-related "symbol not found".
- # Note: this was fixed via https://github.com/facebook/react-native/commit/eb938863063f5535735af2be4e706f70647e5b90
- # Keeping this logic here but commented out for future reference.
- #
- # installer.aggregate_targets.each do |aggregate_target|
- # aggregate_target.user_project.native_targets.each do |target|
- # target.build_configurations.each do |config|
- # config.build_settings['LIBRARY_SEARCH_PATHS'] = ['$(SDKROOT)/usr/lib/swift', '$(inherited)']
- # end
- # end
- # aggregate_target.user_project.save
- # end
-
- # Flipper podspecs are still targeting an older iOS deployment target, and may cause an error like:
- # "error: thread-local storage is not supported for the current target"
- # The most reliable known workaround is to bump iOS deployment target to match react-native (iOS 11 now).
- installer.pods_project.targets.each do |target|
- target.build_configurations.each do |config|
- # ensure IPHONEOS_DEPLOYMENT_TARGET is at least 11.0
- should_upgrade = config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].split('.')[0].to_i < 11
- if should_upgrade
- config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
- end
- end
- end
-
- # But... doing so caused another issue in Flipper:
- # "Time.h:52:17: error: typedef redefinition with different types"
- # We need to make a patch to RCT-Folly - remove the `__IPHONE_OS_VERSION_MIN_REQUIRED` check.
- # See https://github.com/facebook/flipper/issues/834 for more details.
- `sed -i -e $'s/ && (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0)//' Pods/RCT-Folly/folly/portability/Time.h`
+ puts "__apply_Xcode_12_5_M1_post_install_workaround() is not needed anymore"
end