git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 5/5] rust: generate bindings via cbindgen

From
Toon Claes <toon@iotcl.com>
Date
Oct 24, 2025, 14:01 UTC
Message-ID
<87v7k4pffg.fsf@iotcl.com>
In-Reply-To
<20251024-b4-pks-rust-cbindgen-v2-5-4b4bd4f18490@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 22 quoted lines
> [snip]
>
> diff --git a/meson.build b/meson.build
> index 308798e861..b4acc417ad 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -523,6 +523,7 @@ libgit_sources = [
>    'usage.c',
>    'userdiff.c',
>    'utf8.c',
> +  'varint.c',
>    'version.c',
>    'versioncmp.c',
>    'walker.c',
> @@ -1704,7 +1705,9 @@ version_def_h = custom_target(
>  libgit_sources += version_def_h
>  
>  cargo = find_program('cargo', dirs: program_path, native: true, required: get_option('rust'))
> -rust_option = get_option('rust').disable_auto_if(not cargo.found())
> +cbindgen = find_program('cbindgen', dirs: program_path, native: true, required: get_option('rust'))
> +
> +rust_option = get_option('rust').disable_auto_if(not cargo.found() or not cbindgen.found())

This means to compile with Rust we not only need cargo, but also cbindgen. As we ideally want to have a broad platform support, would adding another dependency (i.e. `cbindgen`) narrow the platforms we'd eventually support? Or can we consider platforms supporting Rust also have cbindgen?

Show 17 quoted lines
> [snip]
>
> diff --git a/varint.c b/varint.c
> index 03cd54416b..1ed738a756 100644
> --- a/varint.c
> +++ b/varint.c
> @@ -1,6 +1,14 @@
>  #include "git-compat-util.h"
>  #include "varint.h"
>  
> +/*
> + * When building with Rust we don't compile the C code, but we only verify
> + * whether the function signatures of our C bindings match the ones we have
> + * declared in "varint.h".
> + */
> +#ifdef WITH_RUST
> +# include "c-bindings.h"

So when we rewrite more subsystems into Rust, this will include definitions from all those subsystems into this compilation unit. If one subsystem with a Rust alternative implementation includes the header from another subsystem with a Rust-alternative implementation, the function signatures are checked twice, and errors are surfaced twice. I guess this is a tradeoff we can accept for now, because:

* We only have one subsystem in Rust now.
* The approach in this patch simplifies the build setup.

We might revisit that at some point, but I can agree this is the most sensical approach for now.

-- 
Cheers,
Toon
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 35 of 38 in “rust: generate bindings via cbindgen”
  1. 0/3 rust: generate bindings via cbindgenPatrick Steinhardt, Oct 23, 2025
  2. 1/3 ci: use Debian instead of deprecated i386/ubuntuPatrick Steinhardt, Oct 23, 2025
  3. Junio C HamanoOct 23, 2025
  4. Patrick SteinhardtOct 24, 2025
  5. 2/3 meson: rename Rust library targetPatrick Steinhardt, Oct 23, 2025
  6. 3/3 rust: generate bindings via cbindgenPatrick Steinhardt, Oct 23, 2025
  7. Ezekiel NewrenOct 23, 2025
  8. Patrick SteinhardtOct 24, 2025
  9. Ezekiel NewrenOct 27, 2025
  10. brian m. carlsonOct 27, 2025
  11. Junio C HamanoOct 28, 2025
  12. Ezekiel NewrenOct 28, 2025
  13. Patrick SteinhardtOct 30, 2025
  14. Patrick SteinhardtOct 30, 2025
  15. brian m. carlsonOct 30, 2025
  16. Junio C HamanoOct 30, 2025
  17. brian m. carlsonOct 30, 2025
  18. Patrick SteinhardtOct 31, 2025
  19. Patrick SteinhardtOct 30, 2025
  20. Ezekiel NewrenOct 31, 2025
  21. Junio C HamanoOct 23, 2025
  22. Junio C HamanoOct 23, 2025
  23. Junio C HamanoOct 23, 2025
  24. Patrick SteinhardtOct 24, 2025
  25. 0/5 rust: generate bindings via cbindgenPatrick Steinhardt, Oct 24, 2025
  26. 1/5 gitlab-ci: reorder Linux job matrix to match GitHub's orderPatrick Steinhardt, Oct 24, 2025
  27. Ezekiel NewrenOct 28, 2025
  28. 2/5 gitlab-ci: backfill missing Linux jobsPatrick Steinhardt, Oct 24, 2025
  29. Ezekiel NewrenOct 28, 2025
  30. 3/5 ci: use Debian instead of deprecated i386/ubuntuPatrick Steinhardt, Oct 24, 2025
  31. Ezekiel NewrenOct 28, 2025
  32. Patrick SteinhardtOct 30, 2025
  33. 4/5 meson: rename Rust library targetPatrick Steinhardt, Oct 24, 2025
  34. 5/5 rust: generate bindings via cbindgenPatrick Steinhardt, Oct 24, 2025
  35. Toon ClaesOct 24, 2025
  36. Patrick SteinhardtOct 30, 2025
  37. Ezekiel NewrenOct 28, 2025
  38. Patrick SteinhardtOct 30, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.