Improve build sytem support for readline instead of editline

Changes:

- CPP variable is now `USE_READLINE` not `READLINE`

- `configure.ac` supports with new CLI flag

- `package.nix` supports with new configuration option

- `flake.nix` CIs this (along with no markdown)

Remove old Ubuntu 16.04 stop-gap too, as that is now quite old.

Motivation:

- editline does not build for Windows, but readline *should*. (I am
  still working on this in Nixpkgs at this time, however. So there will
  be a follow-up Nix PR removing the windows-only skipping of the
  readline library once I am done.)

- Per
  https://salsa.debian.org/debian/nix/-/blob/master/debian/rules?ref_type=heads#L27
  and #2551, Debian builds Nix with readline. Now we better support and
  CI that build configuration.

This is picking up where #2551 left off, ensuring we test a few more
things not merely have CPP for them.

Co-authored-by: Weijia Wang <9713184+wegank@users.noreply.github.com>
This commit is contained in:
John Ericson 2023-09-02 15:56:37 -04:00
parent b91c935c2f
commit 2cea88dbc8
4 changed files with 41 additions and 15 deletions

View file

@ -251,17 +251,25 @@ PKG_CHECK_MODULES([SQLITE3], [sqlite3 >= 3.6.19], [CXXFLAGS="$SQLITE3_CFLAGS $CX
# Look for libcurl, a required dependency. # Look for libcurl, a required dependency.
PKG_CHECK_MODULES([LIBCURL], [libcurl], [CXXFLAGS="$LIBCURL_CFLAGS $CXXFLAGS"]) PKG_CHECK_MODULES([LIBCURL], [libcurl], [CXXFLAGS="$LIBCURL_CFLAGS $CXXFLAGS"])
# Look for editline, a required dependency. # Look for editline or readline, a required dependency.
# The the libeditline.pc file was added only in libeditline >= 1.15.2, # The the libeditline.pc file was added only in libeditline >= 1.15.2,
# see https://github.com/troglobit/editline/commit/0a8f2ef4203c3a4a4726b9dd1336869cd0da8607, # see https://github.com/troglobit/editline/commit/0a8f2ef4203c3a4a4726b9dd1336869cd0da8607,
# but e.g. Ubuntu 16.04 has an older version, so we fall back to searching for # Older versions are no longer supported.
# editline.h when the pkg-config approach fails. AC_ARG_WITH(
PKG_CHECK_MODULES([EDITLINE], [libeditline], [CXXFLAGS="$EDITLINE_CFLAGS $CXXFLAGS"], [ [readline-flavor],
AC_CHECK_HEADERS([editline.h], [true], AS_HELP_STRING([--with-readline-flavor],[Which library to use for nice line editting with the Nix language REPL" [default=editline]]),
[AC_MSG_ERROR([Nix requires libeditline; it was found neither via pkg-config nor its normal header.])]) [readline_flavor=$withval],
AC_SEARCH_LIBS([readline read_history], [editline], [], [readline_flavor=editline])
[AC_MSG_ERROR([Nix requires libeditline; it was not found via pkg-config, but via its header, but required functions do not work. Maybe it is too old? >= 1.14 is required.])]) AS_CASE(["$readline_flavor"],
]) [editline], [
readline_flavor_pc=libeditline
],
[readline], [
readline_flavor_pc=readline
AC_DEFINE([USE_READLINE], [1], [Use readline instead of editline])
],
[AC_MSG_ERROR([bad value "$readline_flavor" for --with-readline-flavor, must be one of: editline, readline])])
PKG_CHECK_MODULES([EDITLINE], [$readline_flavor_pc], [CXXFLAGS="$EDITLINE_CFLAGS $CXXFLAGS"])
# Look for libsodium. # Look for libsodium.
PKG_CHECK_MODULES([SODIUM], [libsodium], [CXXFLAGS="$SODIUM_CFLAGS $CXXFLAGS"]) PKG_CHECK_MODULES([SODIUM], [libsodium], [CXXFLAGS="$SODIUM_CFLAGS $CXXFLAGS"])
@ -387,8 +395,7 @@ AS_CASE(["$enable_markdown"],
]) ])
], ],
[no], [have_lowdown=], [no], [have_lowdown=],
[AC_MSG_ERROR([--enable-markdown must be one of: yes, no, auto])]) [AC_MSG_ERROR([bad value "$enable_markdown" for --enable-markdown, must be one of: yes, no, auto])])
AC_SUBST(HAVE_LOWDOWN, [$have_lowdown])
# Look for libgit2. # Look for libgit2.

