Skip to content

Commit d69e2ed

Browse files
committed
uclibc support
1 parent c3731f1 commit d69e2ed

16 files changed

+75
-27
lines changed

.cirrus.yml

+3
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ task:
280280
- name: OpenBSD x86_64
281281
env:
282282
TARGET: x86_64-unknown-openbsd
283+
- name: Linux armv7 uclibceabihf
284+
env:
285+
TARGET: armv7-unknown-linux-uclibceabihf
283286
setup_script:
284287
- rustup component add rust-src
285288
<< : *BUILD

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ targets = [
2727
]
2828

2929
[dependencies]
30-
libc = { git = "https://github.com/rust-lang/libc", rev = "e470e3b6a1f940e0024d40d3b79fc73fe29c7f17", features = [ "extra_traits" ] }
30+
libc = { version = "0.2.113", features = [ "extra_traits" ] }
3131
bitflags = "1.1"
3232
cfg-if = "1.0"
3333

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Tier 2:
7878
* x86_64-unknown-netbsd
7979

8080
Tier 3:
81+
* armv7-unknown-linux-uclibceabihf
8182
* x86_64-fuchsia
8283
* x86_64-unknown-dragonfly
8384
* x86_64-unknown-linux-gnux32

bors.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ status = [
1414
"Linux arm gnueabi",
1515
"Linux arm-musleabi",
1616
"Linux armv7 gnueabihf",
17+
"Linux armv7 uclibceabihf",
1718
"Linux i686 musl",
1819
"Linux i686",
1920
"Linux mipsel",

src/sys/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#[cfg(any(target_os = "dragonfly",
33
target_os = "freebsd",
44
target_os = "ios",
5-
target_os = "linux",
5+
all(target_os = "linux", not(target_env = "uclibc")),
66
target_os = "macos",
77
target_os = "netbsd"))]
88
feature! {

src/sys/personality.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ libc_bitflags! {
1111
ADDR_NO_RANDOMIZE;
1212
ADDR_LIMIT_32BIT;
1313
ADDR_LIMIT_3GB;
14-
#[cfg(not(target_env = "musl"))]
14+
#[cfg(not(any(target_env = "musl", target_env = "uclibc")))]
1515
FDPIC_FUNCPTRS;
1616
MMAP_PAGE_ZERO;
1717
READ_IMPLIES_EXEC;
1818
SHORT_INODE;
1919
STICKY_TIMEOUTS;
20-
#[cfg(not(target_env = "musl"))]
20+
#[cfg(not(any(target_env = "musl", target_env = "uclibc")))]
2121
UNAME26;
2222
WHOLE_SECONDS;
2323
}

src/sys/ptrace/linux.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use libc::user_regs_struct;
2020

2121
cfg_if! {
2222
if #[cfg(any(all(target_os = "linux", target_arch = "s390x"),
23-
all(target_os = "linux", target_env = "gnu")))] {
23+
all(target_os = "linux", target_env = "gnu"),
24+
target_env = "uclibc"))] {
2425
#[doc(hidden)]
2526
pub type RequestType = ::libc::c_uint;
2627
} else {
@@ -30,8 +31,8 @@ cfg_if! {
3031
}
3132

3233
libc_enum!{
33-
#[cfg_attr(not(any(target_env = "musl", target_os = "android")), repr(u32))]
34-
#[cfg_attr(any(target_env = "musl", target_os = "android"), repr(i32))]
34+
#[cfg_attr(not(any(target_env = "musl", target_env = "uclibc", target_os = "android")), repr(u32))]
35+
#[cfg_attr(any(target_env = "musl", target_env = "uclibc", target_os = "android"), repr(i32))]
3536
/// Ptrace Request enum defining the action to be taken.
3637
#[non_exhaustive]
3738
pub enum Request {

src/sys/resource.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ pub use libc::rlim_t;
77
use std::mem;
88

99
cfg_if! {
10-
if #[cfg(all(target_os = "linux", target_env = "gnu"))]{
10+
if #[cfg(all(target_os = "linux", any(target_env = "gnu", target_env = "uclibc")))]{
1111
use libc::{__rlimit_resource_t, rlimit, RLIM_INFINITY};
12-
}else if #[cfg(any(
12+
} else if #[cfg(any(
1313
target_os = "freebsd",
1414
target_os = "openbsd",
1515
target_os = "netbsd",
@@ -199,9 +199,9 @@ pub fn getrlimit(resource: Resource) -> Result<(Option<rlim_t>, Option<rlim_t>)>
199199
let mut old_rlim = mem::MaybeUninit::<rlimit>::uninit();
200200

201201
cfg_if! {
202-
if #[cfg(all(target_os = "linux", target_env = "gnu"))]{
202+
if #[cfg(all(target_os = "linux", any(target_env = "gnu", target_env = "uclibc")))]{
203203
let res = unsafe { libc::getrlimit(resource as __rlimit_resource_t, old_rlim.as_mut_ptr()) };
204-
}else{
204+
} else {
205205
let res = unsafe { libc::getrlimit(resource as c_int, old_rlim.as_mut_ptr()) };
206206
}
207207
}
@@ -253,7 +253,7 @@ pub fn setrlimit(
253253
rlim_max: hard_limit.unwrap_or(RLIM_INFINITY),
254254
};
255255
cfg_if! {
256-
if #[cfg(all(target_os = "linux", target_env = "gnu"))]{
256+
if #[cfg(all(target_os = "linux", any(target_env = "gnu", target_env = "uclibc")))]{
257257
let res = unsafe { libc::setrlimit(resource as __rlimit_resource_t, &new_rlim as *const rlimit) };
258258
}else{
259259
let res = unsafe { libc::setrlimit(resource as c_int, &new_rlim as *const rlimit) };

src/sys/signal.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::str::FromStr;
1111
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
1212
use std::os::unix::io::RawFd;
1313
use std::ptr;
14+
use cfg_if::cfg_if;
1415

1516
#[cfg(not(any(target_os = "openbsd", target_os = "redox")))]
1617
#[cfg(any(feature = "aio", feature = "signal"))]
@@ -420,10 +421,15 @@ pub const SIGPOLL : Signal = SIGIO;
420421
/// Alias for [`SIGSYS`]
421422
pub const SIGUNUSED : Signal = SIGSYS;
422423

423-
#[cfg(not(target_os = "redox"))]
424-
type SaFlags_t = libc::c_int;
425-
#[cfg(target_os = "redox")]
426-
type SaFlags_t = libc::c_ulong;
424+
cfg_if! {
425+
if #[cfg(target_os = "redox")] {
426+
type SaFlags_t = libc::c_ulong;
427+
} else if #[cfg(target_env = "uclibc")] {
428+
type SaFlags_t = libc::c_ulong;
429+
} else {
430+
type SaFlags_t = libc::c_int;
431+
}
432+
}
427433
}
428434

