Skip to content

Commit 1814e0e

Browse files
committed
[3.12] pythongh-114099: Add configure and Makefile targets to support iOS compilation. (pythonGH-115390)
1 parent ae5a2bc commit 1814e0e

19 files changed

Lines changed: 858 additions & 108 deletions

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Lib/test/data/*
7070
/_bootstrap_python
7171
/Makefile
7272
/Makefile.pre
73+
iOS/Resources/Info.plist
7374
Mac/Makefile
7475
Mac/PythonLauncher/Info.plist
7576
Mac/PythonLauncher/Makefile

‎Makefile.pre.in‎

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,21 @@ $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK): \
871871
$(LN) -fsn Versions/Current/$(PYTHONFRAMEWORK) $(PYTHONFRAMEWORKDIR)/$(PYTHONFRAMEWORK)
872872
$(LN) -fsn Versions/Current/Resources $(PYTHONFRAMEWORKDIR)/Resources
873873

874+
# This rule is for iOS, which requires an annoyingly just slighly different
875+
# format for frameworks to macOS. It *doesn't* use a versioned framework, and
876+
# the Info.plist must be in the root of the framework.
877+
$(PYTHONFRAMEWORKDIR)/$(PYTHONFRAMEWORK): \
878+
$(LIBRARY) \
879+
$(RESSRCDIR)/Info.plist
880+
$(INSTALL) -d -m $(DIRMODE) $(PYTHONFRAMEWORKDIR)
881+
$(CC) -o $(LDLIBRARY) $(PY_CORE_LDFLAGS) -dynamiclib \
882+
-all_load $(LIBRARY) \
883+
-install_name $(PYTHONFRAMEWORKINSTALLNAMEPREFIX)/$(PYTHONFRAMEWORK) \
884+
-compatibility_version $(VERSION) \
885+
-current_version $(VERSION) \
886+
-framework CoreFoundation $(LIBS);
887+
$(INSTALL_DATA) $(RESSRCDIR)/Info.plist $(PYTHONFRAMEWORKDIR)/Info.plist
888+
874889
# This rule builds the Cygwin Python DLL and import library if configured
875890
# for a shared core library; otherwise, this rule is a noop.
876891
$(DLLLIBRARY) libpython$(LDVERSION).dll.a: $(LIBRARY_OBJS)
@@ -2513,10 +2528,11 @@ frameworkinstall: install
25132528
# only have to cater for the structural bits of the framework.
25142529

25152530
.PHONY: frameworkinstallframework
2516-
frameworkinstallframework: frameworkinstallstructure install frameworkinstallmaclib
2531+
frameworkinstallframework: @FRAMEWORKINSTALLFIRST@ install frameworkinstallmaclib
25172532

2518-
.PHONY: frameworkinstallstructure
2519-
frameworkinstallstructure: $(LDLIBRARY)
2533+
# macOS uses a versioned frameworks structure that includes a full install
2534+
.PHONY: frameworkinstallversionedstructure
2535+
frameworkinstallversionedstructure: $(LDLIBRARY)
25202536
@if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
25212537
echo Not configured with --enable-framework; \
25222538
exit 1; \
@@ -2537,6 +2553,27 @@ frameworkinstallstructure: $(LDLIBRARY)
25372553
$(LN) -fsn Versions/Current/Resources $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Resources
25382554
$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(LDLIBRARY)
25392555

2556+
# iOS/tvOS/watchOS uses a non-versioned framework with Info.plist in the
2557+
# framework root, no .lproj data, and only stub compilation assistance binaries
2558+
.PHONY: frameworkinstallunversionedstructure
2559+
frameworkinstallunversionedstructure: $(LDLIBRARY)
2560+
@if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
2561+
echo Not configured with --enable-framework; \
2562+
exit 1; \
2563+
else true; \
2564+
fi
2565+
if test -d $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include; then \
2566+
echo "Clearing stale header symlink directory"; \
2567+
rm -rf $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include; \
2568+
fi
2569+
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)
2570+
sed 's/%VERSION%/'"`$(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import platform; print(platform.python_version())'`"'/g' < $(RESSRCDIR)/Info.plist > $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Info.plist
2571+
$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(LDLIBRARY)
2572+
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(BINDIR)
2573+
for file in $(srcdir)/$(RESSRCDIR)/bin/* ; do \
2574+
$(INSTALL) -m $(EXEMODE) $$file $(DESTDIR)$(BINDIR); \
2575+
done
2576+
25402577
# This installs Mac/Lib into the framework
25412578
# Install a number of symlinks to keep software that expects a normal unix
25422579
# install (which includes python-config) happy.
@@ -2577,6 +2614,19 @@ frameworkaltinstallunixtools:
25772614
frameworkinstallextras:
25782615
cd Mac && $(MAKE) installextras DESTDIR="$(DESTDIR)"
25792616

2617+
# On iOS, bin/lib can't live inside the framework; include needs to be called
2618+
# "Headers", but *must* be in the framework, and *not* include the `python3.X`
2619+
# subdirectory. The install has put these folders in the same folder as
2620+
# Python.framework; Move the headers to their final framework-compatible home.
2621+
.PHONY: frameworkinstallmobileheaders
2622+
frameworkinstallmobileheaders:
2623+
if test -d $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers; then \
2624+
echo "Removing old framework headers"; \
2625+
rm -rf $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers; \
2626+
fi
2627+
mv "$(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include/python$(VERSION)" "$(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers"
2628+
$(LN) -fs "../$(PYTHONFRAMEWORKDIR)/Headers" "$(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include/python$(VERSION)"
2629+
25802630
# Build the toplevel Makefile
25812631
Makefile.pre: $(srcdir)/Makefile.pre.in config.status
25822632
CONFIG_FILES=Makefile.pre CONFIG_HEADERS= ./config.status
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)