From: Ezekiel Newren Date: Fri, 19 Sep 2025 20:34:56 GMT Subject: Re: [PATCH v2 14/18] build-helper: cbindgen, let crates generate a header file Message-ID: In-Reply-To: On Wed, Sep 17, 2025 at 3:09 AM Eric Sunshine wrote: > It would be nice to have a bit more explanation of what this patch is > doing and why. I presume that this is adding boilerplate functionality > but that there are no clients of this functionality yet. Is that > correct? I included cbindgen at Brian's request. Its job is to generate C header files based on Rust code. This eliminates errors of manually keeping definitions in sync between Rust and C. You are correct that nothing in my code uses cbindgen yet. I wanted people to see what would be required to make cbindgen exist in Git. I think I'll drop cbindgen for this series since varint is so trivial. I think it would be worthwhile to go over some Rust terminology: [rustc]: The rust compiler. [cargo]: Canonical build system + package manager. Even rustc uses cargo to build itself. [rustup]: Rust toolchain manager. This provides rustc and cargo + other stuff. [crate]: The unit of compilation. In C it's akin to a single library file or executable. It follows the structure of my_crate ├── Cargo.toml ├── build.rs └── src ├── do_that.rs ├── do_this.rs └── lib.rs Where src/lib.rs (the entry point) means it's a library crate and main.rs (the entry point) would mean it's an executable crate (though you can define both in the same crate). This means for each crate there will be lib.a and optionally interop/.h. So places like xdiff and reftable would be easy to fit into the concept of a crate. The rest of Git would take some doing to organize into crates. > > diff --git a/rust/cbindgen-template.toml b/rust/cbindgen-template.toml > > @@ -0,0 +1,16 @@ > > +## compat/posix.h includes stdbool.h where git-compat-util.h does not > > +## this is mandatory for correct bool C <-> Rust interop. Though the > > +## 'includes' (and all other variables in this file) can be > > +## overridden in build.rs. > > There seems to be some missing punctuation in the above comment, and > the final sentence seems to be incomplete, both of which make it > difficult to understand what is being said. I'll fix that wording. > > +sys_includes = ["compat/posix.h"] > > + > > +autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" > > + > > +language = "C" > > +no_includes = true > > +usize_is_size_t = true > > +style = "tag" > > +tab_width = 4 > > It's a minor thing and probably not super important but I'm wondering > if it would be a good idea to follow project guidelines and make the > TAB width 8 rather than 4. Doing so might be appreciated by people > reading the generated header files. I'm fine with changing this value. I was aware that Git uses a tab width of 8, but the problem is that Git uses tab characters instead of spaces and as far as I can tell cbindgen doesn't support using a tab character for indentation. So tab_width in cbindgen-template.toml means X space characters per indent.