From 0ced767f14bb7291bdd9f466ffb5969eab33cae2 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Thu, 8 Oct 2026 11:21:09 +0100 Subject: [PATCH] tools/cbindgen: add cbindgen host tool Build cbindgen 0.28.0 from a vendor tarball. cbindgen generates C headers from Rust code and is needed by Mesa for the NIL and NAK components of the Nouveau driver. USE_CBINDGEN is enabled by default with any Rust toolchain. Signed-off-by: Daniel Golle --- toolchain/Config.in | 10 ++++++++++ tools/Makefile | 2 ++ tools/cbindgen/Makefile | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 tools/cbindgen/Makefile diff --git a/toolchain/Config.in b/toolchain/Config.in index d3fdd20f0cf..2fd4cb7e302 100644 --- a/toolchain/Config.in +++ b/toolchain/Config.in @@ -392,6 +392,16 @@ config BUILD_BINDGEN help Installs bindgen-cli to the host toolchain. +config USE_CBINDGEN + bool + prompt "Build cbindgen (Rust to C-header generator)" if RUST_TOOLCHAINOPTS + depends on USE_RUST_TOOLCHAIN + default y + help + Installs cbindgen to the host toolchain. Required by Mesa3D Nouveau + (NIL image library, NAK compiler) which generates C headers from Rust. + Select when building Mesa3D with Nouveau/NVIDIA support. + config HAS_BPF_TOOLCHAIN default y if !BPF_TOOLCHAIN_NONE bool diff --git a/tools/Makefile b/tools/Makefile index 02a040e949c..6fa5e6d82c4 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -89,6 +89,7 @@ tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(CONFIG_USE_LLVM_BUILD),y) += llvm-bpf tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(CONFIG_USE_MOLD),y) += mold tools-$(CONFIG_USE_RUST_TOOLCHAIN) += rust tools-$(CONFIG_BUILD_BINDGEN) += bindgen +tools-$(CONFIG_USE_CBINDGEN) += cbindgen # builddir dependencies $(curdir)/autoconf/compile := $(curdir)/m4/compile @@ -121,6 +122,7 @@ $(curdir)/lzop/compile := $(curdir)/cmake/compile $(curdir)/liblzo/compile $(curdir)/llvm-bpf/compile := $(curdir)/cmake/compile $(curdir)/rust/compile := $(curdir)/cmake/compile $(curdir)/libdeflate/compile $(curdir)/xz/compile $(curdir)/bindgen/compile := $(curdir)/rust/compile $(if $(CONFIG_USE_LLVM_BUILD),$(curdir)/llvm-bpf/compile) +$(curdir)/cbindgen/compile := $(curdir)/rust/compile $(curdir)/make-ext4fs/compile := $(curdir)/zlib/compile $(curdir)/meson/compile := $(curdir)/ninja/compile $(curdir)/missing-macros/compile := $(curdir)/autoconf/compile diff --git a/tools/cbindgen/Makefile b/tools/cbindgen/Makefile new file mode 100644 index 00000000000..5ddc6d17992 --- /dev/null +++ b/tools/cbindgen/Makefile @@ -0,0 +1,33 @@ +# SPDX-License-Identifier: GPL-2.0-only + +include $(TOPDIR)/rules.mk + +PKG_NAME:=cbindgen +PKG_VERSION:=0.28.0 +PKG_RELEASE:=1 + +# Vendor tarball: upstream source + vendor/ + .cargo/config.toml. +# Generated from the upstream .crate via DownloadMethod/cargo-vendor-crate, or +# regenerate manually with: scripts/gen-cargo-vendor-tarball.sh crate cbindgen 0.28.0 +# The generator makes the tarball independent of the cargo version. +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-vendor.tar.zst +PKG_SOURCE_URL:=@OPENWRT +PKG_SOURCE_PROTO:=cargo-vendor-crate +PKG_VENDOR_HASH:=eadd868a2ce9ca38de7eeafdcec9c7065ef89b42b32f0839278d55f35c54d1ff +PKG_HASH:=834a03b4fcbbcbd6a2547bf15f8854b075aeb1460a6107c6db47b28a90dee15d + +HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/$(PKG_NAME)-$(PKG_VERSION) + +include $(INCLUDE_DIR)/host-build.mk +include $(INCLUDE_DIR)/rust-host-build.mk + +# cbindgen generates C headers from Rust structs (reverse direction from +# bindgen). Required by Mesa3D Nouveau (NIL image library, NAK compiler). +# Pure Rust parser, with no libclang dependency. + +define Host/Install + $(INSTALL_DIR) $(STAGING_DIR_HOST)/bin + $(INSTALL_BIN) $(HOST_INSTALL_DIR)/bin/cbindgen $(STAGING_DIR_HOST)/bin/cbindgen +endef + +$(eval $(call HostBuild))