[iOS][precompile] Support dynamic static linkage with prebuilts (#53477)

* [ios][precompile] Add use_frameworks resolve method

To be able to handle cocoapods USE_FRAMEWORKS with both dynamic/static linkage and precompiled we needed a common way to resolve this.

The issue was that when using precompiled and USE_FRAMEWORKS our precompiled framework caused the resulting Pods project to only include header files - hence there where no need to change the header_mappings_dir which a lot of the podspecs did.

A method was added that handles this in a common way.

* [ios][precompile] added resolve_use_frameworks to podspecs

Replaced logic for resolving header mappings and module name using the new method `resolve_use_frameworks` in all podspecs.

Also added `React-oscompat` dependency on `React-jsiinspector_modern` which failed when linkage was "dynamic".

* [ios][precompile] added explicit handling of ReactCoden

When using precompiled and building with frameworks (USE_FRAMEWORKS) we need to explicitly add the correct path to ReactCodegen when calling `create_header_search_path_for_frameworks` to ensure libraries can access their codegen files.

This commit adds an explicit check to make sure we add the correct path when using frameworks and the pod is ReactCodegen.

Added includes in the NativeCXXModuleExample.cpp file to test this.

* Update packages/react-native/scripts/cocoapods/utils.rb

Co-authored-by: Riccardo Cipolleschi <cipolleschi@meta.com>

* codereview: removed test include files

* codereview: fixed issue in ruby.rb

After a github `suggestion` we had a superfluous `end`. Sorry for that.

---------

Co-authored-by: Christian Falch <christian.falch@gmail.com>
Co-authored-by: Christian Falch <875252+chrfalch@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2025-08-27 10:24:51 +01:00
1 parent 7404fb620b
commit 6526a98d68
38 files changed
+78 -134

No files matched your search

@@ -45,10 +45,7 @@ Pod::Spec.new do |s|
"HEADER_SEARCH_PATHS" => header_search_paths.join(' '),
}
if ENV['USE_FRAMEWORKS']
s.header_mappings_dir = 'FBReactNativeSpec'
s.module_name = 'React_RCTFBReactNativeSpec'
end
resolve_use_frameworks(s, header_mappings_dir: 'FBReactNativeSpec', module_name: "React_RCTFBReactNativeSpec")
s.dependency "React-jsi"
s.dependency "RCTRequired"
@@ -35,9 +35,7 @@ Pod::Spec.new do |s|
s.header_dir = header_dir
s.module_name = module_name
if ENV['USE_FRAMEWORKS']
s.header_mappings_dir = "./"
end
resolve_use_frameworks(s, header_mappings_dir: "./")
s.pod_target_xcconfig = {
"OTHER_CFLAGS" => "$(inherited) " + new_arch_flags,
@@ -32,10 +32,7 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"DEFINES_MODULE" => "YES" }
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
s.header_mappings_dir = './'
s.module_name = 'React_Fabric'
end
resolve_use_frameworks(s, header_mappings_dir: "./", module_name: "React_Fabric")
s.dependency "React-jsiexecutor"
s.dependency "RCTRequired"
@@ -49,10 +49,7 @@ Pod::Spec.new do |s|
"HEADER_SEARCH_PATHS" => header_search_path.join(" "),
}
if ENV['USE_FRAMEWORKS']
s.header_mappings_dir = './'
s.module_name = 'React_FabricComponents'
end
resolve_use_frameworks(s, header_mappings_dir: "./", module_name: "React_FabricComponents")
s.dependency "React-jsiexecutor"
s.dependency "RCTRequired"
@@ -50,10 +50,7 @@ Pod::Spec.new do |s|
"HEADER_SEARCH_PATHS" => header_search_path.join(" ")
}
if ENV['USE_FRAMEWORKS']
s.header_mappings_dir = './'
s.module_name = 'React_FabricImage'
end
resolve_use_frameworks(s, header_mappings_dir: './', module_name: "React_FabricImage")
s.dependency "React-jsiexecutor", version
s.dependency "RCTRequired", version
@@ -32,10 +32,7 @@ Pod::Spec.new do |s|
s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => ["\"$(PODS_TARGET_SRCROOT)\""], "USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard() }
if ENV['USE_FRAMEWORKS']
s.header_mappings_dir = './'
s.module_name = 'React_Mapbuffer'
end
resolve_use_frameworks(s, header_mappings_dir: './', module_name: "React_Mapbuffer")
add_dependency(s, "React-debug")
add_rn_third_party_dependencies(s)
@@ -32,9 +32,8 @@ Pod::Spec.new do |s|
"DEFINES_MODULE" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"GCC_WARN_PEDANTIC" => "YES" }
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
s.header_mappings_dir = './'
end
resolve_use_frameworks(s, header_mappings_dir: './')
add_rn_third_party_dependencies(s)
add_rncore_dependency(s)
@@ -32,10 +32,7 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"GCC_WARN_PEDANTIC" => "YES" }
if ENV['USE_FRAMEWORKS']
s.header_mappings_dir = './'
s.module_name = 'React_jsitracing'
end
resolve_use_frameworks(s, header_mappings_dir: './', module_name: "React_jsitracing")
s.dependency "React-jsi"
end
@@ -33,10 +33,8 @@ Pod::Spec.new do |s|
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard()
}
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
s.header_mappings_dir = '../'
s.module_name = 'React_jserrorhandler'
end
resolve_use_frameworks(s, header_mappings_dir: '../', module_name: "React_jserrorhandler")
s.dependency "React-jsi"
s.dependency "React-cxxreact"
@@ -44,10 +44,9 @@ Pod::Spec.new do |s|
"PUBLIC_HEADERS_FOLDER_PATH" => "#{module_name}.framework/Headers/#{header_dir}"
} : {})
if ENV['USE_FRAMEWORKS']
s.module_name = module_name
end
resolve_use_frameworks(s, module_name: module_name)
add_dependency(s, "React-oscompat") # Needed for USE_FRAMEWORKS=dynamic
s.dependency "React-featureflags"
add_dependency(s, "React-runtimeexecutor", :additional_framework_paths => ["platform/ios"])
s.dependency "React-jsi"
@@ -41,10 +41,7 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"DEFINES_MODULE" => "YES"}
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
s.module_name = module_name
s.header_mappings_dir = "../.."
end
resolve_use_frameworks(s, header_mappings_dir: "../..", module_name: module_name)
add_rn_third_party_dependencies(s)
add_rncore_dependency(s)
@@ -41,10 +41,7 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"DEFINES_MODULE" => "YES"}
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
s.module_name = module_name
s.header_mappings_dir = "../.."
end
resolve_use_frameworks(s, header_mappings_dir: "../..", module_name: module_name)
add_dependency(s, "React-jsinspectorcdp", :framework_name => 'jsinspector_moderncdp')
add_dependency(s, "React-featureflags")
@@ -41,10 +41,7 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"DEFINES_MODULE" => "YES"}
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
s.module_name = module_name
s.header_mappings_dir = "../.."
end
resolve_use_frameworks(s, header_mappings_dir: "../..", module_name: module_name)
s.dependency "React-oscompat"
s.dependency "React-timing"
@@ -28,10 +28,7 @@ Pod::Spec.new do |s|
s.source_files = podspec_sources("react/runtime/*.{cpp,h}", "react/runtime/*.h")
s.header_dir = "react/runtime"
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
s.module_name = "JSITooling"
s.header_mappings_dir = "./"
end
resolve_use_frameworks(s, header_mappings_dir: "./", module_name: "JSITooling")
s.pod_target_xcconfig = {
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
@@ -30,8 +30,5 @@ Pod::Spec.new do |s|
s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"DEFINES_MODULE" => "YES" }
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
s.module_name = "React_debug"
s.header_mappings_dir = "../.."
end
resolve_use_frameworks(s, header_mappings_dir: "../..", module_name: "React_debug")
end
@@ -37,10 +37,7 @@ Pod::Spec.new do |s|
"HEADER_SEARCH_PATHS" => header_search_paths.join(' '),
"DEFINES_MODULE" => "YES" }
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
s.module_name = "React_featureflags"
s.header_mappings_dir = "../.."
end
resolve_use_frameworks(s, header_mappings_dir: "../..", module_name: "React_featureflags")
add_rn_third_party_dependencies(s)
add_rncore_dependency(s)
@@ -31,9 +31,8 @@ Pod::Spec.new do |s|
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"GCC_WARN_PEDANTIC" => "YES" }
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
s.header_mappings_dir = './'
end
resolve_use_frameworks(s, header_mappings_dir: './')
s.source_files = podspec_sources("ReactCommon/**/*.{mm,cpp,h}", "ReactCommon/**/*.{h}")
@@ -38,10 +38,7 @@ Pod::Spec.new do |s|
"OTHER_CFLAGS" => "$(inherited)",
"DEFINES_MODULE" => "YES" }
if ENV['USE_FRAMEWORKS']
s.module_name = "React_defaultsnativemodule"
s.header_mappings_dir = "../.."
end
resolve_use_frameworks(s, header_mappings_dir: "../..", module_name: "React_defaultsnativemodule")
s.dependency "React-jsi"
s.dependency "React-jsiexecutor"
@@ -40,10 +40,7 @@ Pod::Spec.new do |s|
"OTHER_CFLAGS" => "$(inherited)",
"DEFINES_MODULE" => "YES" }
if ENV['USE_FRAMEWORKS']
s.module_name = "React_domnativemodule"
s.header_mappings_dir = "../.."
end
resolve_use_frameworks(s, header_mappings_dir: "../..", module_name: "React_domnativemodule")
s.dependency "React-jsi"
s.dependency "React-jsiexecutor"
@@ -38,10 +38,7 @@ Pod::Spec.new do |s|
"OTHER_CFLAGS" => "$(inherited)",
"DEFINES_MODULE" => "YES" }
if ENV['USE_FRAMEWORKS']
s.module_name = "React_featureflagsnativemodule"
s.header_mappings_dir = "../.."
end
resolve_use_frameworks(s, header_mappings_dir: "../..", module_name: "React_featureflagsnativemodule")
s.dependency "React-jsi"
s.dependency "React-jsiexecutor"
@@ -38,10 +38,7 @@ Pod::Spec.new do |s|
"OTHER_CFLAGS" => "$(inherited)",
"DEFINES_MODULE" => "YES" }
if ENV['USE_FRAMEWORKS']
s.module_name = "idlecallbacksnativemodule"
s.header_mappings_dir = "../.."
end
resolve_use_frameworks(s, header_mappings_dir: "../..", module_name: "idlecallbacksnativemodule")
s.dependency "React-jsi"
s.dependency "React-jsiexecutor"
@@ -38,10 +38,7 @@ Pod::Spec.new do |s|
"HEADER_SEARCH_PATHS" => header_search_paths.join(' '),
"DEFINES_MODULE" => "YES" }
if ENV['USE_FRAMEWORKS']
s.module_name = "React_microtasksnativemodule"
s.header_mappings_dir = "../.."
end
resolve_use_frameworks(s, header_mappings_dir: "../..", module_name: "React_microtasksnativemodule")
s.dependency "React-jsi"
s.dependency "React-jsiexecutor"
@@ -40,6 +40,8 @@ Pod::Spec.new do |s|
s.framework = "UIKit"
if ENV['USE_FRAMEWORKS']
# Do not use resolve_use_frameworks here - since we're including source files.
# Then it is not needed.
s.header_mappings_dir = './'
end
@@ -38,10 +38,7 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"HEADER_SEARCH_PATHS" => header_search_paths.join(' ')}
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
s.module_name = "React_performancetimeline"
s.header_mappings_dir = "../../.."
end
resolve_use_frameworks(s, header_mappings_dir: "../../..", module_name: "React_performancetimeline")
s.dependency "React-featureflags"
add_dependency(s, "React-jsinspectortracing", :framework_name => 'jsinspector_moderntracing')
@@ -38,8 +38,6 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"HEADER_SEARCH_PATHS" => header_search_paths.join(' ')}
if ENV['USE_FRAMEWORKS']
s.module_name = "React_rendererconsistency"
s.header_mappings_dir = "../../.."
end
resolve_use_frameworks(s, header_mappings_dir: "../../..", module_name: "React_rendererconsistency")
end
@@ -18,7 +18,7 @@ end
header_search_paths = []
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
if ENV['USE_FRAMEWORKS']
header_search_paths << "\"$(PODS_TARGET_SRCROOT)/../../..\"" # this is needed to allow the renderer/css access its own files
end
@@ -40,10 +40,7 @@ Pod::Spec.new do |s|
"DEFINES_MODULE" => "YES",
}
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
s.module_name = "React_renderercss"
s.header_mappings_dir = "../../.."
end
resolve_use_frameworks(s, header_mappings_dir: "../../..", module_name: "React_renderercss")
add_dependency(s, "React-debug")
add_dependency(s, "React-utils")
@@ -40,10 +40,7 @@ Pod::Spec.new do |s|
"DEFINES_MODULE" => "YES"
}
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
s.module_name = "React_rendererdebug"
s.header_mappings_dir = "../../.."
end
resolve_use_frameworks(s, header_mappings_dir: "../../..", module_name: "React_rendererdebug")
add_dependency(s, "React-debug")
add_rn_third_party_dependencies(s)
@@ -34,12 +34,12 @@ Pod::Spec.new do |s|
s.header_dir = "react/renderer/graphics"
s.framework = "UIKit"
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
s.module_name = "React_graphics"
s.header_mappings_dir = "../../.."
if ENV['USE_FRAMEWORKS']
header_search_paths = header_search_paths + ["\"$(PODS_TARGET_SRCROOT)/platform/ios\""]
end
resolve_use_frameworks(s, header_mappings_dir: "../../..", module_name: "React_graphics")
s.pod_target_xcconfig = { "USE_HEADERMAP" => "NO",
"HEADER_SEARCH_PATHS" => header_search_paths.join(" "),
"DEFINES_MODULE" => "YES",
@@ -34,10 +34,7 @@ Pod::Spec.new do |s|
s.source_files = podspec_sources(source_files, "**/*.h")
s.header_dir = "react/renderer/imagemanager"
if ENV['USE_FRAMEWORKS']
s.module_name = "React_ImageManager"
s.header_mappings_dir = "./"
end
resolve_use_frameworks(s, header_mappings_dir: "./", module_name: "React_ImageManager")
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "NO",
@@ -38,10 +38,7 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"HEADER_SEARCH_PATHS" => header_search_paths.join(' ')}
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
s.module_name = "React_runtimescheduler"
s.header_mappings_dir = "../../.."
end
resolve_use_frameworks(s, header_mappings_dir: "../../..", module_name: "React_runtimescheduler")
add_dependency(s, "React-runtimeexecutor", :additional_framework_paths => ["platform/ios"])
s.dependency "React-callinvoker"
@@ -33,10 +33,7 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"GCC_WARN_PEDANTIC" => "YES" }
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
s.header_mappings_dir = '../../'
s.module_name = 'React_RuntimeCore'
end
resolve_use_frameworks(s, header_mappings_dir: "../..", module_name: "React_RuntimeCore")
s.dependency "React-jsiexecutor"
s.dependency "React-cxxreact"
@@ -32,10 +32,7 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"GCC_WARN_PEDANTIC" => "YES" }
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
s.header_mappings_dir = '../../'
s.module_name = 'React_RuntimeHermes'
end
resolve_use_frameworks(s, header_mappings_dir: "../../", module_name: "React_RuntimeHermes")
s.dependency "React-jsitracing"
s.dependency "React-jsi"
@@ -38,10 +38,7 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"GCC_WARN_PEDANTIC" => "YES" }
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
s.header_mappings_dir = './'
s.module_name = 'React_RuntimeApple'
end
resolve_use_frameworks(s, header_mappings_dir: "./", module_name: "React_RuntimeApple")
s.dependency "React-jsiexecutor"
s.dependency "React-cxxreact"
@@ -37,8 +37,7 @@ Pod::Spec.new do |s|
"HEADER_SEARCH_PATHS" => header_search_paths.join(' '),
"DEFINES_MODULE" => "YES" }
if ENV['USE_FRAMEWORKS']
s.module_name = "React_timing"
s.header_mappings_dir = "./"
end
resolve_use_frameworks(s, header_mappings_dir: "./", module_name: "React_timing")
add_dependency(s, "React-debug")
end
@@ -34,12 +34,12 @@ Pod::Spec.new do |s|
s.header_dir = "react/utils"
s.exclude_files = "tests"
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
s.module_name = "React_utils"
s.header_mappings_dir = "../.."
if ENV['USE_FRAMEWORKS']
header_search_paths = header_search_paths + ["\"$(PODS_TARGET_SRCROOT)/platform/ios\""]
end
resolve_use_frameworks(s, header_mappings_dir: "../..", module_name: "React_utils")
s.pod_target_xcconfig = { "USE_HEADERMAP" => "NO",
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"HEADER_SEARCH_PATHS" => header_search_paths.join(' '),
@@ -33,11 +33,12 @@ Pod::Spec.new do |s|
s.source_files = podspec_sources(["ReactCommon/*.{m,mm,cpp,h}", "platform/ios/**/*.{m,mm,cpp,h}"], ["ReactCommon/*.h", "platform/ios/**/*.h"])
s.header_dir = "ReactCommon"
if ENV['USE_FRAMEWORKS'] && ReactNativeCoreUtils.build_rncore_from_source()
s.header_mappings_dir = '.'
if ENV['USE_FRAMEWORKS']
header_search_paths = header_search_paths + ["\"$(PODS_TARGET_SRCROOT)/platform/ios\""]
end
resolve_use_frameworks(s, header_mappings_dir: ".")
s.pod_target_xcconfig = { "USE_HEADERMAP" => "NO",
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"HEADER_SEARCH_PATHS" => header_search_paths.join(' '),
@@ -258,7 +258,8 @@ class ReactNativePodsUtils
search_paths = []
# When building using the prebuilt rncore we can't use framework folders as search paths since these aren't created
if ReactNativeCoreUtils.build_rncore_from_source()
# Except for when adding search path for ReactCodegen since it contains source code.
if ReactNativeCoreUtils.build_rncore_from_source() || pod_name === "ReactCodegen"
platforms = $RN_PLATFORMS != nil ? $RN_PLATFORMS : []
if platforms.empty?() || platforms.length() == 1
@@ -699,4 +700,15 @@ class ReactNativePodsUtils
end
end
end
def self.resolve_use_frameworks(spec, header_mappings_dir: nil, module_name: nil)
return unless ENV['USE_FRAMEWORKS']
if module_name
spec.module_name = module_name
end
if header_mappings_dir != nil && ReactNativeCoreUtils.build_rncore_from_source()
spec.header_mappings_dir = header_mappings_dir
end
end
end
@@ -229,6 +229,20 @@ def folly_flags()
return NewArchitectureHelper.folly_compiler_flags
end
# Resolve the spec for use with the USE_FRAMEWORKS environment variable. To avoid each podspec
# to manually specify the header mappings and module name, we can use this helper function.
# This helper will also resolve header mappings if we're building from source. Precompiled
# React-Core will not generate frameworks since their podspec files only contains the
# header files and no source code - so header_mappings should be the same as for without USE_FRAMEWORKS
#
# Parameters:
# - s: the spec to modify
# - header_mappings_dir: the directory to map headers when building Pod header structure
# - module_name: the name of the module when exposed to swift
def resolve_use_frameworks(spec, header_mappings_dir: nil, module_name: nil)
ReactNativePodsUtils.resolve_use_frameworks(spec, :header_mappings_dir => header_mappings_dir, :module_name => module_name)
end
# Add a dependency to a spec, making sure that the HEADER_SERACH_PATHS are set properly.
# This function automate the requirement to specify the HEADER_SEARCH_PATHS which was error prone
# and hard to pull out properly to begin with.