8000 unix: switch Linux 3.10 builds from readline to libedit · adiantek/python-build-standalone@1148eb9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1148eb9

Browse files
committed
unix: switch Linux 3.10 builds from readline to libedit
CPython 3.10 adds mostly working support for libedit outside of macOS. I think it is good enough to use by default. This commit rewrites the build logic to use libedit and only libedit on CPython 3.10+.
1 parent e612033 commit 1148eb9

13 files changed

+76
-77
lines changed

cpython-unix/build-cpython.sh

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -493,24 +493,22 @@ diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py
493493
if _os.name == "nt":
494494
EOF
495495

496-
# libedit on non-macOS requires various hacks because readline.c assumes
497-
# libedit is only used on macOS and its readline/libedit detection code
498-
# makes various assumptions about the macOS environment.
496+
# CPython 3.10 added proper support for building against libedit outside of
497+
# macOS. On older versions, we need to patch readline.c and distribute
498+
# multiple extension module variants.
499499
#
500500
# USE_LIBEDIT comes from our static-modules file.
501-
#
502-
# TODO make upstream patches to readline.c to properly support libedit
503-
# on other platforms.
504-
cp Modules/readline.c Modules/readline-libedit.c
501+
if [[ "${PYTHON_MAJMIN_VERSION}" = "3.8" || "${PYTHON_MAJMIN_VERSION}" = "3.9" ]]; then
502+
cp Modules/readline.c Modules/readline-libedit.c
505503

506-
# readline.c assumes that a modern readline API version has a free_history_entry().
507-
# but libedit does not. Change the #ifdef accordingly.
508-
#
509-
# Similarly, we invoke configure using readline, which sets
510-
# HAVE_RL_COMPLETION_SUPPRESS_APPEND improperly. So hack that. This is a bug
511-
# in our build system, as we should probably be invoking configure again when
512-
# using libedit.
513-
patch -p1 << EOF
504+
# readline.c assumes that a modern readline API version has a free_history_entry().
505+
# but libedit does not. Change the #ifdef accordingly.
506+
#
507+
# Similarly, we invoke configure using readline, which sets
508+
# HAVE_RL_COMPLETION_SUPPRESS_APPEND improperly. So hack that. This is a bug
509+
# in our build system, as we should probably be invoking configure again when
510+
# using libedit.
511+
patch -p1 << EOF
514512
diff --git a/Modules/readline-libedit.c b/Modules/readline-libedit.c
515513
index 1e74f997b0..56a36e26e6 100644
516514
--- a/Modules/readline-libedit.c
@@ -543,6 +541,7 @@ index 1e74f997b0..56a36e26e6 100644
543541
#endif
544542
rl_cleanup_after_signal();
545543
EOF
544+
fi
546545

547546
# iOS doesn't have system(). Teach posixmodule.c about that.
548547
if [ "${PYTHON_MAJMIN_VERSION}" != "3.8" ]; then
@@ -572,6 +571,7 @@ fi
572571
# So we need to set both.
573572
CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC -I${TOOLS_PATH}/deps/include -I${TOOLS_PATH}/deps/include/ncursesw"
574573
LDFLAGS="${EXTRA_TARGET_LDFLAGS} -L${TOOLS_PATH}/deps/lib"
574+
EXTRA_CONFIGURE_FLAGS=
575575

576576
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
577577
CFLAGS="${CFLAGS} -I${TOOLS_PATH}/deps/include/uuid"
@@ -580,14 +580,27 @@ if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
580580
CFLAGS="${CFLAGS} -Werror=unguarded-availability-new"
581581
fi
582582

583+
# CPython 3.10 introduced proper support for libedit on all platforms. Link against
584+
# libedit by default because it isn't GPL.
585+
#
586+
# Ideally we wouldn't need to adjust global compiler and linker flags. But configure
587+
# performs detection of readline features and sets some preprocessor defines accordingly.
588+
# So we define these accordingly.
589+
if [[ "${PYBUILD_PLATFORM}" != "macos" && "${PYTHON_MAJMIN_VERSION}" != "3.8" && "${PYTHON_MAJMIN_VERSION}" != "3.9" ]]; then
590+
CFLAGS="${CFLAGS} -I${TOOLS_PATH}/deps/libedit/include"
591+
LDFLAGS="${LDFLAGS} -L${TOOLS_PATH}/deps/libedit/lib"
592+
EXTRA_CONFIGURE_FLAGS="${EXTRA_CONFIGURE_FLAGS} --with-readline=editline"
593+
fi
594+
583595
CPPFLAGS=$CFLAGS
584596

