bindgen-cli: depend on libclang-dev, recommend rustfmt and fix long description
TL;DR: bindgen
MUST depend on libclang1
, SHOULD recommend rustfmt
, and it'd better depend on libclang-dev
Since #1070241 has been the only open bug on my DDPO for a while, I thought I should give it a shot :-)
In bug #1070241 the reporter raises the issue that bindgen cannot work without clang. To show this, they report the following error message:
/usr/include/zconf.h: 254 fatal error 'stddef.h' not found
This error is triggered by the absence of /usr/lib/llvm-16/lib/clang/16/include/stddef.h
(not just any other stddef.h
, I checked this) on the system, which is provided by libclang-common-16-dev
(of course the llvm version is not important here).
Now, stddef.h
is not actually strictly needed for bindgen to function. I tested in a minbase unstable chroot that, for a minimal header.h
like
struct s {
int integer;
};
all bindgen needs is libclang1
. Without the latter, it throws out the following panic:
root@debian:~# bindgen header.h
thread 'main' panicked at /usr/share/cargo/registry/bindgen-0.66.1/lib.rs:604:31:
Unable to find libclang: "couldn't find any valid shared libraries matching: ['libclang.so', 'libclang-*.so', 'libclang.so.*', 'libclang-*.so.*'], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: [])"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
After installing libclang1
(with no recommends), on the other hand, the bindings are generated, but with a warning:
Failed to run rustfmt: cannot find binary path (non-fatal, continuing)
Thus bindgen MUST depend on libclang1
, and SHOULD at least recommend rustfmt
(without it the generated bindings look like a mess. They will work but they are unreadable).
As for stddef.h
, that's needed by libclang so that bindgen can generate bindings for some (not all) headers, namely those which expect stddef.h
to be available, like zlib's zconf.h
. For instance, again in a minbase unstable chroot,
root@debian:~# apt install --no-install-recommends bindgen libclang1 zlib1g-dev
root@debian:~# bindgen /usr/include/zconf.h
/usr/include/zconf.h:254:14: fatal error: 'stddef.h' file not found
panicked at main.rs:52:36:
Unable to generate bindings: ClangDiagnostic("/usr/include/zconf.h:254:14: fatal error: 'stddef.h' file not found\n")
which is the error reported in the bug. I'd argue that bindgen should not fail because of missing clang headers. This means libclang-common-$VERSION-dev
SHOULD be a dependency of bindgen as well.
Finally, to minimize the risk of other code requiring other libclang/libgcc/libstdc++ headers for bindings generation, I'd just make bindgen depend on the whole libclang-dev
, which also pulls in libclang1
, libclang-common-$VERSION-dev
, and the gcc/c++ headers. After all, bindgen's requirement page (https://rust-lang.github.io/rust-bindgen/requirements.html) would have us also install llvm-dev and clang itself (which may be overshoot in the absence of reports that those dependencies are actually needed), so only installing libclang-dev should not be too much.