rust-lang / rust-bindgen

Automatically generates Rust FFI bindings to C (and some C++) libraries.
https://rust-lang.github.io/rust-bindgen/
BSD 3-Clause "New" or "Revised" License
4.23k stars 679 forks source link

Publishing self-contained static executable (with bundled libclang.a) #2767

Open ianks opened 4 months ago

ianks commented 4 months ago

One of the biggest pain points about using bindgen is installing libclang. It's a massive dependency to manage, and adds pain to the development and deployment of Rust apps. It would be nice if you could just run bindgen-cli-installer.sh and be done with it, whether you're compiling in CI or on a laptop.

The downside is that the generated executable is pretty massive (85M on arm64-darwin, compared to 5.4M now).

There's already support for statically linking libclang.a, so I think this is mostly a matter of automating the release process. I have a hacky proof-of-concept here for reference.

I'd be happy to work on making this happen if others would find it useful.

HadrienG2 commented 3 months ago

Another possible (complementary) strategy is to use the pre-built binaries provided by LLVM contributors for various hardware + OS combinations.

They contain way more than we need, but extracting the (self-contained) libclang.so from them is not terribly difficult. So it should be possible to have a scheduled CI job that periodically scans the LLVM releases, extracts the libclang, and attaches it to the bindgen github release.

Of course, given that people are easily scared by binaries for reasons I have never fully understood (unless you claim that you or anyone else actually understands everything that the LLVM source code does, there is no meaningful security difference between building LLVM from source and using a pre-built binary from my perspective), the use of binaries should be optional.