Re: [PATCH 3/3] rust: generate bindings via cbindgen
- From
brian m. carlson <sandals@crustytoothpaste.net>
- Date
- Oct 27, 2025, 21:14 UTC
- Message-ID
- <aP_gy-Rj8MI7zAWd@fruit.crustytoothpaste.net>
- In-Reply-To
- <CAH=ZcbBWuS6QVQT4LsxSP-X4GupZwr+NwzXNH2+qZGoufUWDrQ@mail.gmail.com>
On 2025-10-27 at 20:35:59, Ezekiel Newren wrote:
Show 22 quoted lines
> On Fri, Oct 24, 2025 at 12:37 AM Patrick Steinhardt <ps@pks.im> wrote: > > > cbindgen is a Rust crate and it should be specified in the Cargo.toml > > > under [build-dependencies] block. > > > > What is the benefit for us? The generated code is not a dependency of > > the Rust code, and neither do we use it via "build.rs". And if we use > > cbindgen via "Cargo.toml" we'd be forced to build it first, which slows > > down our CI jobs. > > > > Please let me know in case I miss any reasons to have it in our build > > dependencies instead. > > You're targeting a very old version of Rust (1.49). I'm not even sure > that cbindgen will work with a version that old, but if it does then > we should use it in build.rs to make sure we're not using any features > of cbindgen that aren't available until later versions. If we use > cbindgen that is packaged with the platform then we can't precisely > control which version of cbindgen is being used. This is a matter of > reproducibility. There may be platforms that can compile Rust, but > can't generate C header files via cbindgen because cbindgen hard codes > that a certain minimum Rust version is required in its own Cargo.toml > file.
Yes, I agree with this. Not all systems have cbindgen and it's not guaranteed that the system's cbindgen will work with the version of Rust that you want to target or that's being used to compile.
For instance, I'm using Debian unstable with a system cbindgen 0.27.0. This requires Rust 1.70 or newer. If I use rustup to test my code on Rust 1.49, then the code won't compile for me.
-- brian m. carlson (they/them) Toronto, Ontario, CA