Skip to content

Commit bee7bb3

Browse files
authored
gh-114099: Add configure and Makefile targets to support iOS compilation. (GH-115390)
1 parent e921f09 commit bee7bb3

20 files changed

+849
-104
lines changed

.gitignore

+1
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

+53-3
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,21 @@ $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK): \
912912
$(LN) -fsn Versions/Current/$(PYTHONFRAMEWORK) $(PYTHONFRAMEWORKDIR)/$(PYTHONFRAMEWORK)
913913
$(LN) -fsn Versions/Current/Resources $(PYTHONFRAMEWORKDIR)/Resources
914914

915+
# This rule is for iOS, which requires an annoyingly just slighly different
916+
# format for frameworks to macOS. It *doesn't* use a versioned framework, and
917+
# the Info.plist must be in the root of the framework.
918+
$(PYTHONFRAMEWORKDIR)/$(PYTHONFRAMEWORK): \
919+
$(LIBRARY) \
920+
$(RESSRCDIR)/Info.plist
921+
$(INSTALL) -d -m $(DIRMODE) $(PYTHONFRAMEWORKDIR)
922+
$(CC) -o $(LDLIBRARY) $(PY_CORE_LDFLAGS) -dynamiclib \
923+
-all_load $(LIBRARY) \
924+
-install_name $(PYTHONFRAMEWORKINSTALLNAMEPREFIX)/$(PYTHONFRAMEWORK) \
925+
-compatibility_version $(VERSION) \
926+
-current_version $(VERSION) \
927+
-framework CoreFoundation $(LIBS);
928+
$(INSTALL_DATA) $(RESSRCDIR)/Info.plist $(PYTHONFRAMEWORKDIR)/Info.plist
929+
915930
# This rule builds the Cygwin Python DLL and import library if configured
916931
# for a shared core library; otherwise, this rule is a noop.
917932
$(DLLLIBRARY) libpython$(LDVERSION).dll.a: $(LIBRARY_OBJS)
@@ -2607,10 +2622,11 @@ frameworkinstall: install
26072622
# only have to cater for the structural bits of the framework.
26082623

26092624
.PHONY: frameworkinstallframework
2610-
frameworkinstallframework: frameworkinstallstructure install frameworkinstallmaclib
2625+
frameworkinstallframework: @FRAMEWORKINSTALLFIRST@ install frameworkinstallmaclib
26112626

2612-
.PHONY: frameworkinstallstructure
2613-
frameworkinstallstructure: $(LDLIBRARY)
2627+
# macOS uses a versioned frameworks structure that includes a full install
2628+
.PHONY: frameworkinstallversionedstructure
2629+
frameworkinstallversionedstructure: $(LDLIBRARY)
26142630
@if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
26152631
echo Not configured with --enable-framework; \
26162632
exit 1; \
@@ -2631,6 +2647,27 @@ frameworkinstallstructure: $(LDLIBRARY)
26312647
$(LN) -fsn Versions/Current/Resources $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Resources
26322648
$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(LDLIBRARY)
26332649

2650+
# iOS/tvOS/watchOS uses a non-versioned framework with Info.plist in the
2651+
# framework root, no .lproj data, and only stub compilation assistance binaries
2652+
.PHONY: frameworkinstallunversionedstructure
2653+
frameworkinstallunversionedstructure: $(LDLIBRARY)
2654+
@if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
2655+
echo Not configured with --enable-framework; \
2656+
exit 1; \
2657+
else true; \
2658+
fi
2659+
if test -d $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include; then \
2660+
echo "Clearing stale header symlink directory"; \
2661+
rm -rf $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include; \
2662+
fi
2663+
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)
2664+
sed 's/%VERSION%/'"`$(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import platform; print(platform.python_version())'`"'/g' < $(RESSRCDIR)/Info.plist > $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Info.plist
2665+
$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(LDLIBRARY)
2666+
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(BINDIR)
2667+
for file in $(srcdir)/$(RESSRCDIR)/bin/* ; do \
2668+
$(INSTALL) -m $(EXEMODE) $$file $(DESTDIR)$(BINDIR); \
2669+
done
2670+
26342671
# This installs Mac/Lib into the framework
26352672
# Install a number of symlinks to keep software that expects a normal unix
26362673
# install (which includes python-config) happy.
@@ -2671,6 +2708,19 @@ frameworkaltinstallunixtools:
26712708
frameworkinstallextras:
26722709
cd Mac && $(MAKE) installextras DESTDIR="$(DESTDIR)"
26732710

2711+
# On iOS, bin/lib can't live inside the framework; include needs to be called
2712+
# "Headers", but *must* be in the framework, and *not* include the `python3.X`
2713+
# subdirectory. The install has put these folders in the same folder as
2714+
# Python.framework; Move the headers to their final framework-compatible home.
2715+
.PHONY: frameworkinstallmobileheaders
2716+
frameworkinstallmobileheaders:
2717+
if test -d $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers; then \
2718+
echo "Removing old framework headers"; \
2719+
rm -rf $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers; \
2720+
fi
2721+
mv "$(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include/python$(VERSION)" "$(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers"
2722+
$(LN) -fs "../$(PYTHONFRAMEWORKDIR)/Headers" "$(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include/python$(VERSION)"
2723+
26742724
# Build the toplevel Makefile
26752725
Makefile.pre: $(srcdir)/Makefile.pre.in config.status
26762726
CONFIG_FILES=Makefile.pre CONFIG_HEADERS= ./config.status
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.

Misc/platform_triplet.c

+15
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,22 @@ PLATFORM_TRIPLET=i386-gnu
233233
# error unknown platform triplet
234234
# endif
235235
#elif defined(__APPLE__)
236+
# include "TargetConditionals.h"
237+
# if TARGET_OS_IOS
238+
# if TARGET_OS_SIMULATOR
239+
# if __x86_64__
240+
PLATFORM_TRIPLET=x86_64-iphonesimulator
241+
# else
242+
PLATFORM_TRIPLET=arm64-iphonesimulator
243+
# endif
244+
# else
245+
PLATFORM_TRIPLET=arm64-iphoneos
246+
# endif
247+
# elif TARGET_OS_OSX
236248
PLATFORM_TRIPLET=darwin
249+
# else
250+
# error unknown Apple platform
251+
# endif
237252
#elif defined(__VXWORKS__)
238253
PLATFORM_TRIPLET=vxworks
239254
#elif defined(__wasm32__)

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)