From 6569aeb9ca9735aed3a008a9f28703a8caa64cad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Fazekas?= Date: Mon, 19 Oct 2026 06:10:55 +0200 Subject: [PATCH] fix(iOS): use the module name when rewriting module map paths of spm_dependency pods --- .../scripts/cocoapods/__tests__/spm-test.rb | 40 +++++++++++++++++-- .../react-native/scripts/cocoapods/spm.rb | 18 +++++---- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/packages/react-native/scripts/cocoapods/__tests__/spm-test.rb b/packages/react-native/scripts/cocoapods/__tests__/spm-test.rb index d3a546def0d7..4e43b5d6b3af 100644 --- a/packages/react-native/scripts/cocoapods/__tests__/spm-test.rb +++ b/packages/react-native/scripts/cocoapods/__tests__/spm-test.rb @@ -18,10 +18,14 @@ def initialize(pods_project, aggregate_targets = []) super end end - PodTargetStub = Struct.new(:name) - AggregateTargetStub = Struct.new(:name, :pod_targets, :embed_frameworks_script_path) do - def xcconfigs - {} + PodTargetStub = Struct.new(:name, :product_module_name) + AggregateTargetStub = Struct.new(:name, :pod_targets, :embed_frameworks_script_path, :xcconfigs) do + def initialize(name, pod_targets, embed_frameworks_script_path, xcconfigs = {}) + super + end + + def xcconfig_path(config_name) + Pathname(TMP_DIR) + "#{name}.#{config_name.downcase}.xcconfig" end end @@ -202,4 +206,32 @@ def test_signature_cleanup_is_added_only_to_pods_not_built_into_the_shared_produ assert_empty(phase_names.call(POD_NAME)) assert_loadable_project(project.path) end + + def test_module_map_references_use_the_module_name_of_pods_built_into_the_shared_products_dir + project = build_project(0) + project.new_target(:static_library, "rnmapbox-maps", :ios) + project.save + manager = SPMManager.new + [POD_NAME, "rnmapbox-maps"].each do |pod_name| + manager.dependency( + PodSpecStub.new(pod_name), + url: "https://github.com/rive-app/rive-ios.git", + requirement: { kind: "exactVersion", version: "6.26.0" }, + products: ["RiveRuntime"] + ) + end + flags = '$(inherited) -fmodule-map-file="${PODS_CONFIGURATION_BUILD_DIR}/%s" -fmodule-map-file="${PODS_CONFIGURATION_BUILD_DIR}/%s"' + config = Xcodeproj::Config.new( + "OTHER_CFLAGS" => flags % ["#{POD_NAME}/#{POD_NAME}.modulemap", "rnmapbox-maps/rnmapbox_maps.modulemap"], + "OTHER_SWIFT_FLAGS" => flags % ["#{POD_NAME}/#{POD_NAME}.modulemap", "rnmapbox-maps/rnmapbox_maps.modulemap"] + ) + pod_targets = [PodTargetStub.new(POD_NAME, POD_NAME), PodTargetStub.new("rnmapbox-maps", "rnmapbox_maps")] + aggregate_target = AggregateTargetStub.new("Pods-App", pod_targets, File.join(TMP_DIR, "none.sh"), { "Debug" => config }) + + manager.apply_on_post_install(InstallerStub.new(project, [aggregate_target])) + + expected = flags % ["#{POD_NAME}.modulemap", "rnmapbox_maps.modulemap"] + assert_equal(expected, config.attributes["OTHER_CFLAGS"]) + assert_equal(expected, config.attributes["OTHER_SWIFT_FLAGS"]) + end end diff --git a/packages/react-native/scripts/cocoapods/spm.rb b/packages/react-native/scripts/cocoapods/spm.rb index 63b3ce92f3a9..f08db53bd0e8 100644 --- a/packages/react-native/scripts/cocoapods/spm.rb +++ b/packages/react-native/scripts/cocoapods/spm.rb @@ -142,21 +142,25 @@ def add_signature_cleanup(project, pod_names) end # Flattening a pod's build dir moves its generated modulemap from - # "/.modulemap" to ".modulemap"; the aggregate xcconfigs - # reference the old path via -fmodule-map-file. Must mutate the in-memory - # Config attributes — later post_install steps (NewArchitectureHelper) re-save - # the same Config objects and would clobber a plain file edit. + # "/.modulemap" to ".modulemap"; the aggregate xcconfigs + # reference the old path via -fmodule-map-file. The module name differs from + # the pod name when the pod name isn't a C identifier (e.g. "rnmapbox-maps"). + # Must mutate the in-memory Config attributes — later post_install steps + # (NewArchitectureHelper) re-save the same Config objects and would clobber a + # plain file edit. def rewrite_aggregate_modulemap_references(installer, pod_names) installer.aggregate_targets.each do |aggregate_target| + pod_targets = aggregate_target.pod_targets.select { |pod_target| pod_names.include?(pod_target.name) } aggregate_target.xcconfigs.each do |config_name, config_file| %w[OTHER_CFLAGS OTHER_SWIFT_FLAGS].each do |key| value = config_file.attributes[key] next unless value - updated_value = pod_names.reduce(value) do |acc, pod_name| + updated_value = pod_targets.reduce(value) do |acc, pod_target| + module_name = pod_target.product_module_name acc.gsub( - "${PODS_CONFIGURATION_BUILD_DIR}/#{pod_name}/#{pod_name}.modulemap", - "${PODS_CONFIGURATION_BUILD_DIR}/#{pod_name}.modulemap" + "${PODS_CONFIGURATION_BUILD_DIR}/#{pod_target.name}/#{module_name}.modulemap", + "${PODS_CONFIGURATION_BUILD_DIR}/#{module_name}.modulemap" ) end config_file.attributes[key] = updated_value if updated_value != value