Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 6 Sep 2024 08:48:59 -0600
From:      Warner Losh <imp@bsdimp.com>
To:        Kyle Evans <kevans@freebsd.org>
Cc:        Baptiste Daroussin <bapt@freebsd.org>, Mark Johnston <markj@freebsd.org>, freebsd-hackers@freebsd.org,  imp@freebsd.org
Subject:   Re: adding new flua libraries
Message-ID:  <CANCZdfrDkUm8j1LrdcH7rpBkTS-ottZ%2BpPZqQMU6b3y1KeJj2A@mail.gmail.com>
In-Reply-To: <2f3039bc-883c-4b11-ab20-d1873c6cc555@FreeBSD.org>
References:  <Zto2Cf0Rp3kIsuFH@nuc> <qwingl2edkh655hjlfxhssez4ntqrit6cw7xkzj57jnmfbgzv7@jbaucgbobapr> <2f3039bc-883c-4b11-ab20-d1873c6cc555@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
On Fri, Sep 6, 2024 at 8:45 AM Kyle Evans <kevans@freebsd.org> wrote:

> On 9/6/24 04:29, Baptiste Daroussin wrote:
> > On Thu 05 Sep 18:51, Mark Johnston wrote:
> >> FreeBSD ships a Lua 5.4 implementation, flua, in the base system.  It's
> >> intended for use by the base system, and so far has a few consumers, but
> >> not many so far.  (As an aside, flua's intended scope is not totally
> >> clear to me.  Is it only for use by the base system?  What compatibility
> >> guarantees does it provide, if any?)
> >>
> >> A few flua modules wrapping FreeBSD libraries (e.g., libjail) are
> >> available, but they don't provide enough to make flua useful as a
> >> general purpose programming tool.  It lacks interfaces for interacting
> >> with the system (e.g., libc/libsys/libutil/etc wrappers) as well as
> >> standard programming facilities (e.g., classes, higher-order functions,
> >> etc.).  Here I'm mostly interested in discussing the former.
> >>
> >> I think flua could be a very useful alternative to shell scripts and C
> >> code where performance is not critical.  It's very good at wrapping C
> >> interfaces and thus could be used to make FreeBSD features (jails,
> >> bhyve, ctl, pf, zfs, dtrace, ...) more accessible to developers who
> >> don't want to interact with C.
> >>
> >> It's a lot of work to build up a set of flua modules that provide enough
> >> functionality to be generally useful.  My feeling is that the easiest
> >> way to get there is to wrap C interfaces directly (to the extent that
> >> that's possible, but it's usually easy) and expose them in flua as a
> >> stable interface.  Libraries written in pure Lua (or other languages
> >> that interoperate well with Lua) could be built on top of that.
> >>
> >> I'm inclined to start by wrapping libc and libsys interfaces in a manner
> >> similar to luaposix.  There, the namespace is partitioned by C headers,
> >> so posix.unistd contains identifiers from unistd.h, posix.sys.stat
> >> contains identifiers from sys/stat.h, and so on.  In fact, flua already
> >> has a small subset of luaposix's functionality.  Wrapping C interfaces
> >> isn't much fun, but it's easy, and it saves us having to come up with
> >> names and interfaces (naming things is hard), and helps ensure that the
> >> glue code is relatively small and doesn't impose a large testing burden.
> >> Moreover, C interfaces don't change much and are subject to
> >> well-understood compatibility constraints, which should mean that Lua
> >> interfaces built on top of them are subject to the same constraints.
> >>
> >> Assuming there's general agreement on that approach, the question I'd
> >> really like to answer is, what should the namespace look like?  It would
> >> be useful to provide a posix module compatible with luaposix, but that
> >> obviously won't contain FreeBSD-specific functionality.
> >>
> >> I propose having a top-level "freebsd" namespace for all modules
> >> implemented in the base system, excluding posix and contrib libraries
> >> which already define a Lua interface (libucl is the one example I see so
> >> far; we could import sqlite bindings as well).  Then, if we follow
> >> luaposix's convention, we could have freebsd.sys.capsicum.* for
> >> Capsicum-related syscalls and constants, freebsd.sys.event.* for kevent
> >> wrappers, and so on.  The posix module could simply provide a subset of
> >> freebsd.*.
> >>
> >> Maybe it's better to separate C wrappers from native Lua modules though,
> >> so it could be better to have freebsd.c.sys.capsicum.*, etc., and
> >> provide higher-level interfaces for FreeBSD features under freebsd.pf,
> >> freebsd.zfs, freebsd.jail, etc..  I'm not really sure.
> >>
> >> In the interest of prompting discussion a bit, I posted some patches to
> >> add some example wrappers to flua:
> >> https://reviews.freebsd.org/D46553
> >> https://reviews.freebsd.org/D46554
> >> https://reviews.freebsd.org/D46556
> >>
> >> Does anyone have opinions on anything I've brought up above?  I'm pretty
> >> happy to write a lot of this glue code or find ways to automate it, as
> >> I've already done a fair bit of it, but it's hard to make progress
> >> without having some rigourous conventions for the flua namespace (again,
> >> naming things is hard).
> >
> > I like all of what I read and I am fully aligned.
> >
> > What I don't see here, is I think we should have dynamic modules libucl,
> fbsd &
> > friends are not dynamic and the reviews I see for the freebsd module
> reviews,
> > this is still bundled.
> >
>
> Right, this is an artifact of how flua's evolved that we need to move
> away from.  We didn't have module support at the beginning- that came
> later, but we didn't really move things out into modules.  We still
> can't move some things because of the bootstrap flua problem I mentioned
> elsewhere (doing so would block work to do `make sysent` type work as
> part of the build as it would break cross-builds), but at least
> libucl/fbsd would be fine.
>

