From 89b583651f1741be4f7dca118c858b6e41c070b0 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Mon, 18 Nov 2024 17:52:49 +0300 Subject: [PATCH 1/4] feat(build): Enable --with[out]-EXECUTABLE=PATH configure flags for tooling dependencies Swaping out custom m4 work with an existing autoconf-archive macro nets us another way to enable or disable specific tools, but more importantly both the new and existing ways are become properly documented in the output of `./configure --help`. This shouldn't change the current way `./configure EXECUTABLE=PATH` can be used to configure tools, just adds another route to get there using `--with[out]-EXECUTABLE=PATH. --- build-aux/que_progvar.m4 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/build-aux/que_progvar.m4 b/build-aux/que_progvar.m4 index 20d1288b4..043a93758 100644 --- a/build-aux/que_progvar.m4 +++ b/build-aux/que_progvar.m4 @@ -1,5 +1,11 @@ AC_DEFUN([QUE_PROGVAR], [ - test -n "$m4_toupper($1)" || { AC_PATH_PROG(m4_toupper($1), m4_default($2,$1)) } - test -n "$m4_toupper($1)" || AC_MSG_ERROR([m4_default($2,$1) is required]) + pushdef([VARIABLE],m4_toupper($1)) + pushdef([EXECUTABLE],m4_default($2,$1)) + AX_WITH_PROG(VARIABLE,EXECUTABLE) + AS_IF([test "x$with_$1" != xno && test -z "$VARIABLE"], [ + AC_MSG_ERROR([EXECUTABLE is required]) + ]) + popdef([EXECUTABLE]) + popdef([VARIABLE]) ]) From aea126776774709113896b27ca0b2906594350e3 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Thu, 21 Nov 2024 14:41:07 +0300 Subject: [PATCH 2/4] refactor(build): Redo Lua module detector with an eye towards upsteraming --- build-aux/ax_lua_module.m4 | 15 ---------- build-aux/ax_lua_require.m4 | 56 +++++++++++++++++++++++++++++++++++++ configure.ac | 44 ++++++++++++++--------------- 3 files changed, 77 insertions(+), 38 deletions(-) delete mode 100644 build-aux/ax_lua_module.m4 create mode 100644 build-aux/ax_lua_require.m4 diff --git a/build-aux/ax_lua_module.m4 b/build-aux/ax_lua_module.m4 deleted file mode 100644 index ef4b2e57b..000000000 --- a/build-aux/ax_lua_module.m4 +++ /dev/null @@ -1,15 +0,0 @@ -#serial 0 - -AC_DEFUN([AX_LUA_MODULE], -[ - AX_PROG_LUA([5.1], [], [], [], [prefer]) - AC_MSG_CHECKING([whether Lua can load module $1]) - AS_IF([$LUA -e 'require("$1")' 2>/dev/null], [ - AC_MSG_RESULT([loaded]) - $3 - ], [ - AC_MSG_RESULT([unable to load]) - m4_default([$4], [AC_MSG_ERROR([cannot find Lua library $1 - install from luarocks package $2])]) - ]) -]) - diff --git a/build-aux/ax_lua_require.m4 b/build-aux/ax_lua_require.m4 new file mode 100644 index 000000000..3850b03d6 --- /dev/null +++ b/build-aux/ax_lua_require.m4 @@ -0,0 +1,56 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_lua_require.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_LUA_REQUIRE([MODULE], [ROCKNAME]) +# +# DESCRIPTION +# +# Tests whether Lua can load a module, fails if it is not loadable. +# +# Example usage: +# +# AX_LUA_REQUIRE(lpeg) +# +# Note: this is an alternative to AX_LUAROCKS_ROCK which queries the +# LuaRocks manifest for whether something is installed. Sometimes a +# proper manifest is not available, and this tests whether a given +# module name is actually loadable. +# +# It can also be useful to test for libraries that may or may not be +# built into Lua VMs. Builtin modules will return a success. +# +# LICENSE +# +# Copyright (c) 2024 Caleb Maclennan +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 1 + +AC_DEFUN([AX_LUA_REQUIRE],[ + # Make sure we have a Lua interpreter + AS_IF([test -z "$LUA"], [ + AC_MSG_ERROR([No Lua VM set, consider using [AX_PROG_LUA] to set one]) + ]) + + AC_PREREQ([2.61]) + + pushdef([MODULE],$1) + pushdef([ROCKNAME],m4_default($2,$1)) + AC_MSG_CHECKING([whether Lua can load module MODULE]) + AS_IF([$LUA -e 'require("MODULE")' 2>/dev/null], [ + AC_MSG_RESULT([loaded]) + ], [ + AC_MSG_RESULT([unable to load]) + AC_MSG_ERROR([cannot find Lua library MODULE, consider installing ROCKNAME via luarocks]) + ]) + popdef([MODULE]) + popdef([ROCKNAME]) +]) + diff --git a/configure.ac b/configure.ac index 00ba91f31..6b75c8bc3 100644 --- a/configure.ac +++ b/configure.ac @@ -205,30 +205,28 @@ AX_LUA_LIBS AM_COND_IF([SYSTEM_LUAROCKS], [ AS_IF([test "$LUA_SHORT_VERSION" -lt 52], [ - AM_COND_IF([LUAJIT], [], [ - AX_LUA_MODULE([bit32], [bit32]) + AM_COND_IF([LUAJIT], [], [AX_LUA_REQUIRE([bit32])]) + ], + [test "$LUA_SHORT_VERSION" -lt 53], [ + AX_LUA_REQUIRE([compat53]) ]) - ]) - AX_LUA_MODULE([cassowary], [cassowary]) - AS_IF([test "$LUA_SHORT_VERSION" -lt 53], [ - AX_LUA_MODULE([compat53], [compat53]) - ]) - AX_LUA_MODULE([cldr], [cldr]) - AX_LUA_MODULE([fluent], [fluent]) - AX_LUA_MODULE([linenoise], [linenoise]) - AX_LUA_MODULE([loadkit], [loadkit]) - AX_LUA_MODULE([lpeg], [lpeg]) - AX_LUA_MODULE([zlib], [lua-zlib]) - AX_LUA_MODULE([cliargs], [lua_cliargs]) - AX_LUA_MODULE([epnf], [luaepnf]) - AX_LUA_MODULE([lxp], [luaexpat]) - AX_LUA_MODULE([lfs], [luafilesystem]) - AX_LUA_MODULE([repl], [luarepl]) - AX_LUA_MODULE([ssl], [luasec]) - AX_LUA_MODULE([socket], [luasocket]) - AX_LUA_MODULE([lua-utf8], [luautf8]) - AX_LUA_MODULE([pl], [penlight]) - AX_LUA_MODULE([vstruct], [vstruct]) + AX_LUA_REQUIRE([cassowary]) + AX_LUA_REQUIRE([cldr]) + AX_LUA_REQUIRE([fluent]) + AX_LUA_REQUIRE([linenoise]) + AX_LUA_REQUIRE([loadkit]) + AX_LUA_REQUIRE([lpeg]) + AX_LUA_REQUIRE([zlib], [lua-zlib]) + AX_LUA_REQUIRE([cliargs], [lua_cliargs]) + AX_LUA_REQUIRE([epnf], [luaepnf]) + AX_LUA_REQUIRE([lxp], [luaexpat]) + AX_LUA_REQUIRE([lfs], [luafilesystem]) + AX_LUA_REQUIRE([repl], [luarepl]) + AX_LUA_REQUIRE([ssl], [luasec]) + AX_LUA_REQUIRE([socket], [luasocket]) + AX_LUA_REQUIRE([lua-utf8], [luautf8]) + AX_LUA_REQUIRE([pl], [penlight]) + AX_LUA_REQUIRE([vstruct]) ], [ QUE_PROGVAR([luarocks]) QUE_PROGVAR([git]) # required for luarocks to install zlib rock From 81f7b2baf568ebf0df6c062e71a40e0487269ade Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Thu, 21 Nov 2024 16:17:20 +0300 Subject: [PATCH 3/4] chore(build): Handle both rocks or modules when fulfilling Lua deps --- build-aux/ax_lua_module.m4 | 53 ++++++++++++++++++++++++++++++ build-aux/ax_lua_require.m4 | 23 +++++++++---- build-aux/ax_luarocks_rock.m4 | 62 +++++++++++++++++++++++++++++++++++ configure.ac | 43 ++++++++++++------------ 4 files changed, 152 insertions(+), 29 deletions(-) create mode 100644 build-aux/ax_lua_module.m4 create mode 100644 build-aux/ax_luarocks_rock.m4 diff --git a/build-aux/ax_lua_module.m4 b/build-aux/ax_lua_module.m4 new file mode 100644 index 000000000..3d1f74ea5 --- /dev/null +++ b/build-aux/ax_lua_module.m4 @@ -0,0 +1,53 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_lua_module.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_LUA_MODULE([ROCKNAME], [MODULE]) +# +# DESCRIPTION +# +# Tests the availability of a Lua module using both available mechanisms, +# first checking if a Lua Rock manifest is available, and if not falling +# back to attempting to load a module directly. +# +# If the module name is the same as the rock name, the second argument can +# be ommitted. +# +# Example usage: +# +# AX_LUA_MODULE([ssl], [luasec]) +# +# Note: under the hood this uses AX_LUAROCKS_ROCK and AX_LUA_REQUIRE. +# +# LICENSE +# +# Copyright (c) 2024 Caleb Maclennan +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 1 + +AC_DEFUN([AX_LUA_MODULE],[ + pushdef([ROCKNAME],$1) + pushdef([MODULE],m4_default($2,$1)) + pushdef([VARIABLE],LUA_HAS_[]m4_toupper(m4_translit($1,-.,__))) + + AC_ARG_VAR(VARIABLE,Was Lua module found) + + AS_IF(test -z "$VARIABLE",[ + AX_LUAROCKS_ROCK(ROCKNAME,[VARIABLE=yes],[VARIABLE=no]) + AS_IF([test "x$VARIABLE" != xyes],[ + AX_LUA_REQUIRE(MODULE,[VARIABLE=yes]) + ]) + ]) + + popdef([ROCKNAME]) + popdef([MODULE]) +]) + + diff --git a/build-aux/ax_lua_require.m4 b/build-aux/ax_lua_require.m4 index 3850b03d6..8aebb1d1f 100644 --- a/build-aux/ax_lua_require.m4 +++ b/build-aux/ax_lua_require.m4 @@ -4,7 +4,7 @@ # # SYNOPSIS # -# AX_LUA_REQUIRE([MODULE], [ROCKNAME]) +# AX_LUA_REQUIRE([MODULE], [ACTION_IF_FOUND], [ACTION_IF_NOT_FOUND]) # # DESCRIPTION # @@ -35,22 +35,31 @@ AC_DEFUN([AX_LUA_REQUIRE],[ # Make sure we have a Lua interpreter - AS_IF([test -z "$LUA"], [ - AC_MSG_ERROR([No Lua VM set, consider using [AX_PROG_LUA] to set one]) - ]) + if test -z "$LUA"; then + AX_PROG_LUA + if test -z "$LUA"; then + AC_MSG_ERROR([No Lua VM set]) + fi + fi AC_PREREQ([2.61]) pushdef([MODULE],$1) - pushdef([ROCKNAME],m4_default($2,$1)) + pushdef([ACTION_IF_FOUND],$2) + pushdef([ACTION_IF_NOT_FOUND],$3) + AC_MSG_CHECKING([whether Lua can load module MODULE]) AS_IF([$LUA -e 'require("MODULE")' 2>/dev/null], [ AC_MSG_RESULT([loaded]) + ACTION_IF_FOUND ], [ AC_MSG_RESULT([unable to load]) - AC_MSG_ERROR([cannot find Lua library MODULE, consider installing ROCKNAME via luarocks]) + m4_ifset([ACTION_IF_NOT_FOUND][ACTION_IF_NOT_FOUND], + [AC_MSG_FAILURE([cannot find Lua module MODULE])]) ]) + popdef([MODULE]) - popdef([ROCKNAME]) + popdef([ACTION_IF_FOUND]) + popdef([ACTION_IF_NOT_FOUND]) ]) diff --git a/build-aux/ax_luarocks_rock.m4 b/build-aux/ax_luarocks_rock.m4 new file mode 100644 index 000000000..3e98700f7 --- /dev/null +++ b/build-aux/ax_luarocks_rock.m4 @@ -0,0 +1,62 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_luarocks_rock.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_LUAROCKS_ROCK([ROCKNAME], [ACTION_IF_FOUND], [ACTION_IF_NOT_FOUND]) +# +# DESCRIPTION +# +# Checks for a rock, and fails if it is not installed. +# +# Example usage: +# +# AX_LUAROCKS_ROCK(stdlib) +# +# Note: use of this macro is not normally recommended. Normally, LuaRocks +# should be used to drive the build system, and it takes care of rock +# dependencies. Use this macro only if LuaRocks cannot be used at the top +# level, for example, in a build system that uses Lua only incidentally. +# +# LICENSE +# +# Copyright (c) 2024 Caleb Maclennan +# Copyright (c) 2016 Reuben Thomas +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 4 + +AC_DEFUN([AX_LUAROCKS_ROCK],[ + # Make sure we have luarocks + if test -z "$LUAROCKS"; then + AX_WITH_PROG(LUAROCKS,luarocks) + if test -z "$LUAROCKS"; then + AC_MSG_ERROR([can't find luarocks]) + fi + fi + + AC_PREREQ([2.61]) + + pushdef([ROCKNAME],$1) + pushdef([ACTION_IF_FOUND],$2) + pushdef([ACTION_IF_NOT_FOUND],$3) + + AC_MSG_CHECKING(whether LuaRock ROCKNAME is installed) + AS_IF(["$LUAROCKS"${LUA_VERSION+ --lua-version $LUA_VERSION} show ROCKNAME > /dev/null 2>&1],[ + AC_MSG_RESULT(yes) + ACTION_IF_FOUND + ],[ + AC_MSG_RESULT(no) + m4_ifset([ACTION_IF_NOT_FOUND],[ACTION_IF_NOT_FOUND], + [AC_MSG_FAILURE([LuaRock ROCKNAME not found])]) + ]) + + popdef([ROCKNAME]) + popdef([ACTION_IF_FOUND]) + popdef([ACTION_IF_NOT_FOUND]) +]) diff --git a/configure.ac b/configure.ac index 6b75c8bc3..d3ff56d1a 100644 --- a/configure.ac +++ b/configure.ac @@ -205,28 +205,27 @@ AX_LUA_LIBS AM_COND_IF([SYSTEM_LUAROCKS], [ AS_IF([test "$LUA_SHORT_VERSION" -lt 52], [ - AM_COND_IF([LUAJIT], [], [AX_LUA_REQUIRE([bit32])]) - ], - [test "$LUA_SHORT_VERSION" -lt 53], [ - AX_LUA_REQUIRE([compat53]) - ]) - AX_LUA_REQUIRE([cassowary]) - AX_LUA_REQUIRE([cldr]) - AX_LUA_REQUIRE([fluent]) - AX_LUA_REQUIRE([linenoise]) - AX_LUA_REQUIRE([loadkit]) - AX_LUA_REQUIRE([lpeg]) - AX_LUA_REQUIRE([zlib], [lua-zlib]) - AX_LUA_REQUIRE([cliargs], [lua_cliargs]) - AX_LUA_REQUIRE([epnf], [luaepnf]) - AX_LUA_REQUIRE([lxp], [luaexpat]) - AX_LUA_REQUIRE([lfs], [luafilesystem]) - AX_LUA_REQUIRE([repl], [luarepl]) - AX_LUA_REQUIRE([ssl], [luasec]) - AX_LUA_REQUIRE([socket], [luasocket]) - AX_LUA_REQUIRE([lua-utf8], [luautf8]) - AX_LUA_REQUIRE([pl], [penlight]) - AX_LUA_REQUIRE([vstruct]) + AM_COND_IF([LUAJIT], [], [AX_LUA_MODULE(bit32)]) + ]) + AX_LUA_MODULE(cassowary) + AS_IF([test "$LUA_SHORT_VERSION" -lt 53], [AX_LUA_MODULE(compat53)]) + AX_LUA_MODULE(cldr) + AX_LUA_MODULE(fluent) + AX_LUA_MODULE(linenoise) + AX_LUA_MODULE(loadkit) + AX_LUA_MODULE(lpeg) + AX_LUA_MODULE(lua-zlib, zlib) + AX_LUA_MODULE(lua_cliargs, cliargs) + AX_LUA_MODULE(luaepnf, epnf) + AX_LUA_MODULE(luaexpat, lxp) + AX_LUA_MODULE(luafilesystem, lfs) + AX_LUA_MODULE(luafilesystem) + AX_LUA_MODULE(luarepl, repl) + AX_LUA_MODULE(luasec, ssl) + AX_LUA_MODULE(luasocket, socket) + AX_LUA_MODULE(luautf8, lua-utf8) + AX_LUA_MODULE(penlight, pl) + AX_LUA_MODULE(vstruct) ], [ QUE_PROGVAR([luarocks]) QUE_PROGVAR([git]) # required for luarocks to install zlib rock From 3c670e1ca4b88634f9426e8eec5e6094edf89470 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 23 Nov 2024 12:17:34 +0300 Subject: [PATCH 4/4] chore(deps): Make LuaRocks a dependency for all build types so we can find manifests --- .cirrus.yml | 1 + build-aux/pkg.nix | 4 ++++ configure.ac | 3 +-- flake.nix | 1 - 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index b4c9b3f47..61d6ab423 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -50,6 +50,7 @@ task: --disable-font-variations \ --with-system-lua-sources \ --with-system-luarocks \ + --with-luarocks=luarocks51 \ --without-manual make_script: - gmake all diff --git a/build-aux/pkg.nix b/build-aux/pkg.nix index 2cf64e802..6b9fd535e 100644 --- a/build-aux/pkg.nix +++ b/build-aux/pkg.nix @@ -45,6 +45,10 @@ let ps: with ps; [ + # used for module detection, also recommended at runtime for 3rd party module installation + luarocks + + # modules used at runtime cassowary cldr fluent diff --git a/configure.ac b/configure.ac index d3ff56d1a..0404287c7 100644 --- a/configure.ac +++ b/configure.ac @@ -25,6 +25,7 @@ QUE_PROGVAR([diff]) QUE_PROGVAR([find]) QUE_PROGVAR([head]) QUE_PROGVAR([jq]) +QUE_PROGVAR([luarocks]) QUE_PROGVAR([pdfinfo]) QUE_PROGVAR([sort]) QUE_PROGVAR([xargs]) @@ -189,7 +190,6 @@ AM_COND_IF([DEVELOPER_TOOLS], [ QUE_PROGVAR([curl]) QUE_PROGVAR([ldoc]) QUE_PROGVAR([luacheck]) - QUE_PROGVAR([luarocks]) QUE_PROGVAR([nix]) QUE_PROGVAR([npm]) QUE_PROGVAR([perl]) @@ -227,7 +227,6 @@ AM_COND_IF([SYSTEM_LUAROCKS], [ AX_LUA_MODULE(penlight, pl) AX_LUA_MODULE(vstruct) ], [ - QUE_PROGVAR([luarocks]) QUE_PROGVAR([git]) # required for luarocks to install zlib rock ]) diff --git a/flake.nix b/flake.nix index 0a9c4ee36..4a2814a36 100644 --- a/flake.nix +++ b/flake.nix @@ -87,7 +87,6 @@ "--with-manual" ]; nativeBuildInputs = sile.nativeBuildInputs ++ [ - pkgs.luarocks # For regression test diff highlighting pkgs.delta # For commitlint git hook