Skip to content

Commit adf957f

Browse files
committed
unix: build tcl/tk on macOS
Previously, we used the system tcl/tk, which is version 8.5. Unfortunately as reported by #43, this lacks some features. And the official CPython macOS dmg compiles its own tcl/tk at version 8.6, so our packages weren't on parity with the official ones. This commit enables the building of tcl/tk from sources on macOS. This was surprisingly straightforward. The big changes are to ditch the system frameworks and replace with our own libraries. I confirmed that `import tkinter` works and that our new binaries do not link against any tcl/tk libraries or frameworks. I also successfully ran a minimal visual application with tkinter. I'm fairly confident this "just works." Closes #43.
1 parent fba47c6 commit adf957f

File tree

5 files changed

+18
-25
lines changed

5 files changed

+18
-25
lines changed

cpython-unix/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ ifeq ($(HOST_PLATFORM),macos)
5757
NEED_GDBM :=
5858
NEED_X11 :=
5959
NEED_READLINE :=
60-
NEED_TIX :=
60+
NEED_TIX := 1
6161
endif
6262

6363
ifdef PYBUILD_MUSL

cpython-unix/build-cpython.sh

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

210210
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
211211
CFLAGS="${CFLAGS} -I${TOOLS_PATH}/deps/lib/libffi-3.2.1/include -I${TOOLS_PATH}/deps/include/uuid"
212-
213-
CFLAGS="${CFLAGS} -I${MACOS_SDK_PATH}/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers"
214212
CFLAGS="${CFLAGS} -F${MACOS_SDK_PATH}/System/Library/Frameworks"
215213

216214
# Prevent using symbols not supported by current macOS SDK target.
@@ -477,13 +475,11 @@ cp -av ${TOOLS_PATH}/deps/libedit/lib/*.a ${ROOT}/out/python/build/lib/
477475
rm -f ${ROOT}/out/python/build/lib/{libdb-6.0,libxcb-*,libX11-xcb}.a
478476

479477
# Copy tcl/tk/tix resources needed by tkinter.
480-
if [ "${PYBUILD_PLATFORM}" != "macos" ]; then
481-
mkdir ${ROOT}/out/python/install/lib/tcl
482-
# Keep this list in sync with tcl_library_paths.
483-
for source in ${TOOLS_PATH}/deps/lib/{tcl8,tcl8.6,thread2.8.5,Tix8.4.3,tk8.6}; do
478+
mkdir ${ROOT}/out/python/install/lib/tcl
479+
# Keep this list in sync with tcl_library_paths.
480+
for source in ${TOOLS_PATH}/deps/lib/{tcl8,tcl8.6,thread2.8.5,Tix8.4.3,tk8.6}; do
484481
cp -av $source ${ROOT}/out/python/install/lib/
485-
done
486-
fi
482+
done
487483

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

cpython-unix/build.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,9 @@ def build_cpython(
638638
"libedit",
639639
"libffi",
640640
"sqlite",
641+
"tcl",
642+
"tix",
643+
"tk",
641644
"uuid",
642645
"xz",
643646
"zlib",
@@ -660,10 +663,6 @@ def build_cpython(
660663
if host_platform == "linux64":
661664
packages |= {"libX11", "libXau", "libxcb", "xorgproto"}
662665

663-
tix = host_platform != "macos"
664-
if tix:
665-
packages |= {"tcl", "tix", "tk"}
666-
667666
for p in sorted(packages):
668667
build_env.install_artifact_archive(BUILD, p, target_triple, optimizations)
669668

@@ -773,16 +772,14 @@ def build_cpython(
773772
"license_path": "licenses/LICENSE.cpython.txt",
774773
}
775774

776-
# We do not ship tcl libraries on macOS.
777-
if host_platform != "macos":
778-
python_info["tcl_library_path"] = "install/lib"
779-
python_info["tcl_library_paths"] = [
780-
"tcl8",
781-
"tcl8.6",
782-
"thread2.8.5",
783-
"Tix8.4.3",
784-
"tk8.6",
785-
]
775+
python_info["tcl_library_path"] = "install/lib"
776+
python_info["tcl_library_paths"] = [
777+
"tcl8",
778+
"tcl8.6",
779+
"thread2.8.5",
780+
"Tix8.4.3",
781+
"tk8.6",
782+
]
786783

787784
# Add metadata derived from built distribution.
788785
extra_metadata = build_env.get_file("metadata.json")

cpython-unix/static-modules.3.7.macos

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _queue _queuemodule.c
2323
_scproxy _scproxy.c -framework SystemConfiguration -framework CoreFoundation
2424
_sqlite3 _sqlite/cache.c _sqlite/connection.c _sqlite/cursor.c _sqlite/microprotocols.c _sqlite/module.c _sqlite/prepare_protocol.c _sqlite/row.c _sqlite/statement.c _sqlite/util.c -IModules/_sqlite -DMODULE_NAME=\"sqlite3\" -DSQLITE_OMIT_LOAD_EXTENSION=1 -lsqlite3
2525
_ssl _ssl.c -lssl -lcrypto
26-
_tkinter _tkinter.c tkappinit.c -DWITH_APPINIT -framework AppKit -framework ApplicationServices -framework Carbon -framework CoreServices -framework CoreGraphics -framework IOKit -framework Tcl -framework Tk
26+
_tkinter _tkinter.c tkappinit.c -DWITH_APPINIT -framework AppKit -framework ApplicationServices -framework Carbon -framework CoreServices -framework CoreGraphics -framework IOKit -ltcl8.6 -ltk8.6
2727
_uuid _uuidmodule.c -luuid
2828
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
2929
readline readline.c -ledit -lncurses

cpython-unix/static-modules.3.8.macos

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ _queue _queuemodule.c
2424
_scproxy _scproxy.c -framework SystemConfiguration -framework CoreFoundation
2525
_sqlite3 _sqlite/cache.c _sqlite/connection.c _sqlite/cursor.c _sqlite/microprotocols.c _sqlite/module.c _sqlite/prepare_protocol.c _sqlite/row.c _sqlite/statement.c _sqlite/util.c -IModules/_sqlite -DMODULE_NAME=\"sqlite3\" -DSQLITE_OMIT_LOAD_EXTENSION=1 -lsqlite3
2626
_ssl _ssl.c -lssl -lcrypto
27-
_tkinter _tkinter.c tkappinit.c -DWITH_APPINIT -framework AppKit -framework ApplicationServices -framework Carbon -framework CoreServices -framework CoreGraphics -framework IOKit -framework Tcl -framework Tk
27+
_tkinter _tkinter.c tkappinit.c -DWITH_APPINIT -framework AppKit -framework ApplicationServices -framework Carbon -framework CoreServices -framework CoreGraphics -framework IOKit -ltcl8.6 -ltk8.6
2828
_uuid _uuidmodule.c -luuid
2929
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
3030
readline readline.c -ledit -lncurses

0 commit comments

Comments
 (0)