From: Ezekiel Newren Date: Mon, 27 Oct 2025 20:35:59 GMT Subject: Re: [PATCH 3/3] rust: generate bindings via cbindgen Message-ID: In-Reply-To: On Fri, Oct 24, 2025 at 12:37 AM Patrick Steinhardt 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. > > Also I think that we should convert from using a Cargo crate to using > > a Cargo workspace, so that we can generate multiple header files (1 > > per crate) rather than a monolithic generated header. This is because > > cbindgen operates at the granularity of a crate. > > I'm basically still punting this into the future. There is no good > reason yet to have workspaces, so I'd rather introduce them once we have > a better way to sell them and demonstrate their immediate benefits. I'd like to avoid creating a gordian knot in Rust like how the existing C code is a gordian knot. Creating multiple crates will encourage better api design so that our code can be more modular and easier to maintain. The reason why I don't want to put this off is because the more we add to Rust the harder it'll be to refactor the code to use Cargo workspaces. Let's do it now while it's still really easy. As there is only 1 crate conceptually the code changes required to convert it to a workspace will be very minimal.