|
| 1 | +import os |
| 2 | +import shutil |
| 3 | +import subprocess |
| 4 | + |
| 5 | +from script_config import ScriptConfig, ArchiveConfig |
| 6 | + |
| 7 | + |
| 8 | +def parse_config() -> ScriptConfig: |
| 9 | + config = ScriptConfig.parse(allow_ldk_argument=True, parse_configuration=True) |
| 10 | + |
| 11 | + individual_configurations: [ArchiveConfig] = [ |
| 12 | + ArchiveConfig('iOS Simulator', 'iphonesimulator'), |
| 13 | + ArchiveConfig('iOS', 'iphoneos'), |
| 14 | + ArchiveConfig('OS X', 'macosx'), |
| 15 | + ArchiveConfig('macOS,variant=Mac Catalyst', 'catalyst'), |
| 16 | + ] |
| 17 | + config.XCARCHIVE_GENERATION_CONFIGURATIONS = individual_configurations |
| 18 | + |
| 19 | + return config |
| 20 | + |
| 21 | + |
| 22 | +def run(config: ScriptConfig): |
| 23 | + build_products_directory = os.path.realpath(os.path.join(os.path.dirname(__file__), '../../bindings/bin')) |
| 24 | + xcode_project_path = os.path.realpath( |
| 25 | + os.path.join(os.path.dirname(__file__), '../../xcode/LDKFramework/LDKFramework.xcodeproj') |
| 26 | + ) |
| 27 | + framework_input_flags: [str] = [] |
| 28 | + xcframework_output_path = os.path.join( |
| 29 | + build_products_directory, |
| 30 | + config.RUST_CONFIGURATION, |
| 31 | + 'LDKFramework.xcframework' |
| 32 | + ) |
| 33 | + |
| 34 | + child_environment = dict(os.environ) |
| 35 | + child_environment['LDK_C_BINDINGS_BASE'] = config.LDK_C_BINDINGS_BASE |
| 36 | + |
| 37 | + archive_configurations = config.XCARCHIVE_GENERATION_CONFIGURATIONS |
| 38 | + for current_configuration in archive_configurations: |
| 39 | + current_destination = current_configuration.destination |
| 40 | + current_human_readable_platform = current_configuration.human_readable_platform |
| 41 | + |
| 42 | + lipo_binary_directory = os.path.join( |
| 43 | + build_products_directory, |
| 44 | + config.RUST_CONFIGURATION, |
| 45 | + current_human_readable_platform, |
| 46 | + ) |
| 47 | + derived_data_directory = os.path.join( |
| 48 | + build_products_directory, |
| 49 | + config.RUST_CONFIGURATION, |
| 50 | + current_human_readable_platform, |
| 51 | + 'DerivedData' |
| 52 | + ) |
| 53 | + xcarchive_output_path = os.path.join( |
| 54 | + build_products_directory, |
| 55 | + config.RUST_CONFIGURATION, |
| 56 | + current_human_readable_platform, |
| 57 | + current_human_readable_platform # the last component is the filename excluding .xcarchive |
| 58 | + ) |
| 59 | + |
| 60 | + # create clean derived data directory |
| 61 | + if os.path.exists(derived_data_directory): |
| 62 | + shutil.rmtree(derived_data_directory) |
| 63 | + os.makedirs(derived_data_directory, exist_ok=False) |
| 64 | + |
| 65 | + child_environment['LDK_C_BINDINGS_BINARY_DIRECTORY'] = lipo_binary_directory |
| 66 | + |
| 67 | + # xcodebuild archive -verbose -project "${BASEDIR}/LDKFramework/LDKFramework.xcodeproj" -scheme LDKFramework -destination "generic/platform=${CURRENT_DESTINATION_NAME}" -derivedDataPath "${CURRENT_DERIVED_DATA_DIRECTORY}" -archivePath "${CURRENT_ARCHIVE_PATH}" ENABLE_BITCODE=NO EXCLUDED_ARCHS="i386 armv7" SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES LDK_C_BINDINGS_BASE="${LDK_DIRECTORY}" LDK_C_BINDINGS_BINARY_DIRECTORY="${CURRENT_LIPO_DIRECTORY_PATH}" |
| 68 | + subprocess.check_call( |
| 69 | + [ |
| 70 | + 'xcodebuild', |
| 71 | + 'archive', |
| 72 | + '-verbose', |
| 73 | + '-project', |
| 74 | + xcode_project_path, |
| 75 | + '-scheme', |
| 76 | + 'LDKFramework', |
| 77 | + '-destination', |
| 78 | + f'generic/platform={current_destination}', |
| 79 | + '-derivedDataPath', |
| 80 | + derived_data_directory, |
| 81 | + '-archivePath', |
| 82 | + xcarchive_output_path, |
| 83 | + 'ENABLE_BITCODE=NO', |
| 84 | + 'EXCLUDED_ARCHS="i386 armv7"', |
| 85 | + 'SKIP_INSTALL=NO', |
| 86 | + 'BUILD_LIBRARY_FOR_DISTRIBUTION=YES', |
| 87 | + f'LDK_C_BINDINGS_BASE="{config.LDK_C_BINDINGS_BASE}"', |
| 88 | + f'LDK_C_BINDINGS_BINARY_DIRECTORY="{lipo_binary_directory}"', |
| 89 | + f'LDK_C_BINDINGS_BINARY_DIRECTORY_OVERRIDE=""', |
| 90 | + ], env=child_environment |
| 91 | + ) |
| 92 | + |
| 93 | + # clean up the derived data |
| 94 | + shutil.rmtree(derived_data_directory) |
| 95 | + |
| 96 | + # XCFRAMEWORK_INPUT_FLAGS="${XCFRAMEWORK_INPUT_FLAGS}-framework ${CURRENT_ARCHIVE_PATH}.xcarchive/Products/Library/Frameworks/LDKFramework.framework " |
| 97 | + framework_input_flags += ['-framework', f'{xcarchive_output_path}.xcarchive/Products/Library/Frameworks/LDKFramework.framework'] |
| 98 | + |
| 99 | + # xcodebuild -create-xcframework ${XCFRAMEWORK_INPUT_FLAGS} -output ${XCFRAMEWORK_OUTPUT_PATH}" |
| 100 | + if os.path.exists(xcframework_output_path): |
| 101 | + shutil.rmtree(xcframework_output_path) |
| 102 | + subprocess.check_call(['xcodebuild', '-create-xcframework', *framework_input_flags, '-output', xcframework_output_path]) |
| 103 | + |
| 104 | + |
| 105 | +if __name__ == '__main__': |
| 106 | + script_config = parse_config() |
| 107 | + run(script_config) |
0 commit comments