Skip to content

Commit e209bee

Browse files
committed
Add a slice-specific lib folder to iOS XCframeworks.
1 parent 16ea950 commit e209bee

4 files changed

Lines changed: 22 additions & 1 deletion

File tree

Apple/__main__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,12 @@ def lib_platform_files(dirname, names):
487487
or name == "build-details.json"
488488
)
489489
)
490+
elif path.parts[-1] == "lib":
491+
ignored_names = {
492+
name
493+
for name in names
494+
if name.startswith("libpython") and name.endswith(".dylib")
495+
}
490496
else:
491497
ignored_names = set()
492498

@@ -621,6 +627,12 @@ def create_xcframework(platform: str) -> str:
621627
slice_framework / "Headers/pyconfig.h",
622628
)
623629

630+
print(f" - {slice_name} shared library")
631+
# Create a simlink for the fat library
632+
shared_lib = slice_path / f"lib/libpython{version_tag}.dylib"
633+
shared_lib.parent.mkdir()
634+
shared_lib.symlink_to("../Python.framework/Python")
635+
624636
print(f" - {slice_name} architecture-specific files")
625637
for host_triple, multiarch in slice_parts.items():
626638
print(f" - {multiarch} standard library")
@@ -632,13 +644,15 @@ def create_xcframework(platform: str) -> str:
632644
framework_path(host_triple, multiarch) / "lib",
633645
package_path / "Python.xcframework/lib",
634646
ignore=lib_platform_files,
647+
symlinks=True,
635648
)
636649
has_common_stdlib = True
637650

638651
shutil.copytree(
639652
framework_path(host_triple, multiarch) / "lib",
640653
slice_path / f"lib-{arch}",
641654
ignore=lib_non_platform_files,
655+
symlinks=True,
642656
)
643657

644658
# Copy the host's pyconfig.h to an architecture-specific name.

Apple/testbed/Python.xcframework/build/utils.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ install_stdlib() {
4646
rsync -au --delete "$PROJECT_DIR/$PYTHON_XCFRAMEWORK_PATH/lib/" "$CODESIGNING_FOLDER_PATH/python/lib/"
4747
rsync -au "$PROJECT_DIR/$PYTHON_XCFRAMEWORK_PATH/$SLICE_FOLDER/lib-$ARCHS/" "$CODESIGNING_FOLDER_PATH/python/lib/"
4848
else
49-
rsync -au --delete "$PROJECT_DIR/$PYTHON_XCFRAMEWORK_PATH/$SLICE_FOLDER/lib/" "$CODESIGNING_FOLDER_PATH/python/lib/"
49+
# A single-arch framework will have a libpython symlink; that can't be included at runtime
50+
rsync -au --delete "$PROJECT_DIR/$PYTHON_XCFRAMEWORK_PATH/$SLICE_FOLDER/lib/" "$CODESIGNING_FOLDER_PATH/python/lib/" --exclude 'libpython*.dylib'
5051
fi
5152
}
5253

Makefile.pre.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,6 +3049,9 @@ frameworkinstallunversionedstructure: $(LDLIBRARY)
30493049
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)
30503050
sed 's/%VERSION%/'"`$(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import platform; print(platform.python_version())'`"'/g' < $(RESSRCDIR)/Info.plist > $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Info.plist
30513051
$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(LDLIBRARY)
3052+
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(LIBDIR)
3053+
$(LN) -fs "../$(LDLIBRARY)" "$(DESTDIR)$(prefix)/lib/libpython$(LDVERSION).dylib"
3054+
$(LN) -fs "../$(LDLIBRARY)" "$(DESTDIR)$(prefix)/lib/libpython$(VERSION).dylib"
30523055
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(BINDIR)
30533056
for file in $(srcdir)/$(RESSRCDIR)/bin/* ; do \
30543057
$(INSTALL) -m $(EXEMODE) $$file $(DESTDIR)$(BINDIR); \
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Each slice of an iOS XCframework now contains a ``lib`` folder that contains
2+
a symlink to the libpython dylib. This allows binary modules to be compiled
3+
for iOS using dynamic libreary linking, rather than Framework linking.

0 commit comments

Comments
 (0)