diff mbox series

[meta-oe] cbindgen: Fix build on riscv32

Message ID 20250405205809.1482819-1-raj.khem@gmail.com
State New
Headers show
Series [meta-oe] cbindgen: Fix build on riscv32 | expand

Commit Message

Khem Raj April 5, 2025, 8:58 p.m. UTC
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 ...1-Fix-rustix-0.38.x-build-on-riscv32.patch | 72 +++++++++++++++++++
 .../cbindgen/cbindgen_0.28.0.bb               |  3 +-
 2 files changed, 74 insertions(+), 1 deletion(-)
 create mode 100644 meta-oe/recipes-devtools/cbindgen/cbindgen/0001-Fix-rustix-0.38.x-build-on-riscv32.patch
diff mbox series

Patch

diff --git a/meta-oe/recipes-devtools/cbindgen/cbindgen/0001-Fix-rustix-0.38.x-build-on-riscv32.patch b/meta-oe/recipes-devtools/cbindgen/cbindgen/0001-Fix-rustix-0.38.x-build-on-riscv32.patch
new file mode 100644
index 0000000000..951a6ee03c
--- /dev/null
+++ b/meta-oe/recipes-devtools/cbindgen/cbindgen/0001-Fix-rustix-0.38.x-build-on-riscv32.patch
@@ -0,0 +1,72 @@ 
+From 03b4becfbd094be8e28c9f0cd84011d62780316c Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Wed, 2 Apr 2025 20:01:24 -0700
+Subject: [PATCH] Fix rustix 0.38.x build on riscv32
+
+Upstream-Status: Submitted [https://github.com/bytecodealliance/rustix/pull/1435]
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ src/fs/ioctl.rs | 27 ++++++++++++++++++++++++---
+ 1 file changed, 24 insertions(+), 3 deletions(-)
+
+diff --git a/src/fs/ioctl.rs b/src/fs/ioctl.rs
+index 490f183..068b3c7 100644
+--- a/src/fs/ioctl.rs
++++ b/src/fs/ioctl.rs
+@@ -11,6 +11,14 @@ use {
+ 
+ use bitflags::bitflags;
+ 
++/// The datatype used for the ioctl number
++#[cfg(any(target_os = "android", target_env = "musl"))]
++#[doc(hidden)]
++pub type ioctl_num_type = c::c_int;
++#[cfg(not(any(target_os = "android", target_env = "musl")))]
++#[doc(hidden)]
++pub type ioctl_num_type = c::c_ulong;
++
+ #[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))]
+ use crate::fd::{AsRawFd, BorrowedFd};
+ 
+@@ -79,7 +87,8 @@ unsafe impl ioctl::Ioctl for Ficlone<'_> {
+     type Output = ();
+ 
+     const IS_MUTATING: bool = false;
+-    const OPCODE: ioctl::Opcode = ioctl::Opcode::old(c::FICLONE as ioctl::RawOpcode);
++    const OPCODE: ioctl::Opcode =
++        ioctl::Opcode::old(linux_raw_sys::ioctl::FICLONE as ioctl::RawOpcode);
+ 
+     fn as_ptr(&mut self) -> *mut c::c_void {
+         self.0.as_raw_fd() as *mut c::c_void
+@@ -136,7 +145,12 @@ bitflags! {
+ #[doc(alias = "FS_IOC_GETFLAGS")]
+ pub fn ioctl_getflags<Fd: AsFd>(fd: Fd) -> io::Result<IFlags> {
+     unsafe {
+-        #[cfg(target_pointer_width = "32")]
++        #[cfg(target_arch = "riscv32")]
++        let ctl = ioctl::Getter::<
++            ioctl::BadOpcode<{ linux_raw_sys::ioctl::FS_IOC32_GETFLAGS as ioctl_num_type }>,
++            u32,
++        >::new();
++        #[cfg(all(target_pointer_width = "32", not(target_arch = "riscv32")))]
+         let ctl = ioctl::Getter::<ioctl::BadOpcode<{ c::FS_IOC32_GETFLAGS }>, u32>::new();
+         #[cfg(target_pointer_width = "64")]
+         let ctl = ioctl::Getter::<ioctl::BadOpcode<{ c::FS_IOC_GETFLAGS }>, u32>::new();
+@@ -152,8 +166,15 @@ pub fn ioctl_getflags<Fd: AsFd>(fd: Fd) -> io::Result<IFlags> {
+ #[inline]
+ #[doc(alias = "FS_IOC_SETFLAGS")]
+ pub fn ioctl_setflags<Fd: AsFd>(fd: Fd, flags: IFlags) -> io::Result<()> {
++    use crate::ioctl::Ioctl;
++
+     unsafe {
+-        #[cfg(target_pointer_width = "32")]
++        #[cfg(target_arch = "riscv32")]
++        let ctl = ioctl::Setter::<
++            ioctl::BadOpcode<{ linux_raw_sys::ioctl::FS_IOC32_SETFLAGS as ioctl_num_type }>,
++            u32,
++        >::new(flags.bits());
++        #[cfg(all(target_pointer_width = "32", not(target_arch = "riscv32")))]
+         let ctl =
+             ioctl::Setter::<ioctl::BadOpcode<{ c::FS_IOC32_SETFLAGS }>, u32>::new(flags.bits());
+ 
diff --git a/meta-oe/recipes-devtools/cbindgen/cbindgen_0.28.0.bb b/meta-oe/recipes-devtools/cbindgen/cbindgen_0.28.0.bb
index 40436ef035..1ca9b35c4d 100644
--- a/meta-oe/recipes-devtools/cbindgen/cbindgen_0.28.0.bb
+++ b/meta-oe/recipes-devtools/cbindgen/cbindgen_0.28.0.bb
@@ -3,7 +3,8 @@  HOMEPAGE = "https://github.com/mozilla/cbindgen"
 LICENSE = "MPL-2.0"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=9741c346eef56131163e13b9db1241b3"
 
-SRC_URI += "git://github.com/mozilla/cbindgen.git;protocol=https;branch=master"
+SRC_URI += "git://github.com/mozilla/cbindgen.git;protocol=https;branch=master \
+            file://0001-Fix-rustix-0.38.x-build-on-riscv32.patch;patchdir=${CARGO_VENDORING_DIRECTORY}/rustix-0.38.34"
 SRCREV = "bd78bbe59b10eda6ef1255e4acda95c56c6d0279"
 S = "${WORKDIR}/git"