git: 2ef21abe8960 - stable/15 - flua: support our flua modules in the bootstrap flua

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Sat, 11 Apr 2026 15:49:10 UTC
The branch stable/15 has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=2ef21abe8960737238cb519c204131d1d6e31361

commit 2ef21abe8960737238cb519c204131d1d6e31361
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2025-10-03 18:09:03 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2026-04-11 03:18:20 +0000

    flua: support our flua modules in the bootstrap flua
    
    This version builds every module into the flua binary itself, since all
    of the bootstrap tools are built -DNO_SHARED.  As a result, we also
    cannot dlsym(), so we can't really discover the names of our newly
    builtin modules.  Instead, just build out a linker set with all of our
    luaopen_*() functions to register everything up-front.
    
    Building in all of the modules isn't strictly necessary, but it means
    that we have an example of how to add a bootstrap module everywhere you
    go and one doesn't need to consider whether bootstrap flua can use a
    module when writing scripts.  On my build machine, the consequence on
    our binary size is an increase from around 1.6M -> 1.9M, which isn't
    really that bad.
    
    .lua modules can install into their usual path below $WORLDTMP/legacy
    and we'll pick them up automagically by way of the ctor that sets up
    LUA_PATH early on.
    
    This re-lands bootstrap module support with a more sensible subset, and
    after having verified that it cross-builds fine on macOS and Linux -- we
    cannot do libfreebsd on !FreeBSD because it's more system header
    dependant.  We also need to bootstrap libmd to bring in libhash, and
    libucl + libyaml.
    
    Reviewed by:    bapt, emaste (both previous version)
    
    (cherry picked from commit 1953a12ee2cde1afacb3e3f7612d89695c96e04f)
    (cherry picked from commit 80ada959004c4386880e47b11618f8abfc2d80e1)
    (cherry picked from commit 31320402472394af57eb3a36bee7f944117ca0ed)
    (cherry picked from commit 981cf36d64c48ebfa22d44ac83b6d448c2974f23)
    (cherry picked from commit d4c973fa148544a0b949ceb1efb6c68096f02baf)
    (cherry picked from commit bbef1c72b4873b657fdb0466b48b15d1d4f0a731)
    (cherry picked from commit 151bd3516b541823b16793460d73916e63d2b9c1)
    
    build: don't create duplicate bootstrap-tools targets
    
    The general problem is that we might have a somewhat complicated
    dependency tree depending on bootstrap version requirements.  We could
    document when multiple bootstrap tools might have a shared dependency
    and be careful to add them only once to the list, but that is a little
    more fragile- particularly if we purge some bootstrap tools and need to
    re-work the logic a little bit.
    
    Just avoid redefining the build commands as we're iterating over the
    list so that we can keep the actual requirements intact.
    
    Reported by:    dhw, others
    Reviewed by:    imp
    
    (cherry picked from commit ab492c08fc3cbf4fb5d569663c0751bc2a41cb1f)
---
 Makefile.inc1                                   | 15 ++++++++-
 contrib/libucl/lua/lua_ucl.c                    |  4 +++
 contrib/lyaml/ext/yaml/yaml.c                   |  4 +++
 libexec/flua/Makefile                           | 42 +++++++++++++++++++++----
 libexec/flua/Makefile.inc                       |  7 ++++-
 libexec/flua/bootstrap.h                        | 32 +++++++++++++++++++
 libexec/flua/libfreebsd/kenv/Makefile           |  2 +-
 libexec/flua/libfreebsd/kenv/Makefile.inc       |  2 ++
 libexec/flua/libfreebsd/kenv/kenv.c             |  4 +++
 libexec/flua/libfreebsd/sys/linker/Makefile     |  3 +-
 libexec/flua/libfreebsd/sys/linker/Makefile.inc |  2 ++
 libexec/flua/libfreebsd/sys/linker/linker.c     |  4 +++
 libexec/flua/libhash/Makefile                   |  5 +--
 libexec/flua/libhash/Makefile.inc               |  3 ++
 libexec/flua/libhash/lhash.c                    |  4 +++
 libexec/flua/libjail/Makefile                   |  5 +--
 libexec/flua/libjail/Makefile.inc               |  3 ++
 libexec/flua/libjail/lua_jail.c                 |  4 +++
 libexec/flua/liblyaml/Makefile                  | 20 +-----------
 libexec/flua/liblyaml/Makefile.inc              | 20 ++++++++++++
 libexec/flua/libucl/Makefile                    | 12 +------
 libexec/flua/libucl/Makefile.inc                | 12 +++++++
 libexec/flua/linit_flua.c                       | 29 ++++++++++++++++-
 tools/build/Makefile                            |  1 +
 24 files changed, 189 insertions(+), 50 deletions(-)