View file

@ -230,6 +230,15 @@
} }
); );
# Toggles some settings for better coverage. Windows needs these
# library combinations, and Debian build Nix with GNU readline too.
buildReadlineNoMarkdown = forAllSystems (system:
self.packages.${system}.nix.override {
enableMarkdown = false;
readlineFlavor = "readline";
}
);
# Perl bindings for various platforms. # Perl bindings for various platforms.
perlBindings = forAllSystems (system: nixpkgsFor.${system}.native.nix.perl-bindings); perlBindings = forAllSystems (system: nixpkgsFor.${system}.native.nix.perl-bindings);

View file

@ -13,6 +13,7 @@
, changelog-d , changelog-d
, curl , curl
, editline , editline
, readline
, fileset , fileset
, flex , flex
, git , git
@ -71,6 +72,14 @@
# Whether to enable Markdown rendering in the Nix binary. # Whether to enable Markdown rendering in the Nix binary.
, enableMarkdown ? !stdenv.hostPlatform.isWindows , enableMarkdown ? !stdenv.hostPlatform.isWindows
# Which interactive line editor library to use for Nix's repl.
#
# Currently supported choices are:
#
# - editline (default)
# - readline
, readlineFlavor ? if stdenv.hostPlatform.isWindows then "readline" else "editline"
# Whether to compile `rl-next.md`, the release notes for the next # Whether to compile `rl-next.md`, the release notes for the next
# not-yet-released version of Nix in the manul, from the individual # not-yet-released version of Nix in the manul, from the individual
# change log entries in the directory. # change log entries in the directory.
@ -219,7 +228,7 @@ in {
sqlite sqlite
xz xz
] ++ lib.optionals (!stdenv.hostPlatform.isWindows) [ ] ++ lib.optionals (!stdenv.hostPlatform.isWindows) [
editline ({ inherit readline editline; }.${readlineFlavor})
] ++ lib.optionals enableMarkdown [ ] ++ lib.optionals enableMarkdown [
lowdown lowdown
] ++ lib.optionals buildUnitTests [ ] ++ lib.optionals buildUnitTests [
@ -279,6 +288,7 @@ in {
(lib.enableFeature enableManual "doc-gen") (lib.enableFeature enableManual "doc-gen")
(lib.enableFeature enableMarkdown "markdown") (lib.enableFeature enableMarkdown "markdown")
(lib.enableFeature installUnitTests "install-unit-tests") (lib.enableFeature installUnitTests "install-unit-tests")
(lib.withFeatureAs true "readline-flavor" readlineFlavor)
] ++ lib.optionals (!forDevShell) [ ] ++ lib.optionals (!forDevShell) [
"--sysconfdir=/etc" "--sysconfdir=/etc"
] ++ lib.optionals installUnitTests [ ] ++ lib.optionals installUnitTests [

View file

@ -5,7 +5,7 @@
#include <setjmp.h> #include <setjmp.h>
#ifdef READLINE #ifdef USE_READLINE
#include <readline/history.h> #include <readline/history.h>
#include <readline/readline.h> #include <readline/readline.h>
#else #else
@ -249,14 +249,14 @@ void NixRepl::mainLoop()
} catch (SysError & e) { } catch (SysError & e) {
logWarning(e.info()); logWarning(e.info());
} }
#ifndef READLINE #ifndef USE_READLINE
el_hist_size = 1000; el_hist_size = 1000;
#endif #endif
read_history(historyFile.c_str()); read_history(historyFile.c_str());
auto oldRepl = curRepl; auto oldRepl = curRepl;
curRepl = this; curRepl = this;
Finally restoreRepl([&] { curRepl = oldRepl; }); Finally restoreRepl([&] { curRepl = oldRepl; });
#ifndef READLINE #ifndef USE_READLINE
rl_set_complete_func(completionCallback); rl_set_complete_func(completionCallback);
rl_set_list_possib_func(listPossibleCallback); rl_set_list_possib_func(listPossibleCallback);
#endif #endif