Skip to content

Commit 9ff4ec5

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

19 files changed

+854
-104
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Lib/test/data/*
6969
/_bootstrap_python
7070
/Makefile
7171
/Makefile.pre
72+
iOS/Resources/Info.plist
7273
Mac/Makefile
7374
Mac/PythonLauncher/Info.plist
7475
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)
@@ -2506,10 +2521,11 @@ frameworkinstall: install
25062521
# only have to cater for the structural bits of the framework.
25072522

25082523
.PHONY: frameworkinstallframework
2509-
frameworkinstallframework: frameworkinstallstructure install frameworkinstallmaclib
2524+
frameworkinstallframework: @FRAMEWORKINSTALLFIRST@ install frameworkinstallmaclib
25102525

2511-
.PHONY: frameworkinstallstructure
2512-
frameworkinstallstructure: $(LDLIBRARY)
2526+
# macOS uses a versioned frameworks structure that includes a full install
2527+
.PHONY: frameworkinstallversionedstructure
2528+
frameworkinstallversionedstructure: $(LDLIBRARY)
25132529
@if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
25142530
echo Not configured with --enable-framework; \
25152531
exit 1; \
@@ -2530,6 +2546,27 @@ frameworkinstallstructure: $(LDLIBRARY)
25302546
$(LN) -fsn Versions/Current/Resources $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Resources
25312547
$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(LDLIBRARY)
25322548

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

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