diff --git a/Makefile.inc1 b/Makefile.inc1
index 30d37e6bd2f5..d8890822d6ad 100644
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -2616,6 +2616,10 @@ ${_bt}-usr.sbin/kldxref: ${_bt_libelf_depend} ${_bt_libkldelf_depend}
 .if ${BOOTSTRAPPING} < 1300059
 ${_bt}-libexec/flua: ${_bt}-lib/liblua
 _flua= lib/liblua libexec/flua
+.if ${BOOTSTRAPPING} == 0
+_flua+= lib/libmd lib/libucl lib/libyaml
+${_bt}-libexec/flua: ${_bt}-lib/libmd ${_bt}-lib/libucl ${_bt}-lib/libyaml
+.endif # BOOTSTRAPPING == 0
 .endif
 
 # r245440 mtree -N support added
@@ -2927,6 +2931,15 @@ bootstrap-tools: ${_bt}-links .PHONY
     ${_mkesdb} \
     ${_zic} \
     ${LOCAL_BSTOOL_DIRS}
+# We don't enforce any particular uniqueness of targets in the above list; it
+# may be the case that different bootstrap tools may have shared dependencies
+# at different BOOTSTRAPPING points, so we don't object to them using their own
+# conditionals and duplicating them into their ${_foo} variable to ease future
+# maintenance if we purge some entries.  These target names are purposefully
+# unique and this is the only place that should be generating commands for them,
+# but the target may have been defined earlier to express dependencies -- thus,
+# we specifically want commands() here.
+.if !commands(${_bt}-${_tool})
 ${_bt}-${_tool}: ${_bt}-links .PHONY .MAKE
 	${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \
 		cd ${.CURDIR}/${_tool}; \
@@ -2936,8 +2949,8 @@ ${_bt}-${_tool}: ${_bt}-links .PHONY .MAKE
 		fi; \
 		${MAKE} DIRPRFX=${_tool}/ all; \
 		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${WORLDTMP}/legacy install
-
 bootstrap-tools: ${_bt}-${_tool}
+.endif
 .endfor
 .if target(${_bt}-lib/libmd)
 # If we are bootstrapping libmd (e.g. when building on macOS/Linux) add the
diff --git a/contrib/libucl/lua/lua_ucl.c b/contrib/libucl/lua/lua_ucl.c
index d6be69e42a71..1b3f9dfd111c 100644
--- a/contrib/libucl/lua/lua_ucl.c
+++ b/contrib/libucl/lua/lua_ucl.c
@@ -30,6 +30,8 @@
 #include "lua_ucl.h"
 #include <strings.h>
 
+#include "bootstrap.h"
+
 /***
  * @module ucl
  * This lua module allows to parse objects from strings and to store data into
@@ -1571,3 +1573,5 @@ ucl_object_toclosure (const ucl_object_t *obj)
 
 	return (struct ucl_lua_funcdata*)obj->value.ud;
 }
+
+FLUA_MODULE(ucl);
diff --git a/contrib/lyaml/ext/yaml/yaml.c b/contrib/lyaml/ext/yaml/yaml.c
index 54478610134f..6a5ddc605e0f 100644
--- a/contrib/lyaml/ext/yaml/yaml.c
+++ b/contrib/lyaml/ext/yaml/yaml.c
@@ -35,6 +35,8 @@
 
 #include "lyaml.h"
 
+#include "bootstrap.h"
+
 #define MYNAME		"yaml"
 #define MYVERSION	MYNAME " library for " LUA_VERSION " / " VERSION
 
@@ -64,3 +66,5 @@ luaopen_yaml (lua_State *L)
 
    return 1;
 }
+
+FLUA_MODULE(yaml);
diff --git a/libexec/flua/Makefile b/libexec/flua/Makefile
index 0b870817331c..02e177b12f3d 100644
--- a/libexec/flua/Makefile
+++ b/libexec/flua/Makefile
@@ -2,11 +2,41 @@
 
 PACKAGE=	flua
 
-SUBDIR+=	libfreebsd
-SUBDIR+=	libhash
-SUBDIR+=	libjail
-SUBDIR+=	libucl
-SUBDIR+=	liblyaml
+# New flua modules should be added here rather than to SUBDIR so that we can do
+# the right thing for both bootstrap flua and target flua.  The former does not
+# do any shared libs, so we just build them all straight into flua itself rather
+# than mucking about with the infrastructure to make them linkable -- thus, why
+# these are all structured to have a Makefile that describes what we want
+# *installed*, and a Makefile.inc that describes what we need to *build*.
+FLUA_MODULES+=	libhash
+.ifndef BOOTSTRAPPING
+# Bootstrap flua can't usefully do anything with libjail anyways, because it
+# can't assume it's being run on a system that even supports jails.
+FLUA_MODULES+=	libjail
+.endif
+FLUA_MODULES+=	libucl
+FLUA_MODULES+=	liblyaml
+
+.ifdef BOOTSTRAPPING
+# libfreebsd is generally omitted from the bootstrap flua because its
+# functionality largely assumes a FreeBSD kernel/system headers, so it doesn't
+# really offer functionality that we can use in bootstrap.
+CFLAGS+=	-I${.CURDIR} -DBOOTSTRAPPING
+
+SHAREDIR=	${WORLDTMP}/legacy/usr/share/flua
+FLUA_PATH=	${SHAREDIR}/?.lua;${SHAREDIR}/?/init.lua
+CFLAGS+=	-DBOOTSTRAP_FLUA_PATH=\"${FLUA_PATH:Q}\"
+
+.for mod in ${FLUA_MODULES}
+.include "${mod}/Makefile.inc"
+.endfor
+
+.else
+
+FLUA_MODULES+=	libfreebsd
+SUBDIR+=	${FLUA_MODULES}
+
+.endif
 
 LUASRC?=	${SRCTOP}/contrib/lua/src
 .PATH: ${LUASRC}
@@ -16,7 +46,7 @@ WARNS?=	3
 
 CWARNFLAGS.gcc+=	-Wno-format-nonliteral
 
-LIBADD=	lua
+LIBADD+=	lua
 
 # Entry point
 SRCS+=	lua.c
diff --git a/libexec/flua/Makefile.inc b/libexec/flua/Makefile.inc
index 0ccb1a62f4cb..5e214c76921b 100644
--- a/libexec/flua/Makefile.inc
+++ b/libexec/flua/Makefile.inc
@@ -4,4 +4,9 @@ SHLIBDIR?=	${LIBDIR}/flua
 
 CFLAGS+=	\
 		-I${SRCTOP}/contrib/lua/src \
-		-I${SRCTOP}/lib/liblua
+		-I${SRCTOP}/lib/liblua \
+		-I${SRCTOP}/libexec/flua
+
+.ifdef BOOTSTRAPPING
+CFLAGS+=	-DBOOTSTRAPPING
+.endif
diff --git a/libexec/flua/bootstrap.h b/libexec/flua/bootstrap.h
new file mode 100644
index 000000000000..caf00518c1e0
--- /dev/null
+++ b/libexec/flua/bootstrap.h
@@ -0,0 +1,32 @@
+/*-
+ * Copyright (c) 2025 Kyle Evans <kevans@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#ifndef FLUA_BOOTSTRAP_H
+#define	FLUA_BOOTSTRAP_H
+
+#ifdef BOOTSTRAPPING
+#include <sys/linker_set.h>
+
+#include <lauxlib.h>
+
+#define	FLUA_MODULE_SETNAME	flua_modules
+
+SET_DECLARE(FLUA_MODULE_SETNAME, const luaL_Reg);
+#define	FLUA_MODULE_DEF(ident, modname, openfn)			\
+	static const luaL_Reg ident = {	modname, openfn };	\
+	DATA_SET(FLUA_MODULE_SETNAME, ident)
+
+#define	FLUA_MODULE_NAMED(mod, name)	\
+	FLUA_MODULE_DEF(module_ ## mod, name, luaopen_ ## mod)
+#define	FLUA_MODULE(mod)		\
+	FLUA_MODULE_DEF(module_ ## mod, #mod, luaopen_ ## mod)
+#else	/* !BOOTSTRAPPING */
+#define	FLUA_MODULE_DEF(ident, modname, openfn)
+#define	FLUA_MODULE_NAMED(mod, name)
+#define	FLUA_MODULE(modname)
+#endif	/* BOOTSTRAPPING */
+
+#endif	/* FLUA_BOOTSTRAP_H */
diff --git a/libexec/flua/libfreebsd/kenv/Makefile b/libexec/flua/libfreebsd/kenv/Makefile
index 1726c892c515..a1b388bb3612 100644
--- a/libexec/flua/libfreebsd/kenv/Makefile
+++ b/libexec/flua/libfreebsd/kenv/Makefile
@@ -1,5 +1,5 @@
 SHLIB_NAME=	kenv.so
-SRCS+=		kenv.c
 MAN=		freebsd.kenv.3lua
 
+.include "Makefile.inc"
 .include <bsd.lib.mk>
diff --git a/libexec/flua/libfreebsd/kenv/Makefile.inc b/libexec/flua/libfreebsd/kenv/Makefile.inc
new file mode 100644
index 000000000000..05819c5280d9
--- /dev/null
+++ b/libexec/flua/libfreebsd/kenv/Makefile.inc
@@ -0,0 +1,2 @@
+.PATH:		${.PARSEDIR}
+SRCS+=		kenv.c
diff --git a/libexec/flua/libfreebsd/kenv/kenv.c b/libexec/flua/libfreebsd/kenv/kenv.c
index 954baa00facb..56b24c72904a 100644
--- a/libexec/flua/libfreebsd/kenv/kenv.c
+++ b/libexec/flua/libfreebsd/kenv/kenv.c
@@ -14,6 +14,8 @@
 #include <lualib.h>
 #include <lauxlib.h>
 
+#include "bootstrap.h"
+
 int luaopen_freebsd_kenv(lua_State *L);
 
 static int
@@ -94,3 +96,5 @@ luaopen_freebsd_kenv(lua_State *L)
 
 	return (1);
 }
