OK, it works fine now, thanks to Xcode team! Successfully tested with Xcode 13.2.1, 13.3.1, 13.4.1 and 14 beta 5.
Here is the sample code.
Technical explanation is detailed in the WWDC22 session Debug Swift debugging with LLDB.
Short solution, in many cases.
Use a Debug.xcconfig
file dedicated to DEBUG
configuration.
// Xcode 13.3+
OTHER_LDFLAGS = -Wl,-add_ast_path,$(TARGET_BUILD_DIR)/InternalFramework.framework/Modules/InternalFramework.swiftmodule/$(NATIVE_ARCH_ACTUAL)-apple-$(SHALLOW_BUNDLE_TRIPLE).swiftmodule
// Xcode 13.2
OTHER_LDFLAGS[sdk=iphoneos15.2] = -Wl,-add_ast_path,$(TARGET_BUILD_DIR)/InternalFramework.framework/Modules/InternalFramework.swiftmodule/$(NATIVE_ARCH_ACTUAL)-apple-ios.swiftmodule
OTHER_LDFLAGS[sdk=iphonesimulator15.2] = -Wl,-add_ast_path,$(TARGET_BUILD_DIR)/InternalFramework.framework/Modules/InternalFramework.swiftmodule/$(NATIVE_ARCH_ACTUAL)-apple-simulator.swiftmodule
Use a Debug.xcconfig
file dedicated to DEBUG
configuration.
// Xcode 13.3+
OTHER_LDFLAGS = -Wl,-add_ast_path,$(TARGET_BUILD_DIR)/InternalStaticLibrary.swiftmodule/$(NATIVE_ARCH_ACTUAL)-apple-$(SHALLOW_BUNDLE_TRIPLE).swiftmodule
// Xcode 13.2
OTHER_LDFLAGS[sdk=iphoneos15.2] = -Wl,-add_ast_path,$(TARGET_BUILD_DIR)/InternalStaticLibrary.swiftmodule/$(NATIVE_ARCH_ACTUAL)-apple-ios.swiftmodule
OTHER_LDFLAGS[sdk=iphonesimulator15.2] = -Wl,-add_ast_path,$(TARGET_BUILD_DIR)/InternalStaticLibrary.swiftmodule/$(NATIVE_ARCH_ACTUAL)-apple-simulator.swiftmodule
Update Podfile
with this code.
post_integrate do |installer|
xcconfig_path = installer.sandbox.target_support_files_root.to_s + '/Pods-App/Pods-App.debug.xcconfig'
xcconfig_content = File.read xcconfig_path
xcconfig_original_ld_flags = xcconfig_content.match(/OTHER_LDFLAGS = ([^\n]+)\n/)[1]
xcconfig_new_ld_flags = <<~CONTENT
// Xcode 13.3+
OTHER_LDFLAGS = #{xcconfig_original_ld_flags} -Wl,-add_ast_path,$(TARGET_BUILD_DIR)/InternalPod/InternalPod.framework/Modules/InternalPod.swiftmodule/$(NATIVE_ARCH_ACTUAL)-apple-$(SHALLOW_BUNDLE_TRIPLE).swiftmodule
// Xcode 13.2
OTHER_LDFLAGS[sdk=iphoneos15.2] = #{xcconfig_original_ld_flags} -Wl,-add_ast_path,$(TARGET_BUILD_DIR)/InternalPod/InternalPod.framework/Modules/InternalPod.swiftmodule/$(NATIVE_ARCH_ACTUAL)-apple-ios.swiftmodule
OTHER_LDFLAGS[sdk=iphonesimulator15.2] = #{xcconfig_original_ld_flags} -Wl,-add_ast_path,$(TARGET_BUILD_DIR)/InternalPod/InternalPod.framework/Modules/InternalPod.swiftmodule/$(NATIVE_ARCH_ACTUAL)-apple-simulator.swiftmodule
CONTENT
xcconfig_content.gsub! /OTHER_LDFLAGS = ([^\n]+)\n/, xcconfig_new_ld_flags
File.open(xcconfig_path, 'w') do |f|
f.puts xcconfig_content
end
end