Build an XCframework from the component parts for the platform. :return: The version number of the Python version that was packaged.
(platform: str)
| 514 | |
| 515 | |
| 516 | def create_xcframework(platform: str) -> str: |
| 517 | """Build an XCframework from the component parts for the platform. |
| 518 | |
| 519 | :return: The version number of the Python version that was packaged. |
| 520 | """ |
| 521 | package_path = CROSS_BUILD_DIR / platform |
| 522 | try: |
| 523 | package_path.mkdir() |
| 524 | except FileExistsError: |
| 525 | raise RuntimeError( |
| 526 | f"{platform} XCframework already exists; do you need to run " |
| 527 | "with --clean?" |
| 528 | ) from None |
| 529 | |
| 530 | frameworks = [] |
| 531 | # Merge Frameworks for each component SDK. If there's only one architecture |
| 532 | # for the SDK, we can use the compiled Python.framework as-is. However, if |
| 533 | # there's more than architecture, we need to merge the individual built |
| 534 | # frameworks into a merged "fat" framework. |
| 535 | for slice_name, slice_parts in HOSTS[platform].items(): |
| 536 | # Some parts are the same across all slices, so we use can any of the |
| 537 | # host frameworks as the source for the merged version. Use the first |
| 538 | # one on the list, as it's as representative as any other. |
| 539 | first_host_triple, first_multiarch = next(iter(slice_parts.items())) |
| 540 | first_framework = ( |
| 541 | framework_path(first_host_triple, first_multiarch) |
| 542 | / "Python.framework" |
| 543 | ) |
| 544 | |
| 545 | if len(slice_parts) == 1: |
| 546 | # The first framework is the only framework, so copy it. |
| 547 | print(f"Copying framework for {slice_name}...") |
| 548 | frameworks.append(first_framework) |
| 549 | else: |
| 550 | print(f"Merging framework for {slice_name}...") |
| 551 | slice_path = CROSS_BUILD_DIR / slice_name |
| 552 | slice_framework = slice_path / "Python.framework" |
| 553 | slice_framework.mkdir(exist_ok=True, parents=True) |
| 554 | |
| 555 | # Copy the Info.plist |
| 556 | shutil.copy( |
| 557 | first_framework / "Info.plist", |
| 558 | slice_framework / "Info.plist", |
| 559 | ) |
| 560 | |
| 561 | # Copy the headers |
| 562 | shutil.copytree( |
| 563 | first_framework / "Headers", |
| 564 | slice_framework / "Headers", |
| 565 | ) |
| 566 | |
| 567 | # Create the "fat" library binary for the slice |
| 568 | run( |
| 569 | ["lipo", "-create", "-output", slice_framework / "Python"] |
| 570 | + [ |
| 571 | ( |
| 572 | framework_path(host_triple, multiarch) |
| 573 | / "Python.framework/Python" |
no test coverage detected
searching dependent graphs…