+
+FLUA_MODULE_NAMED(freebsd_kenv, "freebsd.kenv");
diff --git a/libexec/flua/libfreebsd/sys/linker/Makefile b/libexec/flua/libfreebsd/sys/linker/Makefile
index 1adf547b503c..f1f65ad5f6c1 100644
--- a/libexec/flua/libfreebsd/sys/linker/Makefile
+++ b/libexec/flua/libfreebsd/sys/linker/Makefile
@@ -1,7 +1,6 @@
 SHLIB_NAME=	linker.so
 
-SRCS+=		linker.c
-
 MAN=	freebsd.sys.linker.3lua
 
+.include "Makefile.inc"
 .include <bsd.lib.mk>
diff --git a/libexec/flua/libfreebsd/sys/linker/Makefile.inc b/libexec/flua/libfreebsd/sys/linker/Makefile.inc
new file mode 100644
index 000000000000..da65c0070170
--- /dev/null
+++ b/libexec/flua/libfreebsd/sys/linker/Makefile.inc
@@ -0,0 +1,2 @@
+.PATH:		${.PARSEDIR}
+SRCS+=		linker.c
diff --git a/libexec/flua/libfreebsd/sys/linker/linker.c b/libexec/flua/libfreebsd/sys/linker/linker.c
index 87eccfb651f0..c78fbb2b39d2 100644
--- a/libexec/flua/libfreebsd/sys/linker/linker.c
+++ b/libexec/flua/libfreebsd/sys/linker/linker.c
@@ -15,6 +15,8 @@
 #include <lualib.h>
 #include <lauxlib.h>
 