Yea, if the sysent.lua code doesn't use modules, would we still have the
same
bootstrapping issues? Today, I don't think here's anything but vanilla lua
code
in there.

Warner


> > my proposal for unbundling, I need kldload for a project of mine, so I
> did:
> > https://reviews.freebsd.org/D46558
> >
> > Best regards,
> > Bapt
>
>

[-- Attachment #2 --]
<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Sep 6, 2024 at 8:45 AM Kyle Evans &lt;<a href="mailto:kevans@freebsd.org">kevans@freebsd.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 9/6/24 04:29, Baptiste Daroussin wrote:<br>
&gt; On Thu 05 Sep 18:51, Mark Johnston wrote:<br>
&gt;&gt; FreeBSD ships a Lua 5.4 implementation, flua, in the base system.  It&#39;s<br>
&gt;&gt; intended for use by the base system, and so far has a few consumers, but<br>
&gt;&gt; not many so far.  (As an aside, flua&#39;s intended scope is not totally<br>
&gt;&gt; clear to me.  Is it only for use by the base system?  What compatibility<br>
&gt;&gt; guarantees does it provide, if any?)<br>
&gt;&gt;<br>
&gt;&gt; A few flua modules wrapping FreeBSD libraries (e.g., libjail) are<br>
&gt;&gt; available, but they don&#39;t provide enough to make flua useful as a<br>
&gt;&gt; general purpose programming tool.  It lacks interfaces for interacting<br>
&gt;&gt; with the system (e.g., libc/libsys/libutil/etc wrappers) as well as<br>
&gt;&gt; standard programming facilities (e.g., classes, higher-order functions,<br>
&gt;&gt; etc.).  Here I&#39;m mostly interested in discussing the former.<br>
&gt;&gt;<br>
&gt;&gt; I think flua could be a very useful alternative to shell scripts and C<br>
&gt;&gt; code where performance is not critical.  It&#39;s very good at wrapping C<br>
&gt;&gt; interfaces and thus could be used to make FreeBSD features (jails,<br>
&gt;&gt; bhyve, ctl, pf, zfs, dtrace, ...) more accessible to developers who<br>
&gt;&gt; don&#39;t want to interact with C.<br>
&gt;&gt;<br>
&gt;&gt; It&#39;s a lot of work to build up a set of flua modules that provide enough<br>
&gt;&gt; functionality to be generally useful.  My feeling is that the easiest<br>
&gt;&gt; way to get there is to wrap C interfaces directly (to the extent that<br>
&gt;&gt; that&#39;s possible, but it&#39;s usually easy) and expose them in flua as a<br>
&gt;&gt; stable interface.  Libraries written in pure Lua (or other languages<br>
&gt;&gt; that interoperate well with Lua) could be built on top of that.<br>
&gt;&gt;<br>
&gt;&gt; I&#39;m inclined to start by wrapping libc and libsys interfaces in a manner<br>
&gt;&gt; similar to luaposix.  There, the namespace is partitioned by C headers,<br>
&gt;&gt; so posix.unistd contains identifiers from unistd.h, posix.sys.stat<br>
&gt;&gt; contains identifiers from sys/stat.h, and so on.  In fact, flua already<br>
&gt;&gt; has a small subset of luaposix&#39;s functionality.  Wrapping C interfaces<br>
&gt;&gt; isn&#39;t much fun, but it&#39;s easy, and it saves us having to come up with<br>
&gt;&gt; names and interfaces (naming things is hard), and helps ensure that the<br>
&gt;&gt; glue code is relatively small and doesn&#39;t impose a large testing burden.<br>
&gt;&gt; Moreover, C interfaces don&#39;t change much and are subject to<br>
&gt;&gt; well-understood compatibility constraints, which should mean that Lua<br>
&gt;&gt; interfaces built on top of them are subject to the same constraints.<br>
&gt;&gt;<br>
&gt;&gt; Assuming there&#39;s general agreement on that approach, the question I&#39;d<br>
&gt;&gt; really like to answer is, what should the namespace look like?  It would<br>
&gt;&gt; be useful to provide a posix module compatible with luaposix, but that<br>
&gt;&gt; obviously won&#39;t contain FreeBSD-specific functionality.<br>
&gt;&gt;<br>
&gt;&gt; I propose having a top-level &quot;freebsd&quot; namespace for all modules<br>
&gt;&gt; implemented in the base system, excluding posix and contrib libraries<br>
&gt;&gt; which already define a Lua interface (libucl is the one example I see so<br>
&gt;&gt; far; we could import sqlite bindings as well).  Then, if we follow<br>
&gt;&gt; luaposix&#39;s convention, we could have freebsd.sys.capsicum.* for<br>
&gt;&gt; Capsicum-related syscalls and constants, freebsd.sys.event.* for kevent<br>
&gt;&gt; wrappers, and so on.  The posix module could simply provide a subset of<br>
&gt;&gt; freebsd.*.<br>
&gt;&gt;<br>
&gt;&gt; Maybe it&#39;s better to separate C wrappers from native Lua modules though,<br>
&gt;&gt; so it could be better to have freebsd.c.sys.capsicum.*, etc., and<br>
&gt;&gt; provide higher-level interfaces for FreeBSD features under <a href="http://freebsd.pf" rel="noreferrer" target="_blank">freebsd.pf</a>,<br>
&gt;&gt; freebsd.zfs, freebsd.jail, etc..  I&#39;m not really sure.<br>
&gt;&gt;<br>
&gt;&gt; In the interest of prompting discussion a bit, I posted some patches to<br>
&gt;&gt; add some example wrappers to flua:<br>
&gt;&gt; <a href="https://reviews.freebsd.org/D46553" rel="noreferrer" target="_blank">https://reviews.freebsd.org/D46553</a><br>;
&gt;&gt; <a href="https://reviews.freebsd.org/D46554" rel="noreferrer" target="_blank">https://reviews.freebsd.org/D46554</a><br>;
&gt;&gt; <a href="https://reviews.freebsd.org/D46556" rel="noreferrer" target="_blank">https://reviews.freebsd.org/D46556</a><br>;
&gt;&gt;<br>
&gt;&gt; Does anyone have opinions on anything I&#39;ve brought up above?  I&#39;m pretty<br>
&gt;&gt; happy to write a lot of this glue code or find ways to automate it, as<br>
&gt;&gt; I&#39;ve already done a fair bit of it, but it&#39;s hard to make progress<br>
&gt;&gt; without having some rigourous conventions for the flua namespace (again,<br>
&gt;&gt; naming things is hard).<br>
&gt; <br>
&gt; I like all of what I read and I am fully aligned.<br>
&gt; <br>
&gt; What I don&#39;t see here, is I think we should have dynamic modules libucl, fbsd &amp;<br>
&gt; friends are not dynamic and the reviews I see for the freebsd module reviews,<br>
&gt; this is still bundled.<br>
&gt; <br>
<br>
Right, this is an artifact of how flua&#39;s evolved that we need to move <br>
away from.  We didn&#39;t have module support at the beginning- that came <br>
later, but we didn&#39;t really move things out into modules.  We still <br>
can&#39;t move some things because of the bootstrap flua problem I mentioned <br>
elsewhere (doing so would block work to do `make sysent` type work as <br>
part of the build as it would break cross-builds), but at least <br>
libucl/fbsd would be fine.<br></blockquote><div><br></div><div>Yea, if the sysent.lua code doesn&#39;t use modules, would we still have the same</div><div>bootstrapping issues? Today, I don&#39;t think here&#39;s anything but vanilla lua code</div><div>in there.</div><div><br></div><div>Warner</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
&gt; my proposal for unbundling, I need kldload for a project of mine, so I did:<br>
&gt; <a href="https://reviews.freebsd.org/D46558" rel="noreferrer" target="_blank">https://reviews.freebsd.org/D46558</a><br>;
&gt; <br>
&gt; Best regards,<br>
&gt; Bapt<br>
<br>
</blockquote></div></div>

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfrDkUm8j1LrdcH7rpBkTS-ottZ%2BpPZqQMU6b3y1KeJj2A>