585597
CONFIGURE_FLAGS="
586598
--build=${BUILD_TRIPLE} \
587599
--host=${TARGET_TRIPLE}
588600
--prefix=/install
589601
--with-openssl=${TOOLS_PATH}/deps
590-
--without-ensurepip"
602+
--without-ensurepip
603+
${EXTRA_CONFIGURE_FLAGS}"
591604

592605
if [ "${CC}" = "musl-clang" ]; then
593606
CFLAGS="${CFLAGS} -static"

cpython-unix/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ def build_cpython(
754754
musl="musl" in target_triple,
755755
)
756756

757-
packages = target_needs(TARGETS_CONFIG, target_triple)
757+
packages = target_needs(TARGETS_CONFIG, target_triple, python_version)
758758
# Toolchain packages are handled specially.
759759
packages.discard("binutils")
760760
packages.discard("clang")

cpython-unix/static-modules.3.10.aarch64-unknown-linux-gnu

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,4 @@ _xxsubinterpreters _xxsubinterpretersmodule.c
3535
_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c
3636
ossaudiodev ossaudiodev.c
3737
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
38-
# readline variant needs to come first because libreadline is in /tools/deps and is
39-
# picked up by build. We /could/ make libedit first. But since we employ a hack to
40-
# coerce use of libedit on Linux, it seems prudent for the build system to pick
41-
# up readline.
42-
readline VARIANT=readline readline.c -I/tools/deps/include -I/tools/deps/include/ncursesw -L/tools/deps/lib -lreadline -lncursesw
43-
readline VARIANT=libedit readline-libedit.c -DUSE_LIBEDIT=1 -I/tools/deps/libedit/include -I/tools/deps/libedit/include/ncursesw -L/tools/deps/libedit/lib -ledit -lncursesw
38+
readline readline.c -ledit -lncursesw

cpython-unix/static-modules.3.10.armv7-unknown-linux-gnueabi

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,4 @@ _xxsubinterpreters _xxsubinterpretersmodule.c
3535
_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c
3636
ossaudiodev ossaudiodev.c
3737
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
38-
# readline variant needs to come first because libreadline is in /tools/deps and is
39-
# picked up by build. We /could/ make libedit first. But since we employ a hack to
40-
# coerce use of libedit on Linux, it seems prudent for the build system to pick
41-
# up readline.
42-
readline VARIANT=readline readline.c -I/tools/deps/include -I/tools/deps/include/ncursesw -L/tools/deps/lib -lreadline -lncursesw
43-
readline VARIANT=libedit readline-libedit.c -DUSE_LIBEDIT=1 -I/tools/deps/libedit/include -I/tools/deps/libedit/include/ncursesw -L/tools/deps/libedit/lib -ledit -lncursesw
38+
readline readline.c -ledit -lncursesw

cpython-unix/static-modules.3.10.armv7-unknown-linux-gnueabihf

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,4 @@ _xxsubinterpreters _xxsubinterpretersmodule.c
3535
_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c
3636
ossaudiodev ossaudiodev.c
3737
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
38-
# readline variant needs to come first because libreadline is in /tools/deps and is
39-
# picked up by build. We /could/ make libedit first. But since we employ a hack to
40-
# coerce use of libedit on Linux, it seems prudent for the build system to pick
41-
# up readline.
42-
readline VARIANT=readline readline.c -I/tools/deps/include -I/tools/deps/include/ncursesw -L/tools/deps/lib -lreadline -lncursesw
43-
readline VARIANT=libedit readline-libedit.c -DUSE_LIBEDIT=1 -I/tools/deps/libedit/include -I/tools/deps/libedit/include/ncursesw -L/tools/deps/libedit/lib -ledit -lncursesw
38+
readline readline.c -ledit -lncursesw