+#include "bootstrap.h"
+
 int luaopen_freebsd_sys_linker(lua_State *L);
 
 static int
@@ -80,3 +82,5 @@ luaopen_freebsd_sys_linker(lua_State *L)
 
 	return (1);
 }
+
+FLUA_MODULE_NAMED(freebsd_sys_linker, "freebsd.sys.linker");
diff --git a/libexec/flua/libhash/Makefile b/libexec/flua/libhash/Makefile
index b7c8d7ee9948..9cbd6f15acae 100644
--- a/libexec/flua/libhash/Makefile
+++ b/libexec/flua/libhash/Makefile
@@ -1,9 +1,6 @@
 SHLIB_NAME=	hash.so
 
-SRCS+=		lhash.c
-
-LIBADD+=	md
-
 MAN=	hash.3lua
 
+.include "Makefile.inc"
 .include <bsd.lib.mk>
diff --git a/libexec/flua/libhash/Makefile.inc b/libexec/flua/libhash/Makefile.inc
new file mode 100644
index 000000000000..d112dfe7df33
--- /dev/null
+++ b/libexec/flua/libhash/Makefile.inc
@@ -0,0 +1,3 @@
+.PATH:		${.PARSEDIR}
+SRCS+=		lhash.c
+LIBADD+=	md
diff --git a/libexec/flua/libhash/lhash.c b/libexec/flua/libhash/lhash.c
index 4587961fe8a0..7127ddc1d530 100644
--- a/libexec/flua/libhash/lhash.c
+++ b/libexec/flua/libhash/lhash.c
@@ -11,6 +11,8 @@
 #include <sha256.h>
 #include <string.h>
 
