From 6c907ee11b22f1fc393c91fe09c059239a923400 Mon Sep 17 00:00:00 2001 From: Kudo Chien Date: Thu, 27 Mar 2025 06:39:30 -0700 Subject: [PATCH] fix React-jsitooling build error for use_frameworks build (#50252) Summary: to resolve use_frameworks build error. this is an edge case happening only when there's objective-c files import to `React_RCTAppDelegate`. Xcode will have `include of non-modular header inside framework module` error originally. this is the generated umbrella header for jsitooling is incorrect. even the header path are correct, they are not modular headers. ~this pr adds a workaround to import header from outside the module.~ updates: this pr uses a forward declaration to prevent exposing the dependency in umbrella header. [IOS] [FIXED] - `JSRuntimeFactoryCAPI.h` build error for `use_frameworks` build Pull Request resolved: https://github.com/facebook/react-native/pull/50252 Test Plan: to reproduce the build error, we can build `USE_FRAMEWORKS=static bundle exec pod install` from rn-tester. we also need to import `React_RCTAppDelegate` from objective-c files. in this case, we can add `import React_RCTAppDelegate;` in rn-tester's main.m ```diff --- a/packages/rn-tester/RNTester/main.m +++ b/packages/rn-tester/RNTester/main.m @@ -8,6 +8,9 @@ #import #import "AppDelegate.h" +@import React_RCTAppDelegate; +// This also triggers the error +//#import int main(int argc, char *argv[]) { ``` Reviewed By: fabriziocucci Differential Revision: D71963188 Pulled By: cipolleschi fbshipit-source-id: 5d566ae5aadb9efc032aacfe32862ea289134f87 --- .../AppDelegate/RCTJSRuntimeConfiguratorProtocol.h | 7 ++++--- .../Libraries/AppDelegate/RCTRootViewFactory.mm | 1 + .../ReactCommon/jsitooling/React-jsitooling.podspec | 7 +++++-- .../jsitooling/react/runtime/JSRuntimeFactory.h | 4 ++++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/react-native/Libraries/AppDelegate/RCTJSRuntimeConfiguratorProtocol.h b/packages/react-native/Libraries/AppDelegate/RCTJSRuntimeConfiguratorProtocol.h index 16d22dca4e7..ca7f1a089d6 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTJSRuntimeConfiguratorProtocol.h +++ b/packages/react-native/Libraries/AppDelegate/RCTJSRuntimeConfiguratorProtocol.h @@ -5,13 +5,14 @@ * LICENSE file in the root directory of this source tree. */ -#import -#import - #pragma once NS_ASSUME_NONNULL_BEGIN +// Forward declarations for umbrella headers. +// In implementations, import `` to obtain the actual type. +typedef void *JSRuntimeFactoryRef; + @protocol RCTJSRuntimeConfiguratorProtocol - (JSRuntimeFactoryRef)createJSRuntimeFactory; diff --git a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm index 1ed25b29ba4..17a3ca3d620 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm @@ -32,6 +32,7 @@ #import #import #import +#import @implementation RCTRootViewFactoryConfiguration diff --git a/packages/react-native/ReactCommon/jsitooling/React-jsitooling.podspec b/packages/react-native/ReactCommon/jsitooling/React-jsitooling.podspec index ce29c9a8345..0b5bbdf3365 100644 --- a/packages/react-native/ReactCommon/jsitooling/React-jsitooling.podspec +++ b/packages/react-native/ReactCommon/jsitooling/React-jsitooling.podspec @@ -48,8 +48,11 @@ Pod::Spec.new do |s| s.header_mappings_dir = "./" end - s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => header_search_paths.join(" "), - "CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard() } + s.pod_target_xcconfig = { + "HEADER_SEARCH_PATHS" => header_search_paths.join(" "), + "CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(), + "DEFINES_MODULE" => "YES", + } s.dependency "React-cxxreact", version s.dependency "React-jsi", version diff --git a/packages/react-native/ReactCommon/jsitooling/react/runtime/JSRuntimeFactory.h b/packages/react-native/ReactCommon/jsitooling/react/runtime/JSRuntimeFactory.h index c60a46ab9bc..422dc9b871f 100644 --- a/packages/react-native/ReactCommon/jsitooling/react/runtime/JSRuntimeFactory.h +++ b/packages/react-native/ReactCommon/jsitooling/react/runtime/JSRuntimeFactory.h @@ -7,6 +7,8 @@ #pragma once +#ifdef __cplusplus + #include #include #include @@ -72,3 +74,5 @@ class JSIRuntimeHolder : public JSRuntime { }; } // namespace facebook::react + +#endif // __cplusplus