44.6. lua54-luafilesystem-1.9.0
stat, mkdir and readdir for Lua 5.4
| Version | 1.9.0, release 1 |
| Shelf | lang — Language implementations, plus the modules of any language that has no module shelf of its own |
| Phase | 30_foundation (Build Foundation), 109 of 127 in build order |
| Licence | MIT |
| Homepage | https://github.com/lunarmodules/luafilesystem |
| Build time | 0.1 SBU |
| Installed size | 27.8 KiB in 2 files |
| Recipe | ports/core/lang/lua54-luafilesystem/kpkgbuild |
About
LuaFileSystem is the lfs module: stat, mkdir, rmdir, directory iteration, locking and symbolic-link queries for Lua, which the language’s own standard library leaves out. It is one C file compiled into lfs.so, a module Lua loads with require "lfs".
In KDOS it exists for Prosody, the XMPP server, which is its only reverse dependency. Prosody runs on Lua 5.4, so this port builds against lua54, the 5.4 interpreter installed beside the newer one of the lua port, and installs into that version’s own module directory, /usr/lib/lua/5.4. Prosody’s startup check, util/dependencies.lua, treats a missing lfs as fatal and refuses to start. The port is built in 30_foundation with the other Lua 5.4 modules Prosody depends on, lua54-luasocket, lua54-luasec and lua54-luaexpat.
The project has no configure step. Its Makefile includes a file named config that sets the Lua version, the include path, the compiler flags and the link command as make variables, and build.sh overrides each of them on the command line instead of editing that file.
Why it is in KDOS
The comment above the 4 ports from lua54-luasocket to lua54-luafilesystem in script/phases/30_foundation/packages.txt:
The four modules Prosody will not start without: a transport, TLS over it, an XML parser (XMPP is XML on the wire) and stat/mkdir/readdir.
Sources
lua54-luafilesystem-1.9.0.tar.gz(28.6 KiB)
sha2561142c1876e999b3e28d1c236bf21ffd9b023018e336ac25120fb5373aade1450
upstream: https://github.com/lunarmodules/luafilesystem/archive/refs/tags/v1_9_0.tar.gz
archive copy: sources-3/lang--lua54-luafilesystem-1.9.0.tar.gz
Dependencies
Depends on: lua54.
Required by (1): prosody.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/30_foundation/phase.env && kpkg install lua54-luafilesystem'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/lang/lua54-luafilesystem.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/lang/lua54-luafilesystem
echo '1142c1876e999b3e28d1c236bf21ffd9b023018e336ac25120fb5373aade1450 lua54-luafilesystem-1.9.0.tar.gz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/lua54-luafilesystem
SRC=$SRC_ROOT/lua54-luafilesystem-1.9.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf lua54-luafilesystem-1.9.0.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the recipe’s helpers _lv, _tag and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
make LUA_VERSION=$_lv \
LUA_INC="-I/usr/include/lua$_lv" \
CFLAGS="$CFLAGS -fPIC -I/usr/include/lua$_lv" \
LIB_OPTION="-shared $LDFLAGS"
make DESTDIR=$PKG PREFIX=/usr LUA_VERSION=$_lv install
The switches, and why each is set:
LUA_VERSION— the Lua version the module is built for.configdefaults it to an older Lua. It names the install directory,$(PREFIX)/lib/lua/$(LUA_VERSION), and the versioned include directories ofconfig’s defaultLUA_INC; on both lines it is the recipe’s_lvhelper,5.4.LUA_INC— the compiler’s include path forlua.h. The default adds$(PREFIX)/include, which is/usr/local/include, as well as the versioned directories; this sets only/usr/include/lua5.4, where the lua54 port installs its headers.configreadsLUA_INConly inside its ownCFLAGS, which the next switch replaces, so the include directory that reaches the compiler is the one written into that replacement.CFLAGS— replacesconfig’s wholeCFLAGS, which is its warnings,-O2 -fPICand the include path. The replacement is the tree’s exported flags with-fPICand the include directory appended. The tree’s flags already carry-fPIC; the include directory has to be named here, because the override dropsconfig’s.LIB_OPTION— the link command’s options.configsets-sharedand nothing else, so the module would be linked without the tree’sLDFLAGS(-z now,--as-needed, the build ID); the replacement keeps-sharedand adds them.PREFIX=/usr— the install root.configdefaults to/usr/local, which the package lint refuses.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/lua54-luafilesystem, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf lua54-luafilesystem-1.9.0-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/lua54-luafilesystem, and runs the triggers its paths call for.
Contents
Installed directories: /usr/share/licenses/lua54-luafilesystem.
Notes
The include directory in CFLAGS and LUA_VERSION on the install line must name the same Lua version. The first chooses the headers and the second the directory, so with two different values the module is compiled for one interpreter and put where only the other looks for it; the recipe takes both from _lv. Lua 5.4 looks for C modules in /usr/lib/lua/5.4 because the lua54 port’s lua-root-usr.patch changes LUA_ROOT in luaconf.h from /usr/local/ to /usr/; without that patch, a module installed here would not be found.