+#include "bootstrap.h"
+
 #define SHA256_META "SHA256 meta table"
 #define SHA256_DIGEST_LEN 32
 
@@ -175,3 +177,5 @@ luaopen_hash(lua_State *L)
 
 	return 1;
 }
+
+FLUA_MODULE(hash);
diff --git a/libexec/flua/libjail/Makefile b/libexec/flua/libjail/Makefile
index 20cd9f5f1429..b9c8bdc39095 100644
--- a/libexec/flua/libjail/Makefile
+++ b/libexec/flua/libjail/Makefile
@@ -1,9 +1,6 @@
 SHLIB_NAME=	jail.so
 
-SRCS+=		lua_jail.c
-
-LIBADD+=	jail
-
 MAN=	jail.3lua
 
+.include "Makefile.inc"
 .include <bsd.lib.mk>
diff --git a/libexec/flua/libjail/Makefile.inc b/libexec/flua/libjail/Makefile.inc
new file mode 100644
index 000000000000..a896bf38c65b
--- /dev/null
+++ b/libexec/flua/libjail/Makefile.inc
@@ -0,0 +1,3 @@
+.PATH:		${.PARSEDIR}
+SRCS+=		lua_jail.c
+LIBADD+=	jail
diff --git a/libexec/flua/libjail/lua_jail.c b/libexec/flua/libjail/lua_jail.c
index 9632db795775..8c3ec6c1d500 100644
--- a/libexec/flua/libjail/lua_jail.c
+++ b/libexec/flua/libjail/lua_jail.c
@@ -38,6 +38,8 @@
 #include <lauxlib.h>
 #include <lualib.h>
 
