Skip to content

Commit 972144e

Browse files
committed
unix: make CPython compile on Catalina / disable Tcl/Tk
I couldn't get things to build in their current state on Catalina for several reasons. First, it looks like a lot of developer files are no longer in /usr and our custom Clang can't pick them without some nudging. So, we had to pass some extra CFLAGS when building. A bigger problem is how to deal with Tcl/Tk/Tix. The X11.h file in Catalina's SDK appears to reference a missing xproto.h. I no longer have a copy of older macOS, so I'm not sure what changed here. But I couldn't get Tcl/Tk to work with the X11.h in the macOS SDK. I attempted to install XQuartz and compile with its headers. But we ran into mismatch issues and I didn't feel like going down the rabbit hole. I decided to give up and disable the custom Tcl/Tk/Tix packages on macOS and to instead use the Tcl and Tk frameworks that are part of the macOS SDK. These have been part of the SDK since at least 10.3. And Tcl 8.5 has been present since 10.6. This will add a run-time dependency on the Tcl/Tk frameworks. But I think that's OK. We already rely on some frameworks at runtime. Creating fully static binaries on macOS is effectively impossible these days. Plus Tcl/Tk/Tix features in Python are not used very much. So I think it is acceptable to cut corners. One casuality is Tix. We are no longer building it. We potentially could build it against the macOS Tcl/Tk frameworks. But the tix module has been deprecated since Python 3.6 and we only support Python 3.7. So I think it is acceptable to put on the chopping block. FWIW Homebrew's Python doesn't include Tix support either. I suspect it won't be missed. Anyway, with this commit I am able to build again on Catalina.
1 parent c135c3d commit 972144e

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

README.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ macOS
8484
The XCode command line tools must be installed. A Python 3 interpreter
8585
is required to execute the build. ``/usr/bin/clang`` must exist.
8686

87-
macOS SDK headers must be installed in ``/usr/include`` in order to work
88-
with the Clang toolchain that is built. If ``/usr/include`` does not
89-
exist, try running the installer. e.g.::
90-
91-
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
87+
macOS SDK headers must be installed. Try running ``xcode-select --install``
88+
to install them if you see errors about e.g. ``stdio.h`` not being found.
89+
Verify they are installed by running ``xcrun --show-sdk-path``. It
90+
should print something like
91+
``/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk``
92+
on modern versions of macOS.
9293

9394
Windows
9495
-------

cpython-unix/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ifeq ($(PLATFORM),macos)
3333
NEED_GDBM :=
3434
NEED_X11 :=
3535
NEED_READLINE :=
36-
NEED_TIX := 1
36+
NEED_TIX :=
3737
endif
3838

3939
BASE_PLATFORM := $(PLATFORM)

cpython-unix/build-cpython.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ CFLAGS="-fPIC -I${TOOLS_PATH}/deps/include -I${TOOLS_PATH}/deps/include/ncurses"
107107

108108
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
109109
CFLAGS="${CFLAGS} -I${TOOLS_PATH}/deps/lib/libffi-3.2.1/include -I${TOOLS_PATH}/deps/include/uuid"
110+
111+
CFLAGS="${CFLAGS} -I${MACOS_SDK_PATH}/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers"
112+
CFLAGS="${CFLAGS} -F${MACOS_SDK_PATH}/System/Library/Frameworks"
113+
110114
# Prevent using symbols not supported by current macOS SDK target.
111115
CFLAGS="${CFLAGS} -Werror=unguarded-availability-new"
112116
fi
@@ -242,10 +246,12 @@ cp -av ${TOOLS_PATH}/deps/libedit/lib/*.a ${ROOT}/out/python/build/lib/
242246
rm -f ${ROOT}/out/python/build/lib/{libdb-6.0,libxcb-*,libX11-xcb}.a
243247

244248
# Copy tcl/tk/tix resources needed by tkinter.
245-
mkdir ${ROOT}/out/python/install/lib/tcl
246-
for source in ${TOOLS_PATH}/deps/lib/{tcl8,tcl8.6,thread2.8.4,Tix8.4.3,tk8.6}; do
247-
cp -av $source ${ROOT}/out/python/install/lib/tcl/
248-
done
249+
if [ "${PYBUILD_PLATFORM}" != "macos" ]; then
250+
mkdir ${ROOT}/out/python/install/lib/tcl
251+
for source in ${TOOLS_PATH}/deps/lib/{tcl8,tcl8.6,thread2.8.4,Tix8.4.3,tk8.6}; do
252+
cp -av $source ${ROOT}/out/python/install/lib/tcl/
253+
done
254+
fi
249255

250256
# config.c defines _PyImport_Inittab and extern references to modules, which
251257
# downstream consumers may want to strip. We bundle config.c and config.c.in so

cpython-unix/build.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,6 @@ def build_cpython(
549549
"libedit",
550550
"libffi",
551551
"sqlite",
552-
"tcl",
553-
"tix",
554-
"tk",
555552
"uuid",
556553
"xz",
557554
"zlib",
@@ -574,6 +571,10 @@ def build_cpython(
574571
if platform == "linux64":
575572
packages |= {"libX11", "libXau", "libxcb", "xorgproto"}
576573

574+
tix = platform != "macos"
575+
if tix:
576+
packages |= {"tcl", "tix", "tk"}
577+
577578
for p in sorted(packages):
578579
build_env.install_artifact_archive(BUILD, p, platform, musl=musl)
579580

cpython-unix/static-modules.macos

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ _ssl _ssl.c -lssl -lcrypto
2727
_testbuffer _testbuffer.c
2828
_testimportmultiple _testimportmultiple.c
2929
_testmultiphase _testmultiphase.c
30-
_tkinter _tkinter.c tkappinit.c -DWITH_APPINIT -framework AppKit -framework ApplicationServices -framework Carbon -framework CoreServices -framework CoreGraphics -framework IOKit -ltcl8.6 -ltk8.6
30+
_tkinter _tkinter.c tkappinit.c -DWITH_APPINIT -framework AppKit -framework ApplicationServices -framework Carbon -framework CoreServices -framework CoreGraphics -framework IOKit -framework Tcl -framework Tk
3131
_uuid _uuidmodule.c -luuid
3232
_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c
3333
pyexpat pyexpat.c expat/xmlparse.c expat/xmlrole.c expat/xmltok.c -DHAVE_EXPAT_CONFIG_H=1 -DXML_POOR_ENTROPY=1 -DUSE_PYEXPAT_CAPI -IModules/expat

0 commit comments

Comments
 (0)