@@ -146,8 +146,10 @@ if [[ "${PYTHON_MAJOR_VERSION}" != +(3.9|3.10) ]]; then
146146 )
147147fi
148148
149- # Allow additional configure flags to be supplied via PYTHON_CONFIGURE_OPTS while keeping
150- # the defaults (such as --with-tcltk) earlier in the list so user-supplied values win.
149+ # Tk is discovered via pkg-config from the `tk-dev`/`tcl-dev` packages in the build image,
150+ # so no extra CPPFLAGS/LDFLAGS/PKG_CONFIG_PATH tweaking is required here. Allow additional
151+ # configure flags to be supplied via PYTHON_CONFIGURE_OPTS while keeping the defaults earlier
152+ # in the list so user-supplied values win.
151153if [[ -n " ${PYTHON_CONFIGURE_OPTS:- } " ]]; then
152154 # shellcheck disable=SC2206 # We intentionally rely on word-splitting like configure scripts.
153155 PYTHON_CONFIGURE_OPTS_ARRAY=( ${PYTHON_CONFIGURE_OPTS} )
@@ -190,9 +192,31 @@ if [[ "${PYTHON_MAJOR_VERSION}" == +(3.9) ]]; then
190192 # - `lib/python3.9/config-3.9-x86_64-linux-gnu/libpython3.9.a`
191193 find " ${INSTALL_DIR} " -type f -name ' *.a' -print -exec strip --strip-unneeded ' {}' +
192194elif ! find " ${INSTALL_DIR} " -type f -name ' *.a' -print -exec false ' {}' +; then
193- abort " Unexpected static libraries found!"
195+ abort " Unexpected static libraries found!"
194196fi
195197
198+ # Bundle the Tk runtime shared libraries and data files so they remain available on the Heroku
199+ # run image (which doesn't include Tk by default). This also avoids runtime lookups against the
200+ # system library paths which would break once the archive is relocated by the buildpack.
201+ shopt -s nullglob
202+ TCL_TK_VERSION=" $( tclsh <<< ' puts $tcl_version' ) "
203+ TK_RUNTIME_LIBS=(/usr/lib/* /libtcl${TCL_TK_VERSION} .so* )
204+ TK_RUNTIME_LIBS+=(/usr/lib/* /libtk${TCL_TK_VERSION} .so* )
205+ if [[ " ${# TK_RUNTIME_LIBS[@]} " -eq 0 ]]; then
206+ abort " Tk runtime shared libraries weren't found for version ${TCL_TK_VERSION} !"
207+ fi
208+
209+ TK_LIBRARY_DIRS=(/usr/share/tcltk/tcl${TCL_TK_VERSION} )
210+ TK_LIBRARY_DIRS+=(/usr/share/tcltk/tk${TCL_TK_VERSION} )
211+ for tk_library_dir in " ${TK_LIBRARY_DIRS[@]} " ; do
212+ if [[ ! -d " ${tk_library_dir} " ]]; then
213+ abort " Tk runtime library directory '${tk_library_dir} ' wasn't found!"
214+ fi
215+ done
216+
217+ cp --dereference --target-directory " ${INSTALL_DIR} /lib/" --verbose " ${TK_RUNTIME_LIBS[@]} "
218+ cp --archive --target-directory " ${INSTALL_DIR} /lib/" --verbose " ${TK_LIBRARY_DIRS[@]} "
219+
196220# Remove unneeded test directories, similar to the official Docker Python images:
197221# https://github.com/docker-library/python
198222# This is a no-op on Python 3.11+, since --disable-test-modules will have prevented
0 commit comments