cpython-unix/static-modules.3.10.i686-unknown-linux-gnu

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,4 @@ _xxsubinterpreters _xxsubinterpretersmodule.c
3434
_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c
3535
ossaudiodev ossaudiodev.c
3636
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
37-
# readline variant needs to come first because libreadline is in /tools/deps and is
38-
# picked up by build. We /could/ make libedit first. But since we employ a hack to
39-
# coerce use of libedit on Linux, it seems prudent for the build system to pick
40-
# up readline.
41-
readline VARIANT=readline readline.c -I/tools/deps/include -I/tools/deps/include/ncursesw -L/tools/deps/lib -lreadline -lncursesw
42-
readline VARIANT=libedit readline-libedit.c -DUSE_LIBEDIT=1 -I/tools/deps/libedit/include -I/tools/deps/libedit/include/ncursesw -L/tools/deps/libedit/lib -ledit -lncursesw
37+
readline readline.c -ledit -lncursesw

cpython-unix/static-modules.3.10.linux64

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,4 @@ _xxsubinterpreters _xxsubinterpretersmodule.c
3535
_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c
3636
ossaudiodev ossaudiodev.c
3737
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
38-
# readline variant needs to come first because libreadline is in /tools/deps and is
39-
# picked up by build. We /could/ make libedit first. But since we employ a hack to
40-
# coerce use of libedit on Linux, it seems prudent for the build system to pick
41-
# up readline.
42-
readline VARIANT=readline readline.c -I/tools/deps/include -I/tools/deps/include/ncursesw -L/tools/deps/lib -lreadline -lncursesw
43-
readline VARIANT=libedit readline-libedit.c -DUSE_LIBEDIT=1 -I/tools/deps/libedit/include -I/tools/deps/libedit/include/ncursesw -L/tools/deps/libedit/lib -ledit -lncursesw
38+
readline readline.c -ledit -lncursesw

cpython-unix/static-modules.3.10.mips-unknown-linux-gnu

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,4 @@ _xxsubinterpreters _xxsubinterpretersmodule.c
3535
_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c
3636
ossaudiodev ossaudiodev.c
3737
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
38-
# readline variant needs to come first because libreadline is in /tools/deps and is
39-
# picked up by build. We /could/ make libedit first. But since we employ a hack to
40-
# coerce use of libedit on Linux, it seems prudent for the build system to pick
41-
# up readline.
42-
readline VARIANT=readline readline.c -I/tools/deps/include -I/tools/deps/include/ncursesw -L/tools/deps/lib -lreadline -lncursesw
43-
readline VARIANT=libedit readline-libedit.c -DUSE_LIBEDIT=1 -I/tools/deps/libedit/include -I/tools/deps/libedit/include/ncursesw -L/tools/deps/libedit/lib -ledit -lncursesw
38+
readline readline.c -ledit -lncursesw

cpython-unix/static-modules.3.10.mipsel-unknown-linux-gnu

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,4 @@ _xxsubinterpreters _xxsubinterpretersmodule.c
3535
_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c
3636
ossaudiodev ossaudiodev.c
3737
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
38-
# readline variant needs to come first because libreadline is in /tools/deps and is
39-
# picked up by build. We /could/ make libedit first. But since we employ a hack to
40-
# coerce use of libedit on Linux, it seems prudent for the build system to pick
41-
# up readline.
42-
readline VARIANT=readline readline.c -I/tools/deps/include -I/tools/deps/include/ncursesw -L/tools/deps/lib -lreadline -lncursesw
43-
readline VARIANT=libedit readline-libedit.c -DUSE_LIBEDIT=1 -I/tools/deps/libedit/include -I/tools/deps/libedit/include/ncursesw -L/tools/deps/libedit/lib -ledit -lncursesw
38+
readline readline.c -ledit -lncursesw

cpython-unix/static-modules.3.10.s390x-unknown-linux-gnu

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,4 @@ _xxsubinterpreters _xxsubinterpretersmodule.c
3535
_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c
3636
ossaudiodev ossaudiodev.c
3737
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
38-
# readline variant needs to come first because libreadline is in /tools/deps and is
39-
# picked up by build. We /could/ make libedit first. But since we employ a hack to
40-
# coerce use of libedit on Linux, it seems prudent for the build system to pick
41-
# up readline.
42-
readline VARIANT=readline readline.c -I/tools/deps/include -I/tools/deps/include/ncursesw -L/tools/deps/lib -lreadline -lncursesw
43-
readline VARIANT=libedit readline-libedit.c -DUSE_LIBEDIT=1 -I/tools/deps/libedit/include -I/tools/deps/libedit/include/ncursesw -L/tools/deps/libedit/lib -ledit -lncursesw
38+
readline readline.c -ledit -lncursesw

0 commit comments

Comments
 (0)
0