From: Patrick Steinhardt Date: Fri, 24 Oct 2025 09:51:32 GMT Subject: [PATCH v2 0/5] rust: generate bindings via cbindgen Message-ID: <20251024-b4-pks-rust-cbindgen-v2-0-4b4bd4f18490@pks.im> In-Reply-To: <20251023-b4-pks-rust-cbindgen-v1-0-c19b61b03127@pks.im> Hi, this small patch series introduces support for cbindgen(1). This tool is used to generate C headers from `extern "C"` blocks so that Rust code can easily be called from C code. For now, the only use case is to verify that our varint reimplementation matches the C implementation. But later on this can and will be used to call Rust-specific features from C, as well. The topic is built on top of c54a18ef67 (The twenty-second batch, 2025-10-22) with ps/ci-rust at e509b5b8be (rust: support for Windows, 2025-10-15) merged into it. Changes in v2: - Take some of the pieces from Ezekiel's "cbindgen.toml" file. I have not yet taken `usize_is_size_t`, as that option requires cbindgen v0.16.0, which is not available on Ubuntu 20.04. - Backfill missing jobs for GitLab CI. - Fix CI failures on Alma Linux 8 because cbindgen isn't available there. - Link to v1: https://lore.kernel.org/r/20251023-b4-pks-rust-cbindgen-v1-0-c19b61b03127@pks.im Thanks! Patrick --- Patrick Steinhardt (5): gitlab-ci: reorder Linux job matrix to match GitHub's order gitlab-ci: backfill missing Linux jobs ci: use Debian instead of deprecated i386/ubuntu meson: rename Rust library target rust: generate bindings via cbindgen .github/workflows/main.yml | 3 +-- .gitignore | 1 + .gitlab-ci.yml | 22 ++++++++++++++-------- Makefile | 14 +++++++++++--- cbindgen.toml | 13 +++++++++++++ ci/install-dependencies.sh | 16 +++++++++++----- ci/lib.sh | 2 +- meson.build | 25 ++++++++++++++++++++----- shared.mak | 1 + src/meson.build | 2 +- varint.c | 9 +++++++++ 11 files changed, 83 insertions(+), 25 deletions(-) Range-diff versus v1: -: ---------- > 1: 81e7677f3a gitlab-ci: reorder Linux job matrix to match GitHub's order -: ---------- > 2: c367154007 gitlab-ci: backfill missing Linux jobs 1: 740702529c ! 3: a1d7260326 ci: use Debian instead of deprecated i386/ubuntu @@ .gitlab-ci.yml: test:linux: - jobname: linux32 - image: i386/ubuntu:20.04 + image: i386/debian:latest - - jobname: linux-meson - image: ubuntu:rolling - CC: gcc + # A RHEL 8 compatible distro. Supported until 2029-05-31. + - jobname: almalinux-8 + image: almalinux:8 ## ci/install-dependencies.sh ## @@ ci/install-dependencies.sh: fedora-*|almalinux-*) @@ ci/lib.sh: then CI_OS_NAME=osx JOBS=$(nproc) ;; -- *,alpine:*|*,fedora:*|*,ubuntu:*|*,i386/ubuntu:*) -+ *,alpine:*|*,fedora:*|*,ubuntu:*|*,i386/debian:*) +- *,almalinux:*|*,alpine:*|*,debian:*|*,fedora:*|*,ubuntu:*|*,i386/ubuntu:*) ++ *,almalinux:*|*,alpine:*|*,debian:*|*,fedora:*|*,ubuntu:*|*,i386/debian:*) CI_OS_NAME=linux JOBS=$(nproc) ;; 2: ff696cfb2e = 4: 490c8a4d45 meson: rename Rust library target 3: 67a9f353df ! 5: 8b7a2469b2 rust: generate bindings via cbindgen @@ cbindgen.toml (new) @@ +language = "C" + ++# Write a warning into the generated file. ++autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" ++ +# Don't include standard C headers. These are managed by "git-compat-util.h". +no_includes = true + +# Use plain structs instead of using typedefs. +style = "tag" ++ ++# Match our coding style more closely. ++tab_width = 8 ## ci/install-dependencies.sh ## -@@ ci/install-dependencies.sh: fedora-*|almalinux-*) +@@ ci/install-dependencies.sh: alpine-*) + bash cvs gnupg perl-cgi perl-dbd-sqlite perl-io-tty >/dev/null + ;; + fedora-*|almalinux-*) ++ RUST_DEPS="cargo cbindgen" + case "$jobname" in ++ almalinux-8) ++ # AlmaLinux 8 does not have cbindgen, it was only added in version 9. ++ RUST_DEPS=;; + *-meson) MESON_DEPS="meson ninja";; esac ++ dnf -yq update >/dev/null && - dnf -yq install shadow-utils sudo make pkg-config gcc findutils diffutils perl python3 gawk gettext zlib-devel expat-devel openssl-devel curl-devel pcre2-devel $MESON_DEPS cargo >/dev/null -+ dnf -yq install shadow-utils sudo make pkg-config gcc findutils diffutils perl python3 gawk gettext zlib-devel expat-devel openssl-devel curl-devel pcre2-devel $MESON_DEPS cargo cbindgen >/dev/null ++ dnf -yq install shadow-utils sudo make pkg-config gcc findutils diffutils perl python3 gawk gettext \ ++ zlib-devel expat-devel openssl-devel curl-devel pcre2-devel $MESON_DEPS $RUST_DEPS >/dev/null ;; ubuntu-*|i386/debian-*|debian-*) # Required so that apt doesn't wait for user input on certain packages. --- base-commit: 8654b230d9afe1326340989dd7082997c672472e change-id: 20251009-b4-pks-rust-cbindgen-d80779ed2269