+#include "bootstrap.h"
+
 #define	JAIL_METATABLE "jail iterator metatable"
 
 /*
@@ -716,3 +718,5 @@ luaopen_jail(lua_State *L)
 
 	return (1);
 }
+
+FLUA_MODULE(jail);
diff --git a/libexec/flua/liblyaml/Makefile b/libexec/flua/liblyaml/Makefile
index e7a89d09bb9e..8d1432acd325 100644
--- a/libexec/flua/liblyaml/Makefile
+++ b/libexec/flua/liblyaml/Makefile
@@ -1,22 +1,4 @@
 SHLIB_NAME=	yaml.so
 
-WARNS=	1
-LYAMLSRC?=	${SRCTOP}/contrib/lyaml
-.PATH:		${LYAMLSRC}/ext/yaml ${LYAMLSRC}/lib/lyaml
-SRCS=		emitter.c \
-		parser.c \
-		scanner.c \
-		yaml.c
-CFLAGS+=	\
-		-I${LYAMLSRC}/ext/yaml \
-		-I${SRCTOP}/contrib/libyaml/include \
-		-DVERSION=\"6.2.8\"
-LIBADD+=	yaml
-
-FILES=		explicit.lua \
-		functional.lua \
-		implicit.lua \
-		init.lua
-FILESDIR=	${SHAREDIR}/flua/lyaml
-
+.include "Makefile.inc"
 .include <bsd.lib.mk>
diff --git a/libexec/flua/liblyaml/Makefile.inc b/libexec/flua/liblyaml/Makefile.inc
new file mode 100644
index 000000000000..caa1f37b57eb
--- /dev/null
+++ b/libexec/flua/liblyaml/Makefile.inc
@@ -0,0 +1,20 @@
+WARNS=	1
+
+LYAMLSRC?=	${SRCTOP}/contrib/lyaml
+.PATH:		${LYAMLSRC}/ext/yaml ${LYAMLSRC}/lib/lyaml
+SRCS+=		emitter.c \
+		parser.c \
+		scanner.c \
+		yaml.c
+CFLAGS+=	\
+		-I${LYAMLSRC}/ext/yaml \
+		-I${SRCTOP}/contrib/libyaml/include \
+		-DVERSION=\"6.2.8\"
+LIBADD+=	yaml
+
+FILESGROUPS+=	YAML
+YAML=		explicit.lua \
+		functional.lua \
+		implicit.lua \
+		init.lua
+YAMLDIR=	${SHAREDIR}/flua/lyaml
diff --git a/libexec/flua/libucl/Makefile b/libexec/flua/libucl/Makefile
index a88c8bda6bfc..32d76d1ea1ad 100644
--- a/libexec/flua/libucl/Makefile
+++ b/libexec/flua/libucl/Makefile
@@ -1,14 +1,4 @@
 SHLIB_NAME=	ucl.so
 
-WARNS=		2
-
-UCLSRC?= 	${SRCTOP}/contrib/libucl
-.PATH: ${UCLSRC}/lua
-SRCS+=		lua_ucl.c
-CFLAGS+=	\
-		-I${UCLSRC}/include \
-		-I${UCLSRC}/src \
-		-I${UCLSRC}/uthash
-LIBADD+=	ucl
-
+.include "Makefile.inc"
 .include <bsd.lib.mk>
diff --git a/libexec/flua/libucl/Makefile.inc b/libexec/flua/libucl/Makefile.inc
new file mode 100644
index 000000000000..70fb0f265635
--- /dev/null
+++ b/libexec/flua/libucl/Makefile.inc
@@ -0,0 +1,12 @@
+.if ${WARNS:U6} > 2
+WARNS=		2
+.endif
+
+UCLSRC?=	${SRCTOP}/contrib/libucl
+.PATH: ${UCLSRC}/lua
+SRCS+=		lua_ucl.c
+CFLAGS+=	\
+		-I${UCLSRC}/include \
+		-I${UCLSRC}/src \
+		-I${UCLSRC}/uthash
+LIBADD+=	ucl
diff --git a/libexec/flua/linit_flua.c b/libexec/flua/linit_flua.c
index b466b7872158..e5e38353ec9b 100644
--- a/libexec/flua/linit_flua.c
+++ b/libexec/flua/linit_flua.c
@@ -26,8 +26,8 @@
 
 #include "lprefix.h"
 
-
 #include <stddef.h>
+#include <stdlib.h>
 
 #include "lua.h"
 
@@ -37,6 +37,8 @@
 #include "lposix.h"
 #include "lfbsd.h"
 
+#include "bootstrap.h"
+
 /*
 ** these libs are loaded by lua.c and are readily available to any Lua
 ** program
@@ -62,6 +64,28 @@ static const luaL_Reg loadedlibs[] = {
   {NULL, NULL}
 };
 
+#ifdef BOOTSTRAPPING
+static void __attribute__((constructor)) flua_init_env(void) {
+  /*
+   * This happens in the middle of luaopen_package().  We could move it into
+   * flua_setup_mods(), but it seems better to avoid its timing being so
+   * important that it would break some of our bootstrap modules if someone
+   * were to reorder things.
+   */
+  if (getenv("LUA_PATH") == NULL)
+    setenv("LUA_PATH", BOOTSTRAP_FLUA_PATH, 1);
+}
+
+static void flua_setup_mods (lua_State *L) {
+  const luaL_Reg **flib;
+
+  SET_FOREACH(flib, FLUA_MODULE_SETNAME) {
+    luaL_requiref(L, (*flib)->name, (*flib)->func, 1);
+    lua_pop(L, 1);  /* remove lib */
+  }
+};
+#endif
+
 LUALIB_API void luaL_openlibs (lua_State *L) {
   const luaL_Reg *lib;
   /* "require" functions from 'loadedlibs' and set results to global table */
@@ -69,4 +93,7 @@ LUALIB_API void luaL_openlibs (lua_State *L) {
     luaL_requiref(L, lib->name, lib->func, 1);
     lua_pop(L, 1);  /* remove lib */
   }
+#ifdef BOOTSTRAPPING
+  flua_setup_mods(L);
+#endif
 }
diff --git a/tools/build/Makefile b/tools/build/Makefile
index 973b3a12d98f..fed4f06c290c 100644
--- a/tools/build/Makefile
+++ b/tools/build/Makefile
@@ -507,6 +507,7 @@ INSTALLDIR_LIST= \
 	usr/include/casper \
 	usr/include/openssl \
 	usr/include/private/ucl \
+	usr/include/private/yaml \
 	usr/include/private/zstd \
 	usr/lib \
 	usr/libdata/pkgconfig \