@@ -493,24 +493,22 @@ diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py
493
493
if _os.name == "nt":
494
494
EOF
495
495
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 .
499
499
#
500
500
# 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
505
503
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
514
512
diff --git a/Modules/readline-libedit.c b/Modules/readline-libedit.c
515
513
index 1e74f997b0..56a36e26e6 100644
516
514
--- a/Modules/readline-libedit.c
@@ -543,6 +541,7 @@ index 1e74f997b0..56a36e26e6 100644
543
541
#endif
544
542
rl_cleanup_after_signal();
545
543
EOF
544
+ fi
546
545
547
546
# iOS doesn't have system(). Teach posixmodule.c about that.
548
547
if [ " ${PYTHON_MAJMIN_VERSION} " != " 3.8" ]; then
572
571
# So we need to set both.
573
572
CFLAGS=" ${EXTRA_TARGET_CFLAGS} -fPIC -I${TOOLS_PATH} /deps/include -I${TOOLS_PATH} /deps/include/ncursesw"
574
573
LDFLAGS=" ${EXTRA_TARGET_LDFLAGS} -L${TOOLS_PATH} /deps/lib"
574
+ EXTRA_CONFIGURE_FLAGS=
575
575
576
576
if [ " ${PYBUILD_PLATFORM} " = " macos" ]; then
577
577
CFLAGS=" ${CFLAGS} -I${TOOLS_PATH} /deps/include/uuid"
@@ -580,14 +580,27 @@ if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
580
580
CFLAGS=" ${CFLAGS} -Werror=unguarded-availability-new"
581
581
fi
582
582
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
+
583
595
CPPFLAGS=$CFLAGS
584
596
585
597
CONFIGURE_FLAGS="
586
598
--build=${BUILD_TRIPLE} \
587
599
--host=${TARGET_TRIPLE}
588
600
--prefix=/install
589
601
--with-openssl=${TOOLS_PATH} /deps
590
- --without-ensurepip"
602
+ --without-ensurepip
603
+ ${EXTRA_CONFIGURE_FLAGS} "
591
604
592
605
if [ " ${CC} " = " musl-clang" ]; then
593
606
CFLAGS=" ${CFLAGS} -static"
0 commit comments