@@ -416,6 +416,12 @@ String EditorExportPlatformAppleEmbedded::_process_config_file_line(const Ref<Ed
416416 strnew += p_line.replace (" $modules_buildphase" , p_config.modules_buildphase ) + " \n " ;
417417 } else if (p_line.contains (" $modules_buildgrp" )) {
418418 strnew += p_line.replace (" $modules_buildgrp" , p_config.modules_buildgrp ) + " \n " ;
419+ } else if (p_line.contains (" $spm_packages" )) {
420+ strnew += p_line.replace (" $spm_packages" , p_config.spm_packages ) + " \n " ;
421+ } else if (p_line.contains (" $spm_package_refs" )) {
422+ strnew += p_line.replace (" $spm_package_refs" , p_config.spm_package_refs ) + " \n " ;
423+ } else if (p_line.contains (" $spm_package_products" )) {
424+ strnew += p_line.replace (" $spm_package_products" , p_config.spm_package_products ) + " \n " ;
419425 } else if (p_line.contains (" $name" )) {
420426 strnew += p_line.replace (" $name" , p_config.pkg_name ) + " \n " ;
421427 } else if (p_line.contains (" $bundle_identifier" )) {
@@ -1645,6 +1651,67 @@ Error EditorExportPlatformAppleEmbedded::_export_apple_embedded_plugins(const Re
16451651 p_config_data.linker_flags += result_linker_flags;
16461652 }
16471653
1654+ // SPM Packages
1655+ {
1656+ PbxId pbx_id;
1657+ pbx_id.high_bits = 0xDEB00000 ;
1658+ pbx_id.mid_bits = 0 ;
1659+ pbx_id.low_bits = 0 ;
1660+
1661+ HashMap<String, PluginConfigAppleEmbedded::SPMPackage> unique_packages;
1662+ for (int i = 0 ; i < enabled_plugins.size (); i++) {
1663+ for (const PluginConfigAppleEmbedded::SPMPackage &package : enabled_plugins[i].spm_packages ) {
1664+ if (!unique_packages.has (package.url )) {
1665+ unique_packages[package.url ] = package;
1666+ } else {
1667+ for (const String &product : package.products ) {
1668+ if (unique_packages[package.url ].products .find (product) == -1 ) {
1669+ unique_packages[package.url ].products .push_back (product);
1670+ }
1671+ }
1672+ }
1673+ }
1674+ }
1675+
1676+ Vector<String> sorted_package_urls;
1677+ for (const KeyValue<String, PluginConfigAppleEmbedded::SPMPackage> &E : unique_packages) {
1678+ sorted_package_urls.push_back (E.key );
1679+ }
1680+ sorted_package_urls.sort ();
1681+
1682+ for (const String &url : sorted_package_urls) {
1683+ const PluginConfigAppleEmbedded::SPMPackage &package = unique_packages[url];
1684+ String package_id = (++pbx_id).str ();
1685+ String package_name = package.url .get_file ().get_basename ();
1686+
1687+ p_config_data.spm_packages += vformat (" \t\t\t\t %s /* %s */,\n " , package_id, package_name);
1688+
1689+ p_config_data.spm_package_refs += vformat (" \t\t %s /* %s */ = {\n " , package_id, package_name);
1690+ p_config_data.spm_package_refs += " \t\t\t isa = XCRemoteSwiftPackageReference;\n " ;
1691+ p_config_data.spm_package_refs += vformat (" \t\t\t repositoryURL = \" %s\" ;\n " , package.url );
1692+ p_config_data.spm_package_refs += " \t\t\t requirement = {\n " ;
1693+ p_config_data.spm_package_refs += " \t\t\t\t kind = exactVersion;\n " ;
1694+ p_config_data.spm_package_refs += vformat (" \t\t\t\t version = %s;\n " , package.version );
1695+ p_config_data.spm_package_refs += " \t\t\t };\n " ;
1696+ p_config_data.spm_package_refs += " \t\t };\n " ;
1697+
1698+ for (const String &product : package.products ) {
1699+ String product_id = (++pbx_id).str ();
1700+ String build_file_id = (++pbx_id).str ();
1701+
1702+ p_config_data.spm_package_products += vformat (" \t\t %s /* %s */ = {\n " , product_id, product);
1703+ p_config_data.spm_package_products += " \t\t\t isa = XCSwiftPackageProductDependency;\n " ;
1704+ p_config_data.spm_package_products += vformat (" \t\t\t package = %s /* %s */;\n " , package_id, package_name);
1705+ p_config_data.spm_package_products += vformat (" \t\t\t productName = \" %s\" ;\n " , product);
1706+ p_config_data.spm_package_products += " \t\t };\n " ;
1707+
1708+ p_config_data.modules_buildfile += vformat (" \t\t %s /* %s in Frameworks */ = {isa = PBXBuildFile; productRef = %s /* %s */; };\n " , build_file_id, product, product_id, product);
1709+
1710+ p_config_data.modules_buildphase += vformat (" \t\t\t\t %s /* %s in Frameworks */,\n " , build_file_id, product);
1711+ }
1712+ }
1713+ }
1714+
16481715 return OK ;
16491716}
16501717
@@ -1819,11 +1886,14 @@ Error EditorExportPlatformAppleEmbedded::_export_project_helper(const Ref<Editor
18191886 String (" " ).join (_get_preset_architectures (p_preset)),
18201887 _get_linker_flags (),
18211888 _get_cpp_code (),
1822- " " ,
1823- " " ,
1824- " " ,
1825- " " ,
1826- Vector<String>(),
1889+ " " , // modules_buildfile
1890+ " " , // modules_fileref
1891+ " " , // modules_buildphase
1892+ " " , // modules_buildgrp
1893+ " " , // spm_packages
1894+ " " , // spm_package_refs
1895+ " " , // spm_package_products
1896+ Vector<String>(), // capabilities
18271897 };
18281898
18291899 config_data.plist_content += p_preset->get (" application/additional_plist_content" ).operator String () + " \n " ;
0 commit comments