syncBridgeFiles function
Synchronizes generated bridge files from lib/src/generated to native project roots.
platform is the platform directory name ('ios' or 'macos'). Defaults to 'ios'.
This is needed for Apple development as CocoaPods/SPM normally uses copies instead of symlinks.
Implementation
void syncBridgeFiles(String workingDirectory, {String platform = 'ios'}) {
final generatedDir = Directory(p.join(workingDirectory, 'lib', 'src', 'generated'));
if (!generatedDir.existsSync()) return;
// Discover Apple C++ modules (ios or macos using NativeImpl.cpp).
// Their Swift bridge stubs must NOT be compiled alongside the direct C++ bridge
// (duplicate-symbol guard). Any stale copies in Classes/ must be deleted.
final appleCppModules = _discoverAppleCppModules(workingDirectory);
final pluginName = _readPluginName(workingDirectory);
final className = toPascalCase(pluginName);
// Support both legacy (CocoaPods) and modern (SPM) source layouts.
final classesDir = Directory(p.join(workingDirectory, platform, 'Classes'));
final sourcesDir = Directory(p.join(workingDirectory, platform, 'Sources', className));
if (!classesDir.existsSync() && !sourcesDir.existsSync()) return;
final targetDirs = [
if (classesDir.existsSync()) classesDir,
if (sourcesDir.existsSync()) sourcesDir,
];
_syncSwiftBridges(generatedDir, targetDirs, appleCppModules);
// The following syncs target only the CocoaPods Classes/ layout.
if (!classesDir.existsSync()) return;
_syncCppBridges(generatedDir, classesDir);
_syncCppImplStubs(workingDirectory, appleCppModules, classesDir);
}