429435
#[cfg(feature = "signal")]
@@ -1046,6 +1052,8 @@ mod sigevent {
10461052
SigevNotify::SigevThreadId{..} => libc::SIGEV_THREAD_ID,
10471053
#[cfg(all(target_os = "linux", target_env = "gnu", not(target_arch = "mips")))]
10481054
SigevNotify::SigevThreadId{..} => libc::SIGEV_THREAD_ID,
1055+
#[cfg(all(target_os = "linux", target_env = "uclibc"))]
1056+
SigevNotify::SigevThreadId{..} => libc::SIGEV_THREAD_ID,
10491057
#[cfg(any(all(target_os = "linux", target_env = "musl"), target_arch = "mips"))]
10501058
SigevNotify::SigevThreadId{..} => 4 // No SIGEV_THREAD_ID defined
10511059
};

src/sys/socket/addr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ pub enum AddressFamily {
120120
#[cfg(any(target_os = "android", target_os = "linux"))]
121121
#[cfg_attr(docsrs, doc(cfg(all())))]
122122
Llc = libc::AF_LLC,
123-
#[cfg(target_os = "linux")]
123+
#[cfg(all(target_os = "linux", not(target_env = "uclibc")))]
124124
#[cfg_attr(docsrs, doc(cfg(all())))]
125125
Ib = libc::AF_IB,
126-
#[cfg(target_os = "linux")]
126+
#[cfg(all(target_os = "linux", not(target_env = "uclibc")))]
127127
#[cfg_attr(docsrs, doc(cfg(all())))]
128128
Mpls = libc::AF_MPLS,
129129
#[cfg(any(target_os = "android", target_os = "linux"))]

src/sys/statfs.rs

+29-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ type fs_type_t = libc::c_ulong;
3131
type fs_type_t = libc::c_uint;
3232
#[cfg(all(target_os = "linux", target_env = "musl"))]
3333
type fs_type_t = libc::c_ulong;
34-
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))))]
34+
#[cfg(all(target_os = "linux", target_env = "uclibc"))]
35+
type fs_type_t = libc::c_int;
36+
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl", target_env = "uclibc"))))]
3537
type fs_type_t = libc::__fsword_t;
3638

