Date: Sat, 20 Jan 2024 15:31:23 -0700 From: Warner Losh <imp@bsdimp.com> To: Aleksandr Fedorov <wigneddoom@yandex.ru> Cc: Alan Somers <asomers@freebsd.org>, FreeBSD Hackers <freebsd-hackers@freebsd.org>, Scott Long <scottl@freebsd.org>, "meka@tilda.center" <meka@tilda.center> Subject: Re: The Case for Rust (in the base system) Message-ID: <CANCZdfpqWgvV_RCvVO_pvTrmajQFspW%2BQ9TM_Ok3JrXZAfeAfA@mail.gmail.com> In-Reply-To: <1673801705774097@mail.yandex.ru> References: <CAOtMX2hAUiWdGPtpaCJLPZB%2Bj2yzNw5DSjUmkwTi%2B%2BmyemehCA@mail.gmail.com> <1673801705774097@mail.yandex.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
--000000000000a39865060f682804 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Jan 20, 2024 at 11:45=E2=80=AFAM Aleksandr Fedorov <wigneddoom@yand= ex.ru> wrote: > What about external dependencies? > > https://github.com/Axcient/freebsd-nfs-exporter/blob/master/Cargo.toml#L1= 9 > https://github.com/asomers/gstat-rs/blob/master/gstat/src/main.rs#L20 > > Is there any plan for which crates we should take into the base system? > > We have had C++ in base for many years, but I don=E2=80=99t see any good = libraries > for CLI, logging, JSON, etc. > > > https://doc.rust-lang.org/rustc/platform-support.html#tier-1-with-host-to= ols > > Where is the support for Freebsd as a primary platform? ARM, RISC-V, > Power? Should we rewrite devd? > > I think we need to start by providing official repositories (e.g > git.FreeBSD.org/rust.git or git.FreeBSD.org/go.git) > for different languages that include stable bindings to the system API: > - sysctl > - libgeom > - libifconfig > - netgraph > - jail > - etc. > > So that it=E2=80=99s not just some anonymous on crates.io that represents= these > bindings, but our community. > Officially, with support for a stable ABI for releases, security patches, > etc. > > After this, it will be possible to think about which components to includ= e > in the base system. > > I would be glad to see a more modern language than C in the database, but > I=E2=80=99m afraid that it will be like with C++, > that we will get a couple of daemons and utilities and that=E2=80=99s all= . > These are all good questions that need good answers, though necessarily to get started. But the other question that occured to me after my last posting was "What about build integration?" How much of the rust automation do we take in vs how much do we drive from a future bsd.rust.mk. I can sketch out bsd.rust.mk (to pick an arbitrary name, we'd likely need one for what we traditionally think of as libraries (which may or may not map 1:1 onto crates: we could have c callable libraries written in rust in the future, for example) and one for binaries. Initially, though, if we go with the 'make rust tests possible' then we'd likely need the appropriate packages installed for whatever dependencies we'd have in the tests. This would give us a taste for what we'd need to do for base, I'd think. Once we had that notion, I can easily see there needing to be some sort of rust bindings for ATF/kyua as one of the first libraries / crates that would test that aspect of the build system. That all would be up to the people writing the tests in rust, I'd imagine. While I could jot out the basics of this integration (so one could just add the rust tools to a subdir or subdirs, include the bsd.rust.mk or whatever and then it would build if rust is enabled, and would emit a warning it was skipped because rust was disabled). We'd find out if this is workable or not and iterate from there. But that would also require active participation from the rust advocates to make it a reality: I can put together the build infrastructure for the disabled case, but likely can't on my own do the rust enabled case. I'd be happy to work with someone to do that, but I'm not going to be able to do that myself: my need for rust is slight, my knowledge of rust is weak, etc. Working with someone (or ideally several someones), though it could become reality. So please contact me if you'd like to work on this. Warner > 20.01.2024, 19:51, "Alan Somers" <asomers@freebsd.org>: > > In a recent thread on src-committers, we discussed the costs and > benefits of including Rust code in the FreeBSD base system. To > summarize, the cost is that it would double our build times. imp > suggested adding an additional step after buildworld for stuff that > requires an external toolchain. That would ease the build time pain. > The benefit is that some tools would become easier to write, or even > become possible. Here is a list of actual and potential Rust projects > that could benefit from being in-tree. If anybody else has items to > add, I suggest moving this into the project wiki: > > Stuff that could only be written in Rust if it were in base > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > * ctl-exporter (I started this, but discovered that the CTL stats API is > unstable, so it can't live in ports. Instead, I had to do it in C). > > https://github.com/freebsd/freebsd-src/commit/1a7f22d9c211f504f6c48a86401= 469181a67ec34 > > * fusefs tests. Absolutely impossible to do in C. I considered Rust, but > went > with C++ so they could live in base. They are too closely coupled to > fusefs(5) to live out-of-tree. > https://github.com/freebsd/freebsd-src/tree/main/tests/sys/fs/fusefs > > * devd. Currently C++, but imp suggested a rewrite. > https://github.com/freebsd/freebsd-src/tree/main/sbin/devd > > * zfsd. Currently C++, but I've long pondered a rewrite. Using Rust would > make it more testable. > https://github.com/freebsd/freebsd-src/tree/main/cddl/usr.sbin/zfsd > > * nscd. Currently C, but confusing and with no test coverage. I've > contemplated a rewrite myself, but I don't want to do it in C. > https://github.com/freebsd/freebsd-src/tree/main/usr.sbin/nscd > > * The userland portion of the 802.11ac and Lightning stacks. scottl > suggested > that these were good candidates for Rust. > > * freebsd-kpi-r14-0 . https://crates.io/crates/freebsd-kpi-r14-0 > > Stuff that can live in ports, but would be nicer in base > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D > > * gstat-rs https://crates.io/crates/gstat > > * geom-exporter (I've started this, but haven't published it) > > * nfs-exporter https://crates.io/crates/freebsd-nfs-exporter > > * virtiofsd-rs . Nobody has yet tried to port it to FreeBSD. But if the > connection to bhyve(8) is too intimate, it might be hard to do in ports= . > https://gitlab.com/virtio-fs/virtiofsd > > * jail-exporter https://crates.io/crates/jail_exporter > > * Various jail managers have been attempted in Rust. I think these are > fine in > ports, but others like Goran Mekic have opined that they should be move= d > to > base instead. > > * musikid's pjdfstest rewrite. I think it would be great to start using > this > to test the base system's file systems. If the tests themselves lived i= n > base, they would be easier to sync with file system development. > https://github.com/musikid/pjdfstest > > * pf-rs. I suspect that the API isn't very stable. > https://crates.io/crates/pf-rs > > * benchpmc. The pmc counter names changes between releases. > https://crates.io/crates/benchpmc > > FreeBSD-related applications that are just fine in ports > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D > > * fsx-rs. Unlike pjdfstest, this only tests datapath APIs. Those are > usually > more stable than control path APIs, so I think there's little to be > gained by > moving this into base. https://crates.io/crates/fsx > > * ztop. It uses ZFS's kstats sysctl interface, which is pretty stable. > https://crates.io/crates/ztop > > * iocage-provision https://crates.io/crates/iocage-provision > > * rsblk https://crates.io/crates/rsblk > > * xfuse https://github.com/KhaledEmaraDev/xfuse > > Other FreeBSD-related libraries in Rust > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > Just see the list at https://crates.io/keywords/freebsd > > --000000000000a39865060f682804 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote">= <div dir=3D"ltr" class=3D"gmail_attr">On Sat, Jan 20, 2024 at 11:45=E2=80= =AFAM Aleksandr Fedorov <<a href=3D"mailto:wigneddoom@yandex.ru">wignedd= oom@yandex.ru</a>> wrote:<br></div><blockquote class=3D"gmail_quote" sty= le=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);paddi= ng-left:1ex"><div><div>What about external dependencies?<br><br><a href=3D"= https://github.com/Axcient/freebsd-nfs-exporter/blob/master/Cargo.toml#L19"= target=3D"_blank">https://github.com/Axcient/freebsd-nfs-exporter/blob/mas= ter/Cargo.toml#L19</a></div><div><div><a href=3D"https://github.com/asomers= /gstat-rs/blob/master/gstat/src/main.rs#L20" target=3D"_blank">https://gith= ub.com/asomers/gstat-rs/blob/master/gstat/src/main.rs#L20</a><br><br>Is the= re any plan for which crates we should take into the base system?</div><div= >=C2=A0</div><div><div>We have had C++ in base for many years, but I don=E2= =80=99t see any good libraries for CLI, logging, JSON, etc.</div></div><div= >=C2=A0</div><div><div><a href=3D"https://doc.rust-lang.org/rustc/platform-= support.html#tier-1-with-host-tools" target=3D"_blank">https://doc.rust-lan= g.org/rustc/platform-support.html#tier-1-with-host-tools</a></div></div><di= v>=C2=A0</div><div>Where is the support for Freebsd as a primary platform? = ARM, RISC-V, Power? Should we rewrite devd?</div><div>=C2=A0</div><div><div= ><div>I think we need to start by providing official repositories (e.g <a h= ref=3D"http://git.FreeBSD.org/rust.git" target=3D"_blank">git.FreeBSD.org/r= ust.git</a> or <a href=3D"http://git.FreeBSD.org/go.git" target=3D"_blank">= git.FreeBSD.org/go.git</a>)</div><div>for different languages that include = stable bindings to the system API:</div><div>- sysctl</div><div>- libgeom</= div><div>- libifconfig</div><div>- netgraph</div><div>- jail</div><div>- et= c.</div><div>=C2=A0</div><div>So that it=E2=80=99s not just some anonymous = on <a href=3D"http://crates.io" target=3D"_blank">crates.io</a> that repres= ents these bindings, but our community.</div><div>Officially, with support = for a stable ABI for releases, security patches, etc.</div><div>=C2=A0</div= ><div>After this, it will be possible to think about which components to in= clude in the base system.</div><div>=C2=A0</div><div><div>I would be glad t= o see a more modern language than C in the database, but I=E2=80=99m afraid= that it will be like with C++,</div><div>that we will get a couple of daem= ons and utilities and that=E2=80=99s all.</div></div></div></div></div></di= v></blockquote><div><br></div><div>These are all good questions that need g= ood answers, though necessarily to get started.</div><div><br></div><div>Bu= t the other question that occured to me after my last posting was "Wha= t about build integration?"</div><div>How much of the rust automation = do we take in vs how much do we drive from a future <a href=3D"http://bsd.r= ust.mk">bsd.rust.mk</a>.</div><div>I can sketch out <a href=3D"http://bsd.r= ust.mk">bsd.rust.mk</a> (to pick an arbitrary name, we'd likely need on= e for what we traditionally</div><div>think of as libraries (which may or m= ay not map 1:1 onto crates: we could have c callable libraries</div><div>wr= itten in rust in the future, for example) and one for binaries.=C2=A0 Initi= ally, though, if we go with the</div><div>'make rust tests possible'= ; then we'd likely need the appropriate packages installed for whatever= </div><div>dependencies we'd have in the tests. This would give us a ta= ste for what we'd need to do for</div><div>base, I'd think. Once we= had that notion, I can easily see there needing to be some sort of</div><d= iv>rust bindings for ATF/kyua as one of the first libraries / crates that w= ould test that aspect of</div><div>the build system. That all would be up t= o the people writing the tests in rust, I'd imagine.<br></div><div><br>= </div><div>While I could jot out the basics of this integration (so one cou= ld just add the rust</div><div>tools to a subdir or subdirs, include the <a= href=3D"http://bsd.rust.mk">bsd.rust.mk</a> or whatever and then it would = build</div><div>if rust is enabled, and would emit a warning it was skipped= because rust was disabled).</div><div>We'd find out if this is workabl= e or not and iterate from there. But that would also require</div><div>acti= ve participation from the rust advocates to make it a reality: I can put to= gether the</div><div>build infrastructure for the disabled case, but likely= can't on my own do the rust enabled</div><div>case. I'd be happy t= o work with someone to do that, but I'm not going to be able to do</div= ><div>that myself: my need for rust is slight, my knowledge of rust is weak= , etc. Working with</div><div>someone (or ideally several someones), though= it could become reality. So please contact</div><div>me if you'd like = to work on this.<br></div><div><br></div><div>Warner<br></div><div>=C2=A0</= div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bor= der-left:1px solid rgb(204,204,204);padding-left:1ex"><div>20.01.2024, 19:5= 1, "Alan Somers" <<a href=3D"mailto:asomers@freebsd.org" targe= t=3D"_blank">asomers@freebsd.org</a>>:</div><div><br>In a recent thread = on src-committers, we discussed the costs and<br>benefits of including Rust= code in the FreeBSD base system. To<br>summarize, the cost is that it woul= d double our build times. imp<br>suggested adding an additional step after = buildworld for stuff that<br>requires an external toolchain. That would eas= e the build time pain.<br>The benefit is that some tools would become easie= r to write, or even<br>become possible. Here is a list of actual and potent= ial Rust projects<br>that could benefit from being in-tree. If anybody else= has items to<br>add, I suggest moving this into the project wiki:<br><br>S= tuff that could only be written in Rust if it were in base<br>=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D<br><br>* ctl-exporter (I started this, but discovered that = the CTL stats API is<br>=C2=A0=C2=A0unstable, so it can't live in ports= . Instead, I had to do it in C).<br>=C2=A0=C2=A0<a href=3D"https://github.c= om/freebsd/freebsd-src/commit/1a7f22d9c211f504f6c48a86401469181a67ec34" tar= get=3D"_blank">https://github.com/freebsd/freebsd-src/commit/1a7f22d9c211f5= 04f6c48a86401469181a67ec34</a><br><br>* fusefs tests. Absolutely impossible= to do in C. I considered Rust, but went<br>=C2=A0=C2=A0with C++ so they co= uld live in base. They are too closely coupled to<br>=C2=A0=C2=A0fusefs(5) = to live out-of-tree.<br>=C2=A0=C2=A0<a href=3D"https://github.com/freebsd/f= reebsd-src/tree/main/tests/sys/fs/fusefs" target=3D"_blank">https://github.= com/freebsd/freebsd-src/tree/main/tests/sys/fs/fusefs</a><br><br>* devd. Cu= rrently C++, but imp suggested a rewrite.<br>=C2=A0=C2=A0<a href=3D"https:/= /github.com/freebsd/freebsd-src/tree/main/sbin/devd" target=3D"_blank">http= s://github.com/freebsd/freebsd-src/tree/main/sbin/devd</a><br><br>* zfsd. C= urrently C++, but I've long pondered a rewrite. Using Rust would<br>=C2= =A0=C2=A0make it more testable.<br>=C2=A0=C2=A0<a href=3D"https://github.co= m/freebsd/freebsd-src/tree/main/cddl/usr.sbin/zfsd" target=3D"_blank">https= ://github.com/freebsd/freebsd-src/tree/main/cddl/usr.sbin/zfsd</a><br><br>*= nscd. Currently C, but confusing and with no test coverage. I've<br>= =C2=A0=C2=A0contemplated a rewrite myself, but I don't want to do it in= C.<br>=C2=A0=C2=A0<a href=3D"https://github.com/freebsd/freebsd-src/tree/m= ain/usr.sbin/nscd" target=3D"_blank">https://github.com/freebsd/freebsd-src= /tree/main/usr.sbin/nscd</a><br><br>* The userland portion of the 802.11ac = and Lightning stacks. scottl suggested<br>=C2=A0=C2=A0that these were good = candidates for Rust.<br><br>* freebsd-kpi-r14-0 . <a href=3D"https://crates= .io/crates/freebsd-kpi-r14-0" target=3D"_blank">https://crates.io/crates/fr= eebsd-kpi-r14-0</a><br><br>Stuff that can live in ports, but would be nicer= in base<br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br><br>* gstat-rs <a href=3D"https://crates.= io/crates/gstat" target=3D"_blank">https://crates.io/crates/gstat</a><br><b= r>* geom-exporter (I've started this, but haven't published it)<br>= <br>* nfs-exporter <a href=3D"https://crates.io/crates/freebsd-nfs-exporter= " target=3D"_blank">https://crates.io/crates/freebsd-nfs-exporter</a><br><b= r>* virtiofsd-rs . Nobody has yet tried to port it to FreeBSD. But if the<b= r>=C2=A0=C2=A0connection to bhyve(8) is too intimate, it might be hard to d= o in ports.<br>=C2=A0=C2=A0<a href=3D"https://gitlab.com/virtio-fs/virtiofs= d" target=3D"_blank">https://gitlab.com/virtio-fs/virtiofsd</a><br><br>* ja= il-exporter <a href=3D"https://crates.io/crates/jail_exporter" target=3D"_b= lank">https://crates.io/crates/jail_exporter</a><br><br>* Various jail mana= gers have been attempted in Rust. I think these are fine in<br>=C2=A0=C2=A0= ports, but others like Goran Mekic have opined that they should be moved to= <br>=C2=A0=C2=A0base instead.<br><br>* musikid's pjdfstest rewrite. I t= hink it would be great to start using this<br>=C2=A0=C2=A0to test the base = system's file systems. If the tests themselves lived in<br>=C2=A0=C2=A0= base, they would be easier to sync with file system development.<br>=C2=A0= =C2=A0<a href=3D"https://github.com/musikid/pjdfstest" target=3D"_blank">ht= tps://github.com/musikid/pjdfstest</a><br><br>* pf-rs. I suspect that the A= PI isn't very stable.<br>=C2=A0=C2=A0<a href=3D"https://crates.io/crate= s/pf-rs" target=3D"_blank">https://crates.io/crates/pf-rs</a><br><br>* benc= hpmc. The pmc counter names changes between releases.<br>=C2=A0=C2=A0<a hre= f=3D"https://crates.io/crates/benchpmc" target=3D"_blank">https://crates.io= /crates/benchpmc</a><br><br>FreeBSD-related applications that are just fine= in ports<br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br><br>* fsx-rs. Unlike pjdfstest, thi= s only tests datapath APIs. Those are usually<br>=C2=A0=C2=A0more stable th= an control path APIs, so I think there's little to be gained by<br>=C2= =A0=C2=A0moving this into base. <a href=3D"https://crates.io/crates/fsx" ta= rget=3D"_blank">https://crates.io/crates/fsx</a><br><br>* ztop. It uses ZFS= 's kstats sysctl interface, which is pretty stable.<br>=C2=A0=C2=A0<a h= ref=3D"https://crates.io/crates/ztop" target=3D"_blank">https://crates.io/c= rates/ztop</a><br><br>* iocage-provision <a href=3D"https://crates.io/crate= s/iocage-provision" target=3D"_blank">https://crates.io/crates/iocage-provi= sion</a><br><br>* rsblk <a href=3D"https://crates.io/crates/rsblk" target= =3D"_blank">https://crates.io/crates/rsblk</a><br><br>* xfuse <a href=3D"ht= tps://github.com/KhaledEmaraDev/xfuse" target=3D"_blank">https://github.com= /KhaledEmaraDev/xfuse</a><br><br>Other FreeBSD-related libraries in Rust<br= >=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>Just see the list at <a hr= ef=3D"https://crates.io/keywords/freebsd" target=3D"_blank">https://crates.= io/keywords/freebsd</a><br>=C2=A0</div></blockquote></div></div> --000000000000a39865060f682804--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfpqWgvV_RCvVO_pvTrmajQFspW%2BQ9TM_Ok3JrXZAfeAfA>