Skip to content

Commit

Permalink
Fix build failure on iOS with pnpm and use_frameworks! (#38158)
Browse files Browse the repository at this point in the history
Summary:
Fix build failure on iOS with pnpm and use_frameworks! due to cocoapods copying symlinked headers to wrong paths

When using pnpm all packages are symlinked to node_modules/.pnpm to prevent phantom dependency resolution. This causes react-native iOS build to fail because Cocoapods copies headers to incorrect destinations when they're behind symlinks. The fix resolves absolute paths to the header_mappings_dir at pod install time. With absolute paths cocoapods copies the headers correctly.

This commit also adds a few missing header search paths in use_frameworks! mode.

Fixes #38140

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[IOS] [FIXED] - Build failure with pnpm and use_frameworks! due to incorrect header paths

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests

Pull Request resolved: #38158

Test Plan:
1. `pnpm pnpx react-native@latest init AwesomeProject`
2. `cd AwesomeProject`
3. `rm -rf node_modules yarn.lock`
4. `mkdir patches`
5. copy [react-native@0.72.1.patch](https://github.com/facebook/react-native/files/11937570/react-native%400.72.1.patch) to `patches/`
6. Add patch to package.json
```
"pnpm": {
    "patchedDependencies": {
        "react-native@0.72.1": "patches/react-native@0.72.1.patch"
    }
}
```
7. `pnpm install`
8. `cd ios`
9. `NO_FLIPPER=1 USE_FRAMEWORKS=static pod install`
10. `cd ..`
11. `pnpm react-native run-ios`

Hopefully an automated test of building with `pnpm` can be added to CI. I don't know how to make that happen, hopefully someone at facebook can do it.

Reviewed By: dmytrorykun

Differential Revision: D47211946

Pulled By: cipolleschi

fbshipit-source-id: 87640bd3f32f023c43291213b5291a7b990d7e1f
  • Loading branch information
evelant authored and facebook-github-bot committed Jul 6, 2023
1 parent 41477c8 commit 58adc5e
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ header_search_paths = [
if ENV["USE_FRAMEWORKS"]
header_search_paths = header_search_paths.concat([
"\"$(PODS_CONFIGURATION_BUILD_DIR)/ReactCommon/ReactCommon.framework/Headers/react/nativemodule/core\"",
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-NativeModulesApple/React_NativeModulesApple.framework/Headers\""
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-NativeModulesApple/React_NativeModulesApple.framework/Headers\"",
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-NativeModulesApple/React_NativeModulesApple.framework/Headers/build/generated/ios\"",
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-Codegen/React_Codegen.framework/Headers/build/generated/ios\"",
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-Codegen/React_Codegen.framework/Headers\""
])
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ header_search_paths = [
if ENV["USE_FRAMEWORKS"]
header_search_paths = header_search_paths.concat([
"\"$(PODS_CONFIGURATION_BUILD_DIR)/ReactCommon/ReactCommon.framework/Headers/react/nativemodule/core\"",
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-NativeModulesApple/React_NativeModulesApple.framework/Headers\""
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-NativeModulesApple/React_NativeModulesApple.framework/Headers\"",
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-NativeModulesApple/React_NativeModulesApple.framework/Headers/build/generated/ios\"",
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-Codegen/React_Codegen.framework/Headers/build/generated/ios\"",
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-Codegen/React_Codegen.framework/Headers\"",

])
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ header_search_paths = [
if ENV["USE_FRAMEWORKS"]
header_search_paths = header_search_paths.concat([
"\"$(PODS_CONFIGURATION_BUILD_DIR)/ReactCommon/ReactCommon.framework/Headers/react/nativemodule/core\"",
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-NativeModulesApple/React_NativeModulesApple.framework/Headers\""
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-NativeModulesApple/React_NativeModulesApple.framework/Headers\"",
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-NativeModulesApple/React_NativeModulesApple.framework/Headers/build/generated/ios\"",
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-Codegen/React_Codegen.framework/Headers/build/generated/ios\"",
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-Codegen/React_Codegen.framework/Headers\"",
])
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ header_search_paths = [
if ENV["USE_FRAMEWORKS"]
header_search_paths = header_search_paths.concat([
"\"$(PODS_CONFIGURATION_BUILD_DIR)/ReactCommon/ReactCommon.framework/Headers/react/nativemodule/core\"",
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-NativeModulesApple/React_NativeModulesApple.framework/Headers\""
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-NativeModulesApple/React_NativeModulesApple.framework/Headers\"",
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-Codegen/React_Codegen.framework/Headers/build/generated/ios\"",
"\"$(PODS_CONFIGURATION_BUILD_DIR)/React-Codegen/React_Codegen.framework/Headers\""
])
end

Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/ReactCommon/React-Fabric.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Pod::Spec.new do |s|
"DEFINES_MODULE" => "YES" }

if ENV['USE_FRAMEWORKS']
s.header_mappings_dir = './'
s.header_mappings_dir = File.absolute_path('./')
s.module_name = 'React_Fabric'
end

Expand Down
12 changes: 12 additions & 0 deletions packages/react-native/ReactCommon/React-rncore.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ react_native_dependency_path = ENV['REACT_NATIVE_PATH']
# Relative path to react native from current podspec
react_native_sources_path = '..'

header_search_paths = [
"\"$(PODS_TARGET_SRCROOT)\"",
"\"$(PODS_TARGET_SRCROOT)/ReactCommon\"",
]

if ENV["USE_FRAMEWORKS"]
header_search_paths = header_search_paths.concat([
"\"$(PODS_CONFIGURATION_BUILD_DIR)/ReactCommon/ReactCommon.framework/Headers/react/nativemodule/core\"",
])
end

Pod::Spec.new do |s|
s.name = "React-rncore"
s.version = version
Expand All @@ -37,6 +48,7 @@ Pod::Spec.new do |s|
s.source = source
s.source_files = "dummyFile.cpp"
s.pod_target_xcconfig = { "USE_HEADERMAP" => "YES",
"HEADER_SEARCH_PATHS" => header_search_paths.join(' '),
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17" }


Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/ReactCommon/ReactCommon.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
"GCC_WARN_PEDANTIC" => "YES" }
if ENV['USE_FRAMEWORKS']
s.header_mappings_dir = './'
s.header_mappings_dir = File.absolute_path("./")
end

# TODO (T48588859): Restructure this target to align with dir structure: "react/nativemodule/..."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ Pod::Spec.new do |s|

if ENV['USE_FRAMEWORKS']
s.module_name = "React_debug"
s.header_mappings_dir = "../.."
s.header_mappings_dir = File.absolute_path("../..")
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
"GCC_WARN_PEDANTIC" => "YES" }
if ENV['USE_FRAMEWORKS']
s.header_mappings_dir = './'
s.header_mappings_dir = File.absolute_path('./')
end

s.source_files = "ReactCommon/**/*.{mm,cpp,h}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
"GCC_WARN_PEDANTIC" => "YES" }
if ENV['USE_FRAMEWORKS']
s.header_mappings_dir = './'
s.header_mappings_dir = File.absolute_path('./')
end


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Pod::Spec.new do |s|

if ENV['USE_FRAMEWORKS']
s.module_name = "React_graphics"
s.header_mappings_dir = "../../.."
s.header_mappings_dir = File.absolute_path("../../..")
header_search_paths = header_search_paths + ["\"$(PODS_TARGET_SRCROOT)/platform/ios\""]
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Pod::Spec.new do |s|

if ENV['USE_FRAMEWORKS']
s.module_name = "React_ImageManager"
s.header_mappings_dir = "./"
s.header_mappings_dir = File.absolute_path("./")
header_search_paths = header_search_paths + [
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers\"",
"\"$(PODS_ROOT)/DoubleConversion\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Pod::Spec.new do |s|

if ENV['USE_FRAMEWORKS']
s.module_name = "React_runtimescheduler"
s.header_mappings_dir = "../../.."
s.header_mappings_dir = File.absolute_path("../../..")
end

s.dependency "React-jsi"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Pod::Spec.new do |s|

if ENV['USE_FRAMEWORKS']
s.module_name = "React_utils"
s.header_mappings_dir = "../.."
s.header_mappings_dir = File.absolute_path("../..")
end

s.dependency "RCT-Folly", folly_version
Expand Down

3 comments on commit 58adc5e

@koenpunt
Copy link
Contributor

@koenpunt koenpunt commented on 58adc5e Aug 27, 2023

Choose a reason for hiding this comment

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

This commit breaks pod install --deployment --clean-install, because the absolute path is not the same in a CI environment.

Adding spec repo `trunk` with CDN `https://cdn.cocoapods.org/`
Verifying no changes
[!] There were changes to the lockfile in deployment mode:
SPEC CHECKSUMS:
  React-debug:
    New Lockfile: 419922cde6c58cd5b9d43e4a09805146a7dd13a8
    Old Lockfile: 1ce329843d8f9a9cbe0cdd9de264b20e89586734
  React-NativeModulesApple:
    New Lockfile: a683b0c999e76b7d15ad9d5eaf8b6308e710a93e
    Old Lockfile: f82356d67a137295d098a98a03be5ee35871b5a5
  React-runtimescheduler:
    New Lockfile: 79f8dff11acbe36aaeece63553680d7a8272af96
    Old Lockfile: 16c5282d43a0df50d7c68ebf0218aeeb642a7086
  React-utils:
    New Lockfile: 4fabb3cba786651e35bc41e610b0698fa24cecff
    Old Lockfile: e7e9118d0e85b107bb06d1a5f72ec5db6bddb911
  ReactCommon:
    New Lockfile: af30fb021799e18c85a8e30ce799e15607e82212
    Old Lockfile: f04f86f33c22e05dbf875789ea522ee486dace78

@LuckyRoc
Copy link

Choose a reason for hiding this comment

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

This commit breaks pod install --deployment --clean-install, because the absolute path is not the same in a CI environment.

Adding spec repo `trunk` with CDN `https://cdn.cocoapods.org/`
Verifying no changes
[!] There were changes to the lockfile in deployment mode:
SPEC CHECKSUMS:
  React-debug:
    New Lockfile: 419922cde6c58cd5b9d43e4a09805146a7dd13a8
    Old Lockfile: 1ce329843d8f9a9cbe0cdd9de264b20e89586734
  React-NativeModulesApple:
    New Lockfile: a683b0c999e76b7d15ad9d5eaf8b6308e710a93e
    Old Lockfile: f82356d67a137295d098a98a03be5ee35871b5a5
  React-runtimescheduler:
    New Lockfile: 79f8dff11acbe36aaeece63553680d7a8272af96
    Old Lockfile: 16c5282d43a0df50d7c68ebf0218aeeb642a7086
  React-utils:
    New Lockfile: 4fabb3cba786651e35bc41e610b0698fa24cecff
    Old Lockfile: e7e9118d0e85b107bb06d1a5f72ec5db6bddb911
  ReactCommon:
    New Lockfile: af30fb021799e18c85a8e30ce799e15607e82212
    Old Lockfile: f04f86f33c22e05dbf875789ea522ee486dace78

same question

@koenpunt
Copy link
Contributor

Choose a reason for hiding this comment

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

@LuckyRoc it wasn't a question. And also the problem has since been fixed, so I believe if you use the latest version of react-native it should work again.

Please sign in to comment.