Skip to content

Commit 19f3be3

Browse files
committed
Auto merge of #578 - cactorium:master, r=alexcrichton
Steps towards support for musl-unknown-linux-uclibc Hello! I've been working towards resolving #361 , this PR compiles successfully with a newish compiler (with some minor fixes in `gcc`, `ctest`), and all the tests pass for `libc-ctest`. Basically most of the undefined functions, constants, and structs were just removed from the ctest, and then any constants that weren't correct were fixed. Would it make more sense to conditionally remove them from libc? I wasn't sure when it was appropriate to skip the test for it instead of removing the function/constants, so I just removed all the tests for now because that was a little easier than hunting them down. I'm also guessing the way some of the constants were conditionally set wasn't the correct style, would you guys have any advice on how to do it more correctly? Lemme know how it looks!
2 parents c8c5d64 + c0bec43 commit 19f3be3

File tree

6 files changed

+2757
-8
lines changed

6 files changed

+2757
-8
lines changed

libc-test/build.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ fn main() {
1414
let android = target.contains("android");
1515
let apple = target.contains("apple");
1616
let musl = target.contains("musl");
17+
let uclibc = target.contains("uclibc");
1718
let freebsd = target.contains("freebsd");
1819
let dragonfly = target.contains("dragonfly");
1920
let mips = target.contains("mips");
@@ -126,8 +127,10 @@ fn main() {
126127

127128
if !musl {
128129
cfg.header("sys/sysctl.h");
130+
}
131+
if !musl && !uclibc {
129132

130-
if !netbsd && !openbsd {
133+
if !netbsd && !openbsd && !uclibc {
131134
cfg.header("execinfo.h");
132135
cfg.header("xlocale.h");
133136
}
@@ -165,7 +168,10 @@ fn main() {
165168
cfg.header("mqueue.h");
166169
cfg.header("ucontext.h");
167170
cfg.header("sys/signalfd.h");
168-
cfg.header("sys/xattr.h");
171+
if !uclibc {
172+
// optionally included in uclibc
173+
cfg.header("sys/xattr.h");
174+
}
169175
cfg.header("sys/ipc.h");
170176
cfg.header("sys/msg.h");
171177
cfg.header("sys/shm.h");
@@ -185,7 +191,9 @@ fn main() {
185191
cfg.header("sys/sendfile.h");
186192
cfg.header("sys/vfs.h");
187193
cfg.header("sys/syscall.h");
188-
cfg.header("sys/sysinfo.h");
194+
if !uclibc {
195+
cfg.header("sys/sysinfo.h");
196+
}
189197
cfg.header("sys/reboot.h");
190198
if !musl {
191199
cfg.header("linux/netlink.h");
@@ -227,7 +235,9 @@ fn main() {
227235
}
228236

229237
if linux || freebsd || dragonfly || netbsd || apple {
230-
cfg.header("aio.h");
238+
if !uclibc {
239+
cfg.header("aio.h");
240+
}
231241
}
232242

233243
cfg.type_name(move |ty, is_struct| {
@@ -389,6 +399,11 @@ fn main() {
389399
"KERN_KDENABLE_BG_TRACE" if apple => true,
390400
"KERN_KDDISABLE_BG_TRACE" if apple => true,
391401

402+
// These are either unimplemented or optionally built into uClibc
403+
"LC_CTYPE_MASK" | "LC_NUMERIC_MASK" | "LC_TIME_MASK" | "LC_COLLATE_MASK" | "LC_MONETARY_MASK" | "LC_MESSAGES_MASK" |
404+
"MADV_MERGEABLE" | "MADV_UNMERGEABLE" | "MADV_HWPOISON" | "IPV6_ADD_MEMBERSHIP" | "IPV6_DROP_MEMBERSHIP" | "IPV6_MULTICAST_LOOP" | "IPV6_V6ONLY" |
405+
"MAP_STACK" | "RTLD_DEEPBIND" | "SOL_IPV6" | "SOL_ICMPV6" if uclibc => true,
406+
392407
_ => false,
393408
}
394409
});
@@ -475,6 +490,17 @@ fn main() {
475490
// it's in a header file?
476491
"endpwent" if android => true,
477492

493+
494+
// These are either unimplemented or optionally built into uClibc
495+
// or "sysinfo", where it's defined but the structs in linux/sysinfo.h and sys/sysinfo.h
496+
// clash so it can't be tested
497+
"getxattr" | "lgetxattr" | "fgetxattr" | "setxattr" | "lsetxattr" | "fsetxattr" |
498+
"listxattr" | "llistxattr" | "flistxattr" | "removexattr" | "lremovexattr" |
499+
"fremovexattr" |
500+
"backtrace" |
501+
"sysinfo" | "newlocale" | "duplocale" | "freelocale" | "uselocale" |
502+
"nl_langinfo_l" | "wcslen" | "wcstombs" if uclibc => true,
503+
478504
// Apparently res_init exists on Android, but isn't defined in a header:
479505
// https://mail.gnome.org/archives/commits-list/2013-May/msg01329.html
480506
"res_init" if android => true,

src/unix/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -854,10 +854,13 @@ extern {
854854
}
855855

856856
cfg_if! {
857-
if #[cfg(any(target_os = "linux",
858-
target_os = "android",
859-
target_os = "emscripten",
860-
target_os = "fuchsia"))] {
857+
if #[cfg(target_env = "uclibc")] {
858+
mod uclibc;
859+
pub use self::uclibc::*;
860+
} else if #[cfg(any(target_os = "linux",
861+
target_os = "android",
862+
target_os = "emscripten",
863+
target_os = "fuchsia"))] {
861864
mod notbsd;
862865
pub use self::notbsd::*;
863866
} else if #[cfg(any(target_os = "macos",

src/unix/uclibc/mips/mips32.rs

Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
pub type c_char = i8;
2+
pub type c_long = i32;
3+
pub type c_ulong = u32;
4+
pub type clock_t = i32;
5+
pub type time_t = i32;
6+
pub type suseconds_t = i32;
7+
pub type wchar_t = i32;
8+
pub type off_t = i32;
9+
pub type ino_t = u32;
10+
pub type blkcnt_t = i32;
11+
pub type blksize_t = i32;
12+
pub type nlink_t = u32;
13+
pub type fsblkcnt_t = ::c_ulong;
14+
pub type fsfilcnt_t = ::c_ulong;
15+
pub type rlim_t = c_ulong;
16+
17+
s! {
18+
pub struct stat {
19+
pub st_dev: ::dev_t,
20+
st_pad1: [::c_long; 2],
21+
pub st_ino: ::ino_t,
22+
pub st_mode: ::mode_t,
23+
pub st_nlink: ::nlink_t,
24+
pub st_uid: ::uid_t,
25+
pub st_gid: ::gid_t,
26+
pub st_rdev: ::dev_t,
27+
pub st_pad2: [::c_long; 1],
28+
pub st_size: ::off_t,
29+
st_pad3: ::c_long,
30+
pub st_atime: ::time_t,
31+
pub st_atime_nsec: ::c_long,
32+
pub st_mtime: ::time_t,
33+
pub st_mtime_nsec: ::c_long,
34+
pub st_ctime: ::time_t,
35+
pub st_ctime_nsec: ::c_long,
36+
pub st_blksize: ::blksize_t,
37+
pub st_blocks: ::blkcnt_t,
38+
st_pad5: [::c_long; 14],
39+
}
40+
41+
pub struct stat64 {
42+
pub st_dev: ::dev_t,
43+
st_pad1: [::c_long; 2],
44+
pub st_ino: ::ino64_t,
45+
pub st_mode: ::mode_t,
46+
pub st_nlink: ::nlink_t,
47+
pub st_uid: ::uid_t,
48+
pub st_gid: ::gid_t,
49+
pub st_rdev: ::dev_t,
50+
st_pad2: [::c_long; 2],
51+
pub st_size: ::off64_t,
52+
pub st_atime: ::time_t,
53+
pub st_atime_nsec: ::c_long,
54+
pub st_mtime: ::time_t,
55+
pub st_mtime_nsec: ::c_long,
56+
pub st_ctime: ::time_t,
57+
pub st_ctime_nsec: ::c_long,
58+
pub st_blksize: ::blksize_t,
59+
st_pad3: ::c_long,
60+
pub st_blocks: ::blkcnt64_t,
61+
st_pad5: [::c_long; 14],
62+
}
63+
64+
pub struct pthread_attr_t {
65+
__size: [u32; 9]
66+
}
67+
68+
pub struct sigaction {
69+
pub sa_flags: ::c_uint,
70+
pub sa_sigaction: ::sighandler_t,
71+
pub sa_mask: sigset_t,
72+
_restorer: *mut ::c_void,
73+
}
74+
75+
pub struct stack_t {
76+
pub ss_sp: *mut ::c_void,
77+
pub ss_size: ::size_t,
78+
pub ss_flags: ::c_int,
79+
}
80+
81+
pub struct sigset_t {
82+
__val: [::c_ulong; 4],
83+
}
84+
85+
pub struct siginfo_t {
86+
pub si_signo: ::c_int,
87+
pub si_code: ::c_int,
88+
pub si_errno: ::c_int,
89+
pub _pad: [::c_int; 29],
90+
}
91+
92+
pub struct glob64_t {
93+
pub gl_pathc: ::size_t,
94+
pub gl_pathv: *mut *mut ::c_char,
95+
pub gl_offs: ::size_t,
96+
pub gl_flags: ::c_int,
97+
98+
__unused1: *mut ::c_void,
99+
__unused2: *mut ::c_void,
100+
__unused3: *mut ::c_void,
101+
__unused4: *mut ::c_void,
102+
__unused5: *mut ::c_void,
103+
}
104+
105+
pub struct ipc_perm {
106+
pub __key: ::key_t,
107+
pub uid: ::uid_t,
108+
pub gid: ::gid_t,
109+
pub cuid: ::uid_t,
110+
pub cgid: ::gid_t,
111+
pub mode: ::c_uint,
112+
pub __seq: ::c_ushort,
113+
__pad1: ::c_ushort,
114+
__unused1: ::c_ulong,
115+
__unused2: ::c_ulong
116+
}
117+
118+
pub struct shmid_ds {
119+
pub shm_perm: ::ipc_perm,
120+
pub shm_segsz: ::size_t,
121+
pub shm_atime: ::time_t,
122+
pub shm_dtime: ::time_t,
123+
pub shm_ctime: ::time_t,
124+
pub shm_cpid: ::pid_t,
125+
pub shm_lpid: ::pid_t,
126+
pub shm_nattch: ::shmatt_t,
127+
__unused4: ::c_ulong,
128+
__unused5: ::c_ulong
129+
}
130+
131+
pub struct msqid_ds {
132+
pub msg_perm: ::ipc_perm,
133+
#[cfg(target_endian = "big")]
134+
__glibc_reserved1: ::c_ulong,
135+
pub msg_stime: ::time_t,
136+
#[cfg(target_endian = "little")]
137+
__glibc_reserved1: ::c_ulong,
138+
#[cfg(target_endian = "big")]
139+
__glibc_reserved2: ::c_ulong,
140+
pub msg_rtime: ::time_t,
141+
#[cfg(target_endian = "little")]
142+
__glibc_reserved2: ::c_ulong,
143+
#[cfg(target_endian = "big")]
144+
__glibc_reserved3: ::c_ulong,
145+
pub msg_ctime: ::time_t,
146+
#[cfg(target_endian = "little")]
147+
__glibc_reserved3: ::c_ulong,
148+
__msg_cbytes: ::c_ulong,
149+
pub msg_qnum: ::msgqnum_t,
150+
pub msg_qbytes: ::msglen_t,
151+
pub msg_lspid: ::pid_t,
152+
pub msg_lrpid: ::pid_t,
153+
__glibc_reserved4: ::c_ulong,
154+
__glibc_reserved5: ::c_ulong,
155+
}
156+
157+
pub struct statfs {
158+
pub f_type: ::c_long,
159+
pub f_bsize: ::c_long,
160+
pub f_frsize: ::c_long,
161+
pub f_blocks: ::fsblkcnt_t,
162+
pub f_bfree: ::fsblkcnt_t,
163+
pub f_files: ::fsblkcnt_t,
164+
pub f_ffree: ::fsblkcnt_t,
165+
pub f_bavail: ::fsblkcnt_t,
166+
pub f_fsid: ::fsid_t,
167+
168+
pub f_namelen: ::c_long,
169+
f_spare: [::c_long; 6],
170+
}
171+
172+
pub struct msghdr {
173+
pub msg_name: *mut ::c_void,
174+
pub msg_namelen: ::socklen_t,
175+
pub msg_iov: *mut ::iovec,
176+
pub msg_iovlen: ::c_int,
177+
pub msg_control: *mut ::c_void,
178+
pub msg_controllen: ::size_t,
179+
pub msg_flags: ::c_int,
180+
}
181+
182+
pub struct cmsghdr {
183+
pub cmsg_len: ::size_t,
184+
pub cmsg_level: ::c_int,
185+
pub cmsg_type: ::c_int,
186+
}
187+
188+
pub struct termios {
189+
pub c_iflag: ::tcflag_t,
190+
pub c_oflag: ::tcflag_t,
191+
pub c_cflag: ::tcflag_t,
192+
pub c_lflag: ::tcflag_t,
193+
pub c_line: ::cc_t,
194+
pub c_cc: [::cc_t; ::NCCS],
195+
}
196+
197+
pub struct flock {
198+
pub l_type: ::c_short,
199+
pub l_whence: ::c_short,
200+
pub l_start: ::off_t,
201+
pub l_len: ::off_t,
202+
pub l_sysid: ::c_long,
203+
pub l_pid: ::pid_t,
204+
pad: [::c_long; 4],
205+
}
206+
207+
pub struct sysinfo {
208+
pub uptime: ::c_long,
209+
pub loads: [::c_ulong; 3],
210+
pub totalram: ::c_ulong,
211+
pub freeram: ::c_ulong,
212+
pub sharedram: ::c_ulong,
213+
pub bufferram: ::c_ulong,
214+
pub totalswap: ::c_ulong,
215+
pub freeswap: ::c_ulong,
216+
pub procs: ::c_ushort,
217+
pub pad: ::c_ushort,
218+
pub totalhigh: ::c_ulong,
219+
pub freehigh: ::c_ulong,
220+
pub mem_unit: ::c_uint,
221+
pub _f: [::c_char; 8],
222+
}
223+
224+
// FIXME this is actually a union
225+
pub struct sem_t {
226+
#[cfg(target_pointer_width = "32")]
227+
__size: [::c_char; 16],
228+
#[cfg(target_pointer_width = "64")]
229+
__size: [::c_char; 32],
230+
__align: [::c_long; 0],
231+
}
232+
}
233+
234+
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
235+
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24;
236+
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32;
237+
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
238+
239+
pub const RLIM_INFINITY: ::rlim_t = 0x7fffffff;
240+
241+
pub const SYS_gettid: ::c_long = 4222; // Valid for O32
242+
243+
#[link(name = "util")]
244+
extern {
245+
pub fn sysctl(name: *mut ::c_int,
246+
namelen: ::c_int,
247+
oldp: *mut ::c_void,
248+
oldlenp: *mut ::size_t,
249+
newp: *mut ::c_void,
250+
newlen: ::size_t)
251+
-> ::c_int;
252+
pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int;
253+
pub fn backtrace(buf: *mut *mut ::c_void,
254+
sz: ::c_int) -> ::c_int;
255+
pub fn glob64(pattern: *const ::c_char,
256+
flags: ::c_int,
257+
errfunc: ::dox::Option<extern fn(epath: *const ::c_char,
258+
errno: ::c_int)
259+
-> ::c_int>,
260+
pglob: *mut glob64_t) -> ::c_int;
261+
pub fn globfree64(pglob: *mut glob64_t);
262+
pub fn ptrace(request: ::c_uint, ...) -> ::c_long;
263+
pub fn pthread_attr_getaffinity_np(attr: *const ::pthread_attr_t,
264+
cpusetsize: ::size_t,
265+
cpuset: *mut ::cpu_set_t) -> ::c_int;
266+
pub fn pthread_attr_setaffinity_np(attr: *mut ::pthread_attr_t,
267+
cpusetsize: ::size_t,
268+
cpuset: *const ::cpu_set_t) -> ::c_int;
269+
}

0 commit comments

Comments
 (0)