Skip to contentSkip to conversation

python3-grpcio-tools: Fix build with musl

PATCH New Khem Raj 1 participant 2 messages Jul 7, 2023

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/2 python3-grpcio-tools: Fix build with musl

---
 .../0001-direct_mmap-Use-off_t-on-linux.patch | 37 +++++++++++++++++++
 .../python/python3-grpcio-tools_1.56.0.bb     |  1 +
 2 files changed, 38 insertions(+)
 create mode 100644 meta-python/recipes-devtools/python/python3-grpcio-tools/0001-direct_mmap-Use-off_t-on-linux.patch
meta-python/recipes-devtools/python/python3-grpcio-tools/0001-direct_mmap-Use-off_t-on-linux.patch new file +37 -0
new file mode 100644
index 0000000000..9b3e5d4a5f
@@ -0,0 +1,37 @@
+From 45fdade6c0415ec5af3f9312e6311a4ccc682a7b Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Wed, 28 Dec 2022 18:24:21 -0800
+Subject: [PATCH] direct_mmap: Use off_t on linux
+
+off64_t is not provided without defining _LARGEFILE64_SOURCE on musl
+this define is not defined automatically like glibc where it gets
+defined when _GNU_SOURCE is defined. Using off_t makes it portable
+across musl/glibc and for using 64bit off_t on glibc 32bit systems
+-D_FILE_OFFSET_BITS=64 can be defined during build via CXXFLAGS
+
+Upstream-Status: Submitted [https://github.com/abseil/abseil-cpp/pull/1349]
+Signed-off-by: Khem Raj <[email protected]>
+---
+ absl/base/internal/direct_mmap.h | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+--- a/third_party/abseil-cpp/absl/base/internal/direct_mmap.h
++++ b/third_party/abseil-cpp/absl/base/internal/direct_mmap.h
+@@ -72,7 +72,7 @@ namespace base_internal {
+ // Platform specific logic extracted from
+ // https://chromium.googlesource.com/linux-syscall-support/+/master/linux_syscall_support.h
+ inline void* DirectMmap(void* start, size_t length, int prot, int flags, int fd,
+-                        off64_t offset) noexcept {
++                        off_t offset) noexcept {
+ #if defined(__i386__) || defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) || \
+     defined(__m68k__) || defined(__sh__) ||                                  \
+     (defined(__hppa__) && !defined(__LP64__)) ||                             \
+@@ -102,7 +102,7 @@ inline void* DirectMmap(void* start, siz
+ #else
+   return reinterpret_cast<void*>(
+       syscall(SYS_mmap2, start, length, prot, flags, fd,
+-              static_cast<off_t>(offset / pagesize)));
++              offset / pagesize));
+ #endif
+ #elif defined(__s390x__)
+   // On s390x, mmap() arguments are passed in memory.
meta-python/recipes-devtools/python/python3-grpcio-tools_1.56.0.bb +1 -0
index eb1994d7ce..8fbe1fa91f 100644
@@ -11,6 +11,7 @@ DEPENDS += "${PYTHON_PN}-grpcio"
 
 SRC_URI += "file://0001-setup.py-Do-not-mix-C-and-C-compiler-options.patch \
             file://0001-protobuf-Disable-musttail-attribute-on-mips.patch \
+            file://0001-direct_mmap-Use-off_t-on-linux.patch \
             "
 SRC_URI[sha256sum] = "39f5877cea514b3da9f2683dfb3ffb45ef47b05f4ff39c287d7d61c5057f48b8"
 
Signature · 1 line
2.41.0
author
#1 lore raw

PATCH 2/2 thin-provisioning-tools: Fix build on musl.

---
 .../0001-Replace-LFS-functions.patch          | 91 +++++++++++++++++++
 .../thin-provisioning-tools_1.0.4.bb          |  2 +
 2 files changed, 93 insertions(+)
 create mode 100644 meta-oe/recipes-support/thin-provisioning-tools/thin-provisioning-tools/0001-Replace-LFS-functions.patch
meta-oe/recipes-support/thin-provisioning-tools/thin-provisioning-tools/0001-Replace-LFS-functions.patch new file +91 -0
new file mode 100644
index 0000000000..a9f1c8601d
@@ -0,0 +1,91 @@
+From 289105253fbf342fd22cbcde2ccc1127f732ab09 Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Fri, 7 Jul 2023 14:21:17 -0700
+Subject: [PATCH] Replace LFS functions
+
+The original functions are able to consume 64bit off_t now a days
+therefore *64 equivalents can be replaced, as a side it fixes build with
+musl.
+
+Upstream-Status: Submitted [https://github.com/jthornber/thin-provisioning-tools/pull/267]
+Signed-off-by: Khem Raj <[email protected]>
+---
+ src/file_utils.rs     | 10 +++++-----
+ src/io_engine/base.rs |  4 ++--
+ src/thin/trim.rs      |  2 +-
+ 3 files changed, 8 insertions(+), 8 deletions(-)
+
+diff --git a/src/file_utils.rs b/src/file_utils.rs
+index 0ca3c0f..d2b3ee9 100644
+--- a/src/file_utils.rs
++++ b/src/file_utils.rs
+@@ -11,18 +11,18 @@ fn test_bit(mode: u32, flag: u32) -> bool {
+     (mode & libc::S_IFMT) == flag
+ }
+ 
+-fn is_file_or_blk_(info: &libc::stat64) -> bool {
++fn is_file_or_blk_(info: &libc::stat) -> bool {
+     test_bit(info.st_mode, libc::S_IFBLK) || test_bit(info.st_mode, libc::S_IFREG)
+ }
+ 
+ // wrapper of libc::stat64
+-fn libc_stat64(path: &Path) -> io::Result<libc::stat64> {
++fn libc_stat64(path: &Path) -> io::Result<libc::stat> {
+     let c_path = std::ffi::CString::new(path.as_os_str().as_bytes())
+         .map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e.to_string()))?;
+ 
+     unsafe {
+-        let mut st: libc::stat64 = std::mem::zeroed();
+-        let r = libc::stat64(c_path.as_ptr(), &mut st);
++        let mut st: libc::stat = std::mem::zeroed();
++        let r = libc::stat(c_path.as_ptr(), &mut st);
+         if r == 0 {
+             Ok(st)
+         } else {
+@@ -56,7 +56,7 @@ fn get_device_size<P: AsRef<Path>>(path: P) -> io::Result<u64> {
+     let fd = file.as_raw_fd();
+     let mut cap = 0u64;
+     unsafe {
+-        if libc::ioctl(fd, BLKGETSIZE64 as libc::c_ulong, &mut cap) == 0 {
++        if libc::ioctl(fd, BLKGETSIZE64 as libc::c_int, &mut cap) == 0 {
+             Ok(cap)
+         } else {
+             Err(io::Error::last_os_error())
+diff --git a/src/io_engine/base.rs b/src/io_engine/base.rs
+index 725ebf7..db6209f 100644
+--- a/src/io_engine/base.rs
++++ b/src/io_engine/base.rs
+@@ -115,7 +115,7 @@ pub trait VectoredIo {
+ 
+ fn read_vectored_at(file: &File, bufs: &mut [libc::iovec], pos: u64) -> io::Result<usize> {
+     let ptr = bufs.as_ptr();
+-    let ret = match unsafe { libc::preadv64(file.as_raw_fd(), ptr, bufs.len() as i32, pos as i64) }
++    let ret = match unsafe { libc::preadv(file.as_raw_fd(), ptr, bufs.len() as i32, pos as i64) }
+     {
+         -1 => return Err(io::Error::last_os_error()),
+         n => n,
+@@ -125,7 +125,7 @@ fn read_vectored_at(file: &File, bufs: &mut [libc::iovec], pos: u64) -> io::Resu
+ 
+ fn write_vectored_at(file: &File, bufs: &[libc::iovec], pos: u64) -> io::Result<usize> {
+     let ptr = bufs.as_ptr();
+-    let ret = match unsafe { libc::pwritev64(file.as_raw_fd(), ptr, bufs.len() as i32, pos as i64) }
++    let ret = match unsafe { libc::pwritev(file.as_raw_fd(), ptr, bufs.len() as i32, pos as i64) }
+     {
+         -1 => return Err(io::Error::last_os_error()),
+         n => n,
+diff --git a/src/thin/trim.rs b/src/thin/trim.rs
+index 3d938ca..91a53dd 100644
+--- a/src/thin/trim.rs
++++ b/src/thin/trim.rs
+@@ -135,7 +135,7 @@ impl<'a> Iterator for RangeIterator<'a> {
+ const BLKDISCARD: u32 = 0x1277;
+ fn ioctl_blkdiscard(fd: i32, range: &[u64; 2]) -> std::io::Result<()> {
+     unsafe {
+-        if libc::ioctl(fd, BLKDISCARD as libc::c_ulong, range) == 0 {
++        if libc::ioctl(fd, BLKDISCARD as libc::c_int, range) == 0 {
+             Ok(())
+         } else {
+             Err(std::io::Error::last_os_error())
+-- 
+2.41.0
+
meta-oe/recipes-support/thin-provisioning-tools/thin-provisioning-tools_1.0.4.bb +2 -0
index 5a73024289..e79f62ff6e 100644
@@ -10,6 +10,8 @@ S = "${WORKDIR}/git"
 SRC_URI = " \
     git://github.com/jthornber/thin-provisioning-tools;branch=main;protocol=https \
     "
+SRC_URI:append:libc-musl = " file://0001-Replace-LFS-functions.patch"
+
 SRCREV = "3baa3fa3a3e4f714e6170a4152b186f0fa1d76e1"
 UPSTREAM_CHECK_GITTAGREGEX = "v(?P<pver>\d+(\.\d+)+)"
 
Signature · 1 line
2.41.0