Skip to content

Commit fcf612e

Browse files
committed
[3.11] pythongh-114099: Add configure and Makefile targets to support iOS compilation. (pythonGH-115390)
1 parent 83b614a commit fcf612e

20 files changed

+901
-120
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Lib/test/data/*
6565
/_bootstrap_python
6666
/Makefile
6767
/Makefile.pre
68+
iOS/Resources/Info.plist
6869
Mac/Makefile
6970
Mac/PythonLauncher/Info.plist
7071
Mac/PythonLauncher/Makefile

Makefile.pre.in

+54-3
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,21 @@ $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK): \
811811
$(LN) -fsn Versions/Current/$(PYTHONFRAMEWORK) $(PYTHONFRAMEWORKDIR)/$(PYTHONFRAMEWORK)
812812
$(LN) -fsn Versions/Current/Resources $(PYTHONFRAMEWORKDIR)/Resources
813813

814+
# This rule is for iOS, which requires an annoyingly just slighly different
815+
# format for frameworks to macOS. It *doesn't* use a versioned framework, and
816+
# the Info.plist must be in the root of the framework.
817+
$(PYTHONFRAMEWORKDIR)/$(PYTHONFRAMEWORK): \
818+
$(LIBRARY) \
819+
$(RESSRCDIR)/Info.plist
820+
$(INSTALL) -d -m $(DIRMODE) $(PYTHONFRAMEWORKDIR)
821+
$(CC) -o $(LDLIBRARY) $(PY_CORE_LDFLAGS) -dynamiclib \
822+
-all_load $(LIBRARY) \
823+
-install_name $(PYTHONFRAMEWORKINSTALLNAMEPREFIX)/$(PYTHONFRAMEWORK) \
824+
-compatibility_version $(VERSION) \
825+
-current_version $(VERSION) \
826+
-framework CoreFoundation $(LIBS);
827+
$(INSTALL_DATA) $(RESSRCDIR)/Info.plist $(PYTHONFRAMEWORKDIR)/Info.plist
828+
814829
# This rule builds the Cygwin Python DLL and import library if configured
815830
# for a shared core library; otherwise, this rule is a noop.
816831
$(DLLLIBRARY) libpython$(LDVERSION).dll.a: $(LIBRARY_OBJS)
@@ -2319,9 +2334,11 @@ frameworkinstall: install
23192334
# automatically set prefix to the location deep down in the framework, so we
23202335
# only have to cater for the structural bits of the framework.
23212336

2322-
frameworkinstallframework: frameworkinstallstructure install frameworkinstallmaclib
2337+
frameworkinstallframework: @FRAMEWORKINSTALLFIRST@ install frameworkinstallmaclib
23232338

2324-
frameworkinstallstructure: $(LDLIBRARY)
2339+
# macOS uses a versioned frameworks structure that includes a full install
2340+
.PHONY: frameworkinstallversionedstructure
2341+
frameworkinstallversionedstructure: $(LDLIBRARY)
23252342
@if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
23262343
echo Not configured with --enable-framework; \
23272344
exit 1; \
@@ -2342,6 +2359,27 @@ frameworkinstallstructure: $(LDLIBRARY)
23422359
$(LN) -fsn Versions/Current/Resources $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Resources
23432360
$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(LDLIBRARY)
23442361

2362+
# iOS/tvOS/watchOS uses a non-versioned framework with Info.plist in the
2363+
# framework root, no .lproj data, and only stub compilation assistance binaries
2364+
.PHONY: frameworkinstallunversionedstructure
2365+
frameworkinstallunversionedstructure: $(LDLIBRARY)
2366+
@if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
2367+
echo Not configured with --enable-framework; \
2368+
exit 1; \
2369+
else true; \
2370+
fi
2371+
if test -d $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include; then \
2372+
echo "Clearing stale header symlink directory"; \
2373+
rm -rf $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include; \
2374+
fi
2375+
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)
2376+
sed 's/%VERSION%/'"`$(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import platform; print(platform.python_version())'`"'/g' < $(RESSRCDIR)/Info.plist > $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Info.plist
2377+
$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(LDLIBRARY)
2378+
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(BINDIR)
2379+
for file in $(srcdir)/$(RESSRCDIR)/bin/* ; do \
2380+
$(INSTALL) -m $(EXEMODE) $$file $(DESTDIR)$(BINDIR); \
2381+
done
2382+
23452383
# This installs Mac/Lib into the framework
23462384
# Install a number of symlinks to keep software that expects a normal unix
23472385
# install (which includes python-config) happy.
@@ -2376,6 +2414,19 @@ frameworkaltinstallunixtools:
23762414
frameworkinstallextras:
23772415
cd Mac && $(MAKE) installextras DESTDIR="$(DESTDIR)"
23782416

2417+
# On iOS, bin/lib can't live inside the framework; include needs to be called
2418+
# "Headers", but *must* be in the framework, and *not* include the `python3.X`
2419+
# subdirectory. The install has put these folders in the same folder as
2420+
# Python.framework; Move the headers to their final framework-compatible home.
2421+
.PHONY: frameworkinstallmobileheaders
2422+
frameworkinstallmobileheaders:
2423+
if test -d $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers; then \
2424+
echo "Removing old framework headers"; \
2425+
rm -rf $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers; \
2426+
fi
2427+
mv "$(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include/python$(VERSION)" "$(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers"
2428+
$(LN) -fs "../$(PYTHONFRAMEWORKDIR)/Headers" "$(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include/python$(VERSION)"
2429+
23792430
# Build the toplevel Makefile
23802431
Makefile.pre: $(srcdir)/Makefile.pre.in config.status
23812432
CONFIG_FILES=Makefile.pre CONFIG_HEADERS= $(SHELL) config.status
@@ -2581,7 +2632,7 @@ Python/thread.o: @THREADHEADERS@ $(srcdir)/Python/condvar.h
25812632
.PHONY: all build_all build_wasm sharedmods check-clean-src oldsharedmods test quicktest
25822633
.PHONY: install altinstall oldsharedinstall bininstall altbininstall
25832634
.PHONY: maninstall libinstall inclinstall libainstall sharedinstall
2584-
.PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure
2635+
.PHONY: frameworkinstall frameworkinstallframework
25852636
.PHONY: frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools
25862637
.PHONY: frameworkaltinstallunixtools recheck clean clobber distclean
25872638
.PHONY: smelly funny patchcheck touch altmaninstall commoninstall
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Makefile targets were added to support compiling an iOS-compatible framework
2+
build.

config.sub

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
# shellcheck disable=SC2006,SC2268 # see below for rationale
66

7+
# Patched 2024-02-03 to include support for arm64_32 and iOS/tvOS/watchOS simulators
78
timestamp='2024-01-01'
89

910
# This file is free software; you can redistribute it and/or modify it
@@ -1127,7 +1128,7 @@ case $cpu-$vendor in
11271128
xscale-* | xscalee[bl]-*)
11281129
cpu=`echo "$cpu" | sed 's/^xscale/arm/'`
11291130
;;
1130-
arm64-* | aarch64le-*)
1131+
arm64-* | aarch64le-* | arm64_32-*)
11311132
cpu=aarch64
11321133
;;
11331134

@@ -1866,6 +1867,8 @@ case $kernel-$os-$obj in
18661867
;;
18671868
*-eabi*- | *-gnueabi*-)
18681869
;;
1870+
ios*-simulator- | tvos*-simulator- | watchos*-simulator- )
1871+
;;
18691872
none--*)
18701873
# None (no kernel, i.e. freestanding / bare metal),
18711874
# can be paired with an machine code file format

0 commit comments

Comments
 (0)