Skip to content

Commit a1c445a

Browse files
barbierifacebook-github-bot
authored andcommitted
Fix: Xcode 12.5+ build of iPhone Simulator on Apple M1 (#32284)
Summary: Since Apple released its own silicon M1, an ARM64, the react-native build is broken or at least not as effective as it should. This PR stops excluding `arm64` simulator (this is not needed on the M1 neither on Intel devices) and removes the problematic `$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)` from `LIBRARY_SEARCH_PATHS`, since on Xcode 12.5 and 13.0 this folder contains only `i386/x86_64` binaries and will fail compilation. Instead this PR forces `$(SDKROOT)/usr/lib/swift` while it removes the incorrect directory. Ideally we could just remove `LIBRARY_SEARCH_PATHS` altogether if `$(inherited)` and `$(SDKROOT)/usr/lib/swift` were the only entries, but it would require us a **newer CocoaPods**, since that was fixed with `1.11` (see CocoaPods/CocoaPods@6985cbf). Since we don't enforce that, lets keep the `$(SDKROOT)/usr/lib/swift` and call it done. Last but not least, deprecate the `__apply_Xcode_12_5_M1_post_install_workaround()` as it's not needed anymore, at least with recent versions of the dependencies, no patching is required with RCT-Folly, neither we need to force `IPHONEOS_DEPLOYMENT_TARGET=11.0` ## Changelog [iOS] [Fixed] - Xcode 12.5+ build of iPhone Simulator on Apple M1 [iOS] [Changed] - Do not exclude the arm64 iphonesimulator [iOS] [Deprecated] - __apply_Xcode_12_5_M1_post_install_workaround() Pull Request resolved: #32284 Test Plan: * Build `packages/rn-tester` on M1 and see it still works properly * Run `pod install` on x86_64 and arm64 (m1) and see the `project.pbxproj` is not changed ## References: * Closes #31480 * The initial fix ac4ddec * Upgrading CocoaPods to 1.11 would bring us CocoaPods/CocoaPods@6985cbf and we could avoid adding `$(SDKROOT)/usr/lib/swift` ourselves Reviewed By: lunaleaps Differential Revision: D31248460 Pulled By: fkgozali fbshipit-source-id: 5a0d69593e889e296a2ba2e7b4387ecbd56fc08d
1 parent 132d1d0 commit a1c445a

File tree

5 files changed

+42
-41
lines changed

5 files changed

+42
-41
lines changed

packages/rn-tester/Podfile

-1
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,4 @@ end
5252

5353
post_install do |installer|
5454
react_native_post_install(installer)
55-
__apply_Xcode_12_5_M1_post_install_workaround(installer)
5655
end

packages/rn-tester/Podfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,6 @@ SPEC CHECKSUMS:
919919
Yoga: c0d06f5380d34e939f55420669a60fe08b79bd75
920920
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
921921

922-
PODFILE CHECKSUM: 21be0a8894b752aaab399f9d4075cf41baf345f3
922+
PODFILE CHECKSUM: f2609ec079811d7784b6e802b8351314bd41de51
923923

924924
COCOAPODS: 1.10.1

packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj

+2-4
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,6 @@
785785
LIBRARY_SEARCH_PATHS = (
786786
"\"$(SDKROOT)/usr/lib/swift\"",
787787
"$(inherited)",
788-
"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)",
789788
"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)",
790789
);
791790
"LIBRARY_SEARCH_PATHS[arch=*]" = "$(inherited)";
@@ -820,7 +819,6 @@
820819
LIBRARY_SEARCH_PATHS = (
821820
"\"$(SDKROOT)/usr/lib/swift\"",
822821
"$(inherited)",
823-
"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)",
824822
"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)",
825823
);
826824
OTHER_LDFLAGS = (
@@ -873,7 +871,7 @@
873871
ENABLE_BITCODE = NO;
874872
ENABLE_STRICT_OBJC_MSGSEND = YES;
875873
ENABLE_TESTABILITY = YES;
876-
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 ";
874+
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
877875
GCC_C_LANGUAGE_STANDARD = gnu11;
878876
GCC_DYNAMIC_NO_PIC = NO;
879877
GCC_NO_COMMON_BLOCKS = YES;
@@ -957,7 +955,7 @@
957955
ENABLE_BITCODE = NO;
958956
ENABLE_NS_ASSERTIONS = NO;
959957
ENABLE_STRICT_OBJC_MSGSEND = YES;
960-
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 ";
958+
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
961959
GCC_C_LANGUAGE_STANDARD = gnu11;
962960
GCC_NO_COMMON_BLOCKS = YES;
963961
GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES;

scripts/react_native_pods.rb

+39-33
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,49 @@ def exclude_architectures(installer)
127127
.uniq{ |p| p.path }
128128
.push(installer.pods_project)
129129

130-
arm_value = `/usr/sbin/sysctl -n hw.optional.arm64 2>&1`.to_i
131-
132130
# Hermes does not support `i386` architecture
133131
excluded_archs_default = has_pod(installer, 'hermes-engine') ? "i386" : ""
134132

135133
projects.each do |project|
136134
project.build_configurations.each do |config|
137-
if arm_value == 1 then
138-
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = excluded_archs_default
139-
else
140-
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64 " + excluded_archs_default
135+
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = excluded_archs_default
136+
end
137+
138+
project.save()
139+
end
140+
end
141+
142+
def fix_library_search_paths(installer)
143+
def fix_config(config)
144+
lib_search_paths = config.build_settings["LIBRARY_SEARCH_PATHS"]
145+
if lib_search_paths
146+
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)\"")
147+
# $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME) causes problem with Xcode 12.5 + arm64 (Apple M1)
148+
# since the libraries there are only built for x86_64 and i386.
149+
lib_search_paths.delete("$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)")
150+
lib_search_paths.delete("\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"")
151+
if !(lib_search_paths.include?("$(SDKROOT)/usr/lib/swift") || lib_search_paths.include?("\"$(SDKROOT)/usr/lib/swift\""))
152+
# however, $(SDKROOT)/usr/lib/swift is required, at least if user is not running CocoaPods 1.11
153+
lib_search_paths.insert(0, "$(SDKROOT)/usr/lib/swift")
154+
end
141155
end
142156
end
157+
end
158+
159+
projects = installer.aggregate_targets
160+
.map{ |t| t.user_project }
161+
.uniq{ |p| p.path }
162+
.push(installer.pods_project)
143163

164+
projects.each do |project|
165+
project.build_configurations.each do |config|
166+
fix_config(config)
167+
end
168+
project.native_targets.each do |target|
169+
target.build_configurations.each do |config|
170+
fix_config(config)
171+
end
172+
end
144173
project.save()
145174
end
146175
end
@@ -151,6 +180,7 @@ def react_native_post_install(installer)
151180
end
152181

153182
exclude_architectures(installer)
183+
fix_library_search_paths(installer)
154184
end
155185

156186
def use_react_native_codegen!(spec, options={})
@@ -337,32 +367,8 @@ def use_react_native_codegen!(spec, options={})
337367
# See https://github.com/facebook/react-native/issues/31480#issuecomment-902912841 for more context.
338368
# Actual fix was authored by https://github.com/mikehardy.
339369
# New app template will call this for now until the underlying issue is resolved.
370+
#
371+
# It's not needed anymore and will be removed later
340372
def __apply_Xcode_12_5_M1_post_install_workaround(installer)
341-
# Apple Silicon builds require a library path tweak for Swift library discovery to resolve Swift-related "symbol not found".
342-
# Note: this was fixed via https://github.com/facebook/react-native/commit/eb938863063f5535735af2be4e706f70647e5b90
343-
# Keeping this logic here but commented out for future reference.
344-
#
345-
# installer.aggregate_targets.each do |aggregate_target|
346-
# aggregate_target.user_project.native_targets.each do |target|
347-
# target.build_configurations.each do |config|
348-
# config.build_settings['LIBRARY_SEARCH_PATHS'] = ['$(SDKROOT)/usr/lib/swift', '$(inherited)']
349-
# end
350-
# end
351-
# aggregate_target.user_project.save
352-
# end
353-
354-
# Flipper podspecs are still targeting an older iOS deployment target, and may cause an error like:
355-
# "error: thread-local storage is not supported for the current target"
356-
# The most reliable known workaround is to bump iOS deployment target to match react-native (iOS 11 now).
357-
installer.pods_project.targets.each do |target|
358-
target.build_configurations.each do |config|
359-
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
360-
end
361-
end
362-
363-
# But... doing so caused another issue in Flipper:
364-
# "Time.h:52:17: error: typedef redefinition with different types"
365-
# We need to make a patch to RCT-Folly - set `__IPHONE_10_0` to our iOS target + 1.
366-
# See https://github.com/facebook/flipper/issues/834 for more details.
367-
`sed -i -e $'s/__IPHONE_10_0/__IPHONE_12_0/' #{installer.sandbox.root}/RCT-Folly/folly/portability/Time.h`
373+
puts "__apply_Xcode_12_5_M1_post_install_workaround() is not needed anymore"
368374
end

template/ios/HelloWorld.xcodeproj/project.pbxproj

-2
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,6 @@
437437
LIBRARY_SEARCH_PATHS = (
438438
"\"$(SDKROOT)/usr/lib/swift\"",
439439
"\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
440-
"\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"",
441440
"\"$(inherited)\"",
442441
);
443442
MTL_ENABLE_DEBUG_INFO = YES;
@@ -495,7 +494,6 @@
495494
LIBRARY_SEARCH_PATHS = (
496495
"\"$(SDKROOT)/usr/lib/swift\"",
497496
"\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
498-
"\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"",
499497
"\"$(inherited)\"",
500498
);
501499
MTL_ENABLE_DEBUG_INFO = NO;

0 commit comments

Comments
 (0)