Skip to content

Commit 7b0b708

Browse files
authored
gh-141692: Add a slice-specific lib folder to iOS XCframeworks. (#141693)
Modifies the iOS XCframework to include a lib folder for each slice that contains a symlinked version of the libPython dynamic library.
1 parent ce79154 commit 7b0b708

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

Apple/__main__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,12 @@ def lib_platform_files(dirname, names):
477477
or name == "build-details.json"
478478
)
479479
}
480+
elif path.parts[-1] == "lib":
481+
ignored_names = {
482+
name
483+
for name in names
484+
if name.startswith("libpython") and name.endswith(".dylib")
485+
}
480486
else:
481487
ignored_names = set()
482488

@@ -614,6 +620,12 @@ def create_xcframework(platform: str) -> str:
614620
slice_framework / "Headers/pyconfig.h",
615621
)
616622

623+
print(f" - {slice_name} shared library")
624+
# Create a simlink for the fat library
625+
shared_lib = slice_path / f"lib/libpython{version_tag}.dylib"
626+
shared_lib.parent.mkdir()
627+
shared_lib.symlink_to("../Python.framework/Python")
628+
617629
print(f" - {slice_name} architecture-specific files")
618630
for host_triple, multiarch in slice_parts.items():
619631
print(f" - {multiarch} standard library")
@@ -625,13 +637,15 @@ def create_xcframework(platform: str) -> str:
625637
framework_path(host_triple, multiarch) / "lib",
626638
package_path / "Python.xcframework/lib",
627639
ignore=lib_platform_files,
640+
symlinks=True,
628641
)
629642
has_common_stdlib = True
630643

631644
shutil.copytree(
632645
framework_path(host_triple, multiarch) / "lib",
633646
slice_path / f"lib-{arch}",
634647
ignore=lib_non_platform_files,
648+
symlinks=True,
635649
)
636650

637651
# 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
@@ -3050,6 +3050,9 @@ frameworkinstallunversionedstructure: $(LDLIBRARY)
30503050
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)
30513051
sed 's/%VERSION%/'"`$(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import platform; print(platform.python_version())'`"'/g' < $(RESSRCDIR)/Info.plist > $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Info.plist
30523052
$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(LDLIBRARY)
3053+
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(LIBDIR)
3054+
$(LN) -fs "../$(LDLIBRARY)" "$(DESTDIR)$(prefix)/lib/libpython$(LDVERSION).dylib"
3055+
$(LN) -fs "../$(LDLIBRARY)" "$(DESTDIR)$(prefix)/lib/libpython$(VERSION).dylib"
30533056
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(BINDIR)
30543057
for file in $(srcdir)/$(RESSRCDIR)/bin/* ; do \
30553058
$(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)