Skip to content

Commit 9486990

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

20 files changed

Lines changed: 901 additions & 120 deletions

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
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‎

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,21 @@ $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK): \
814814
$(LN) -fsn Versions/Current/$(PYTHONFRAMEWORK) $(PYTHONFRAMEWORKDIR)/$(PYTHONFRAMEWORK)
815815
$(LN) -fsn Versions/Current/Resources $(PYTHONFRAMEWORKDIR)/Resources
816816

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

2327-
frameworkinstallframework: frameworkinstallstructure install frameworkinstallmaclib
2342+
frameworkinstallframework: @FRAMEWORKINSTALLFIRST@ install frameworkinstallmaclib
23282343

2329-
frameworkinstallstructure: $(LDLIBRARY)
2344+
# macOS uses a versioned frameworks structure that includes a full install
2345+
.PHONY: frameworkinstallversionedstructure
2346+
frameworkinstallversionedstructure: $(LDLIBRARY)
23302347
@if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
23312348
echo Not configured with --enable-framework; \
23322349
exit 1; \
@@ -2347,6 +2364,27 @@ frameworkinstallstructure: $(LDLIBRARY)
23472364
$(LN) -fsn Versions/Current/Resources $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Resources
23482365
$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(LDLIBRARY)
23492366

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

2422+
# On iOS, bin/lib can't live inside the framework; include needs to be called
2423+
# "Headers", but *must* be in the framework, and *not* include the `python3.X`
2424+
# subdirectory. The install has put these folders in the same folder as
2425+
# Python.framework; Move the headers to their final framework-compatible home.
2426+
.PHONY: frameworkinstallmobileheaders
2427+
frameworkinstallmobileheaders:
2428+
if test -d $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers; then \
2429+
echo "Removing old framework headers"; \
2430+
rm -rf $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers; \
2431+
fi
2432+
mv "$(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include/python$(VERSION)" "$(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers"
2433+
$(LN) -fs "../$(PYTHONFRAMEWORKDIR)/Headers" "$(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include/python$(VERSION)"
2434+
23842435
# Build the toplevel Makefile
23852436
Makefile.pre: $(srcdir)/Makefile.pre.in config.status
23862437
CONFIG_FILES=Makefile.pre CONFIG_HEADERS= $(SHELL) config.status
@@ -2586,7 +2637,7 @@ Python/thread.o: @THREADHEADERS@ $(srcdir)/Python/condvar.h
25862637
.PHONY: all build_all build_wasm sharedmods check-clean-src oldsharedmods test quicktest
25872638
.PHONY: install altinstall oldsharedinstall bininstall altbininstall
25882639
.PHONY: maninstall libinstall inclinstall libainstall sharedinstall
2589-
.PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure
2640+
.PHONY: frameworkinstall frameworkinstallframework
25902641
.PHONY: frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools
25912642
.PHONY: frameworkaltinstallunixtools recheck clean clobber distclean
25922643
.PHONY: smelly funny patchcheck touch altmaninstall commoninstall
Lines changed: 2 additions & 0 deletions
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‎

Lines changed: 4 additions & 1 deletion
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)