From 703c2dbb187bf1db2593261788f788b353350e5e Mon Sep 17 00:00:00 2001 From: frc4533-lincoln <132951735+frc4533-lincoln@users.noreply.github.com> Date: Tue, 27 May 2025 10:28:23 -0400 Subject: [PATCH 1/3] Enable statx for musl --- libc-test/build.rs | 13 ++++++------- libc-test/test/cmsg.rs | 2 +- src/unix/aix/mod.rs | 3 +-- src/unix/linux_like/mod.rs | 6 +++--- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index a31d6ba4878ba..1938a61d576b6 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -5525,9 +5525,9 @@ fn test_aix(target: &str) { }); cfg.type_name(move |ty, is_struct, is_union| match ty { - "DIR" => ty.to_string(), - "FILE" => ty.to_string(), - "ACTION" => ty.to_string(), + "DIR" => ty.to_string(), + "FILE" => ty.to_string(), + "ACTION" => ty.to_string(), // 'sigval' is a struct in Rust, but a union in C. "sigval" => format!("union sigval"), @@ -5614,9 +5614,9 @@ fn test_aix(target: &str) { // POSIX-compliant versions in the system libc. As a result, // function pointer comparisons between the C and Rust sides // would fail. - "getpwuid_r" | "getpwnam_r" | "getgrgid_r" | "getgrnam_r" - | "aio_cancel" | "aio_error" | "aio_fsync" | "aio_read" - | "aio_return" | "aio_suspend" | "aio_write" | "select" => true, + "getpwuid_r" | "getpwnam_r" | "getgrgid_r" | "getgrnam_r" | "aio_cancel" + | "aio_error" | "aio_fsync" | "aio_read" | "aio_return" | "aio_suspend" + | "aio_write" | "select" => true, // 'getdtablesize' is a constant in the AIX header but it is // a real function in libc which the Rust side is resolved to. @@ -5633,7 +5633,6 @@ fn test_aix(target: &str) { } }); - cfg.volatile_item(|i| { use ctest::VolatileItemKind::*; match i { diff --git a/libc-test/test/cmsg.rs b/libc-test/test/cmsg.rs index 15f4fed1e30ec..763819019b771 100644 --- a/libc-test/test/cmsg.rs +++ b/libc-test/test/cmsg.rs @@ -70,7 +70,7 @@ mod t { for cmsg_len in 0..64 { // Address must be a multiple of 0x4 for testing on AIX. if cfg!(target_os = "aix") && cmsg_len % std::mem::size_of::() != 0 { - continue; + continue; } for next_cmsg_len in 0..32 { unsafe { diff --git a/src/unix/aix/mod.rs b/src/unix/aix/mod.rs index 75bbcbef1dd93..a45d8b023f3cd 100644 --- a/src/unix/aix/mod.rs +++ b/src/unix/aix/mod.rs @@ -1,6 +1,5 @@ -use crate::in_addr_t; -use crate::in_port_t; use crate::prelude::*; +use crate::{in_addr_t, in_port_t}; pub type caddr_t = *mut c_char; pub type clockid_t = c_longlong; diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs index 3145c06453bd9..2e9d8a8899857 100644 --- a/src/unix/linux_like/mod.rs +++ b/src/unix/linux_like/mod.rs @@ -239,7 +239,7 @@ cfg_if! { } cfg_if! { - if #[cfg(any(target_env = "gnu", target_os = "android"))] { + if #[cfg(any(target_env = "gnu", target_os = "android", target_env = "musl"))] { s! { pub struct statx { pub stx_mask: crate::__u32, @@ -1709,7 +1709,7 @@ cfg_if! { } cfg_if! { - if #[cfg(any(target_env = "gnu", target_os = "android"))] { + if #[cfg(any(target_env = "gnu", target_os = "android", target_env = "musl"))] { pub const AT_STATX_SYNC_TYPE: c_int = 0x6000; pub const AT_STATX_SYNC_AS_STAT: c_int = 0x0000; pub const AT_STATX_FORCE_SYNC: c_int = 0x2000; @@ -2206,7 +2206,7 @@ cfg_if! { // The statx syscall, available on some libcs. cfg_if! { - if #[cfg(any(target_env = "gnu", target_os = "android"))] { + if #[cfg(any(target_env = "gnu", target_os = "android", target_env = "musl"))] { extern "C" { pub fn statx( dirfd: c_int, From 0908643caf9c6a05be361820653322e3ea69fab9 Mon Sep 17 00:00:00 2001 From: frc4533-lincoln <132951735+frc4533-lincoln@users.noreply.github.com> Date: Tue, 27 May 2025 15:21:23 -0400 Subject: [PATCH 2/3] Add renameat2 binding for musl --- src/unix/linux_like/linux/musl/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/unix/linux_like/linux/musl/mod.rs b/src/unix/linux_like/linux/musl/mod.rs index 43222e8185a5e..b711b08b5970c 100644 --- a/src/unix/linux_like/linux/musl/mod.rs +++ b/src/unix/linux_like/linux/musl/mod.rs @@ -927,6 +927,13 @@ extern "C" { flags: c_int, ) -> ssize_t; pub fn getauxval(type_: c_ulong) -> c_ulong; + pub fn renameat2( + oldfd: c_int, + old: *const c_char, + newfd: c_int, + new: *const c_char, + flags: c_uint, + ) -> c_int; // Added in `musl` 1.1.20 pub fn explicit_bzero(s: *mut c_void, len: size_t); From 4c7bd695e473a84380534e1f6e84091674f6d62e Mon Sep 17 00:00:00 2001 From: frc4533-lincoln <132951735+frc4533-lincoln@users.noreply.github.com> Date: Thu, 5 Jun 2025 12:54:35 -0400 Subject: [PATCH 3/3] Fix style --- src/unix/linux_like/mod.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs index 2e9d8a8899857..2935223551dcf 100644 --- a/src/unix/linux_like/mod.rs +++ b/src/unix/linux_like/mod.rs @@ -239,7 +239,11 @@ cfg_if! { } cfg_if! { - if #[cfg(any(target_env = "gnu", target_os = "android", target_env = "musl"))] { + if #[cfg(any( + target_env = "gnu", + target_os = "android", + target_env = "musl" + ))] { s! { pub struct statx { pub stx_mask: crate::__u32, @@ -1709,7 +1713,11 @@ cfg_if! { } cfg_if! { - if #[cfg(any(target_env = "gnu", target_os = "android", target_env = "musl"))] { + if #[cfg(any( + target_env = "gnu", + target_os = "android", + target_env = "musl" + ))] { pub const AT_STATX_SYNC_TYPE: c_int = 0x6000; pub const AT_STATX_SYNC_AS_STAT: c_int = 0x0000; pub const AT_STATX_FORCE_SYNC: c_int = 0x2000; @@ -2206,7 +2214,11 @@ cfg_if! { // The statx syscall, available on some libcs. cfg_if! { - if #[cfg(any(target_env = "gnu", target_os = "android", target_env = "musl"))] { + if #[cfg(any( + target_env = "gnu", + target_os = "android", + target_env = "musl" + ))] { extern "C" { pub fn statx( dirfd: c_int,