[Libguestfs] [libnbd PATCH v3 01/10] rust: create basic Rust bindings

Eric Blake eblake at redhat.com
Tue Jul 25 19:58:29 UTC 2023


On Tue, Jul 25, 2023 at 08:42:05PM +0100, Richard W.M. Jones wrote:
> 
> Just a note that this patch (I think?) causes this if you don't
> have rustfmt installed:
> 
> /bin/sh: line 1: rustfmt: command not found
> Fatal error: exception Failure("Rustfmt failed with exit code 127")
> Raised at Stdlib.failwith in file "stdlib.ml", line 29, characters 17-33
> Called from Utils.output_to in file "utils.ml", line 432, characters 21-76
> Called from Generator in file "generator.ml", line 65, characters 2-88

I'm also trying to see if I can cherry-pick the portion of this patch
that applies an (optional) formatter in the build process for the sake
of golang/.  At least on Fedora, 'go' and 'gofmt' are bundled in the
same package, so if you can compile Go code, you should also be able
to run it through gofmt to get canonical style.

I'm about to post patches that improve existing Go style (my unit
tests were horrendous at TAB vs. space, and go likes function(calls)
without a space, unlike our C style).  For the unit tests, it's easy
to fix.  But for golang/bindings.go, produced by generator/GoLang.ml,
it's tougher: either the generator can already spit out correct
formatting (not always trivial), or the post-process pass by gofmt can
touch up the sources.  Whoever builds an official release tarball will
NEED to have the right formatter tools, but for everyone else, they
should be optional (if you download the tarball, you are not required
to have OCaml installed because the files are build, just as you are
not required to have go or gofmt installed if you only care about the
C and Python bindings).  So handling this gracefully is an interesting
task.

> 
> I don't think rustfmt should be a mandatory dependency of libnbd, so
> we should probably just treat it as a no-op if rustfmt wasn't found.

Indeed - if we CAN format with the canonical program, do so; but if we
can't, yet the result still compiles despite non-canonical formatting,
that should be good enough.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org


More information about the Libguestfs mailing list