Skip to content

Commit

Permalink
chore(build): Handle both rocks or modules when fulfilling Lua deps
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Nov 22, 2024
1 parent aea1267 commit 4c59ced
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 29 deletions.
53 changes: 53 additions & 0 deletions build-aux/ax_lua_module.m4
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
#
# 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])
])


23 changes: 16 additions & 7 deletions build-aux/ax_lua_require.m4
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# SYNOPSIS
#
# AX_LUA_REQUIRE([MODULE], [ROCKNAME])
# AX_LUA_REQUIRE([MODULE], [ACTION_IF_FOUND], [ACTION_IF_NOT_FOUND])
#
# DESCRIPTION
#
Expand Down Expand Up @@ -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])
])

62 changes: 62 additions & 0 deletions build-aux/ax_luarocks_rock.m4
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
# Copyright (c) 2016 Reuben Thomas <[email protected]>
#
# 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])
])
43 changes: 21 additions & 22 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4c59ced

Please sign in to comment.