3739
/// Describes the file system type as known by the operating system.
@@ -71,7 +73,7 @@ pub const EXT3_SUPER_MAGIC: FsType = FsType(libc::EXT3_SUPER_MAGIC as fs_type_t)
7173
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
7274
#[allow(missing_docs)]
7375
pub const EXT4_SUPER_MAGIC: FsType = FsType(libc::EXT4_SUPER_MAGIC as fs_type_t);
74-
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
76+
#[cfg(all(target_os = "linux", not(any(target_env = "musl", target_env = "uclibc"))))]
7577
#[allow(missing_docs)]
7678
pub const FUSE_SUPER_MAGIC: FsType = FsType(libc::FUSE_SUPER_MAGIC as fs_type_t);
7779
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
@@ -192,12 +194,19 @@ impl Statfs {
192194
}
193195

194196
/// Optimal transfer block size
195-
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))))]
197+
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl", target_env = "uclibc"))))]
196198
#[cfg_attr(docsrs, doc(cfg(all())))]
197199
pub fn optimal_transfer_size(&self) -> libc::__fsword_t {
198200
self.0.f_bsize
199201
}
200202

203+
/// Optimal transfer block size
204+
#[cfg(all(target_os = "linux", target_env = "uclibc"))]
205+
#[cfg_attr(docsrs, doc(cfg(all())))]
206+
pub fn optimal_transfer_size(&self) -> libc::c_int {
207+
self.0.f_bsize
208+
}
209+
201210
/// Optimal transfer block size
202211
#[cfg(target_os = "dragonfly")]
203212
#[cfg_attr(docsrs, doc(cfg(all())))]
@@ -237,7 +246,15 @@ impl Statfs {
237246

238247
/// Size of a block
239248
// f_bsize on linux: https://github.com/torvalds/linux/blob/master/fs/nfs/super.c#L471
240-
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))))]
249+
#[cfg(all(target_os = "linux", target_env = "uclibc"))]
250+
#[cfg_attr(docsrs, doc(cfg(all())))]
251+
pub fn block_size(&self) -> libc::c_int {
252+
self.0.f_bsize
253+
}
254+
255+
/// Size of a block
256+
// f_bsize on linux: https://github.com/torvalds/linux/blob/master/fs/nfs/super.c#L471
257+
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl", target_env = "uclibc"))))]
241258
#[cfg_attr(docsrs, doc(cfg(all())))]
242259
pub fn block_size(&self) -> libc::__fsword_t {
243260
self.0.f_bsize
@@ -286,7 +303,14 @@ impl Statfs {
286303
}
287304

288305
/// Maximum length of filenames
289-
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))))]
306+
#[cfg(all(target_os = "linux", target_env = "uclibc"))]
307+
#[cfg_attr(docsrs, doc(cfg(all())))]
308+
pub fn maximum_name_length(&self) -> libc::c_int {
309+
self.0.f_namelen
310+
}
311+
312+
/// Maximum length of filenames
313+
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl", target_env = "uclibc"))))]
290314
#[cfg_attr(docsrs, doc(cfg(all())))]
291315
pub fn maximum_name_length(&self) -> libc::__fsword_t {
292316
self.0.f_namelen

src/sys/uio.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ pub fn readv(fd: RawFd, iov: &mut [IoVec<&mut [u8]>]) -> Result<usize> {
3434
#[cfg_attr(docsrs, doc(cfg(all())))]
3535
pub fn pwritev(fd: RawFd, iov: &[IoVec<&[u8]>],
3636
offset: off_t) -> Result<usize> {
37+
#[cfg(target_env = "uclibc")]
38+
let offset = offset as libc::off64_t; // uclibc doesn't use off_t
3739
let res = unsafe {
3840
libc::pwritev(fd, iov.as_ptr() as *const libc::iovec, iov.len() as c_int, offset)
3941
};
@@ -52,6 +54,8 @@ pub fn pwritev(fd: RawFd, iov: &[IoVec<&[u8]>],
5254
#[cfg_attr(docsrs, doc(cfg(all())))]
5355
pub fn preadv(fd: RawFd, iov: &[IoVec<&mut [u8]>],
5456
offset: off_t) -> Result<usize> {
57+
#[cfg(target_env = "uclibc")]
58+
let offset = offset as libc::off64_t; // uclibc doesn't use off_t
5559
let res = unsafe {
5660
libc::preadv(fd, iov.as_ptr() as *const libc::iovec, iov.len() as c_int, offset)
5761
};
@@ -127,7 +131,7 @@ feature! {
127131
/// [ptrace]: ../ptrace/index.html
128132
/// [`IoVec`]: struct.IoVec.html
129133
/// [`RemoteIoVec`]: struct.RemoteIoVec.html
130-
#[cfg(target_os = "linux")]
134+
#[cfg(all(target_os = "linux", not(target_env = "uclibc")))]
131135
pub fn process_vm_writev(
132136
pid: crate::unistd::Pid,
133137
local_iov: &[IoVec<&[u8]>],
@@ -162,7 +166,7 @@ pub fn process_vm_writev(
162166
/// [`ptrace`]: ../ptrace/index.html
163167
/// [`IoVec`]: struct.IoVec.html
164168
/// [`RemoteIoVec`]: struct.RemoteIoVec.html
165-
#[cfg(any(target_os = "linux"))]
169+
#[cfg(all(target_os = "linux", not(target_env = "uclibc")))]
166170
pub fn process_vm_readv(
167171
pid: crate::unistd::Pid,
168172
local_iov: &[IoVec<&mut [u8]>],

src/time.rs

-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ pub fn clock_gettime(clock_id: ClockId) -> Result<TimeSpec> {
237237
#[cfg(not(any(
238238
target_os = "macos",
239239
target_os = "ios",
240-
target_env = "uclibc",
241240
target_os = "redox",
242241
target_os = "hermit",
243242
)))]

test/sys/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod test_signal;
77
// cases on DragonFly.
88
#[cfg(any(target_os = "freebsd",
99
target_os = "ios",
10-
target_os = "linux",
10+
all(target_os = "linux", not(target_env = "uclibc")),
1111
target_os = "macos",
1212
target_os = "netbsd"))]
1313
mod test_aio;
@@ -28,6 +28,7 @@ mod test_termios;
2828
#[cfg(not(any(target_os = "redox", target_os = "fuchsia")))]
2929
mod test_ioctl;
3030
mod test_wait;
31+
#[cfg(not(target_env = "uclibc"))]
3132
mod test_uio;
3233

3334
#[cfg(any(target_os = "android", target_os = "linux"))]

test/sys/test_aio_drop.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#[test]
55
#[should_panic(expected = "Dropped an in-progress AioCb")]
66
#[cfg(all(not(target_env = "musl"),
7+
not(target_env = "uclibc"),
78
any(target_os = "linux",
89
target_os = "ios",
910
target_os = "macos",

test/test_fcntl.rs

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ use std::os::unix::fs;
3030

3131
#[test]
3232
#[cfg(not(target_os = "redox"))]
33+
// QEMU does not handle openat well enough to satisfy this test
34+
// https://gitlab.com/qemu-project/qemu/-/issues/829
35+
#[cfg_attr(qemu, ignore)]
3336
fn test_openat() {
3437
const CONTENTS: &[u8] = b"abcd";
3538
let mut tmp = NamedTempFile::new().unwrap();
@@ -357,6 +360,7 @@ mod linux_android {
357360

358361
#[test]
359362
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
363+
#[cfg_attr(target_env = "uclibc", ignore)] // uclibc doesn't support OFD locks, but the test should still compile
360364
fn test_ofd_write_lock() {
361365
use nix::sys::stat::fstat;
362366
use std::mem;
@@ -394,6 +398,7 @@ mod linux_android {
394398

395399
#[test]
396400
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
401+
#[cfg_attr(target_env = "uclibc", ignore)] // uclibc doesn't support OFD locks, but the test should still compile
397402
fn test_ofd_read_lock() {
398403
use nix::sys::stat::fstat;
399404
use std::mem;

0 commit comments

Comments
 (0)