Fix android

This commit is contained in:
Alex Crichton 2015-09-17 15:09:02 -07:00
parent cd9b33e32b
commit 1ff961010b
6 changed files with 129 additions and 100 deletions

View File

@ -9,18 +9,19 @@ fn main() {
let windows = target.contains("windows");
let mingw = target.contains("windows-gnu");
let linux = target.contains("unknown-linux");
let android = target.contains("android");
let mut cfg = ctest::TestGenerator::new();
// Pull in extra goodies on linux/mingw
if target.contains("unknown-linux-gnu") {
cfg.define("_GNU_SOURCE", None);
} else if target.contains("windows") {
} else if windows {
cfg.define("_WIN32_WINNT", Some("0x8000"));
}
// Android doesn't actually have in_port_t but it's much easier if we
// provide one for us to test against
if target.contains("android") {
if android {
cfg.define("in_port_t", Some("uint16_t"));
}
@ -39,13 +40,12 @@ fn main() {
if target.contains("apple-darwin") {
cfg.header("mach-o/dyld.h");
cfg.header("mach/mach_time.h");
} else if target.contains("unknown-linux") ||
target.contains("android") {
} else if linux || android {
cfg.header("linux/if_packet.h");
cfg.header("net/ethernet.h");
}
if target.contains("windows") {
if windows {
cfg.header("winsock2.h"); // must be before windows.h
cfg.header("direct.h");
@ -67,6 +67,7 @@ fn main() {
cfg.header("netinet/ip.h");
cfg.header("netinet/tcp.h");
cfg.header("pthread.h");
cfg.header("dlfcn.h");
cfg.header("signal.h");
cfg.header("string.h");
cfg.header("sys/file.h");
@ -81,13 +82,15 @@ fn main() {
cfg.header("utime.h");
cfg.header("pwd.h");
cfg.header("grp.h");
cfg.header("malloc.h");
if target.contains("android") {
if android {
cfg.header("arpa/inet.h");
} else {
cfg.header("glob.h");
cfg.header("ifaddrs.h");
cfg.header("sys/sysctl.h");
cfg.header("execinfo.h");
}
}
@ -193,9 +196,13 @@ fn main() {
"getrlimit" | // non-int in 1st arg
"setrlimit" | // non-int in 1st arg
"gettimeofday" | // typed 2nd arg on linux
"strerror_r" if linux => true, // actually xpg-something-or-other
// typed 2nd arg on linux and android
"gettimeofday" if linux || android => true,
"dlerror" if android => true, // const-ness is added
_ => false,
}
});

View File

@ -150,6 +150,7 @@ extern {
base: c_int) -> c_ulong;
pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void;
pub fn malloc(size: size_t) -> *mut c_void;
pub fn memalign(align: size_t, size: size_t) -> *mut c_void;
pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
pub fn free(p: *mut c_void);
pub fn exit(status: c_int) -> !;

View File

@ -297,8 +297,8 @@ extern {
pub fn ftruncate(fd: c_int, length: off_t) -> c_int;
pub fn signal(signum: c_int,
handler: sighandler_t) -> sighandler_t;
#[cfg_attr(target_os = "android", link_name = "bsd_signal")]
pub fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t;
pub fn getrlimit(resource: c_int, rlim: *mut rlimit) -> c_int;
pub fn setrlimit(resource: c_int, rlim: *const rlimit) -> c_int;
@ -310,70 +310,7 @@ extern {
-> *mut ::c_char;
pub fn flock(fd: c_int, operation: c_int) -> c_int;
}
// TODO: get rid of this #[cfg(not(...))]
#[cfg(not(target_os = "android"))]
extern {
pub fn getifaddrs(ifap: *mut *mut ifaddrs) -> c_int;
pub fn freeifaddrs(ifa: *mut ifaddrs);
pub fn glob(pattern: *const c_char,
flags: c_int,
errfunc: ::dox::Option<extern "C" fn(epath: *const c_char,
errno: c_int) -> c_int>,
pglob: *mut glob_t) -> c_int;
pub fn globfree(pglob: *mut glob_t);
pub fn posix_madvise(addr: *mut ::c_void, len: size_t, advice: c_int)
-> c_int;
pub fn shm_unlink(name: *const c_char) -> c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
link_name = "seekdir$INODE64")]
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "seekdir$INODE64$UNIX2003")]
pub fn seekdir(dirp: *mut ::DIR, loc: c_long);
#[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
link_name = "telldir$INODE64")]
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "telldir$INODE64$UNIX2003")]
pub fn telldir(dirp: *mut ::DIR) -> c_long;
pub fn getsid(pid: pid_t) -> pid_t;
pub fn madvise(addr: *mut ::c_void, len: size_t, advice: c_int)
-> c_int;
pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "putenv$UNIX2003")]
pub fn putenv(string: *mut c_char) -> c_int;
pub fn readlink(path: *const c_char,
buf: *mut c_char,
bufsz: size_t)
-> ssize_t;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "msync$UNIX2003")]
pub fn msync(addr: *mut ::c_void, len: size_t, flags: c_int) -> c_int;
pub fn sysconf(name: c_int) -> c_long;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "usleep$UNIX2003")]
pub fn usleep(secs: c_uint) -> c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "recvfrom$UNIX2003")]
pub fn recvfrom(socket: c_int, buf: *mut ::c_void, len: size_t,
flags: c_int, addr: *mut sockaddr,
addrlen: *mut socklen_t) -> ssize_t;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "send$UNIX2003")]
pub fn send(socket: c_int, buf: *const ::c_void, len: size_t,
flags: c_int) -> ssize_t;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "recv$UNIX2003")]
pub fn recv(socket: c_int, buf: *mut ::c_void, len: size_t,
flags: c_int) -> ssize_t;
pub fn mkfifo(path: *const c_char, mode: mode_t) -> c_int;
pub fn gettimeofday(tp: *mut ::timeval,
tz: *mut ::c_void) -> ::c_int;
@ -443,19 +380,94 @@ extern {
oldact: *mut sigaction) -> ::c_int;
pub fn sigaltstack(ss: *const sigaltstack,
oss: *mut sigaltstack) -> ::c_int;
pub fn sigemptyset(set: *mut sigset_t) -> ::c_int;
pub fn getpwuid_r(uid: ::uid_t,
pwd: *mut passwd,
buf: *mut ::c_char,
buflen: ::size_t,
result: *mut *mut passwd) -> ::c_int;
pub fn utimes(filename: *const ::c_char,
times: *const ::timeval) -> ::c_int;
pub fn gai_strerror(errcode: ::c_int) -> *const ::c_char;
pub fn setgroups(ngroups: ::size_t,
ptr: *const ::gid_t) -> ::c_int;
pub fn dlopen(filename: *const ::c_char,
flag: ::c_int) -> *mut ::c_void;
pub fn dlerror() -> *mut ::c_char;
pub fn dlsym(handle: *mut ::c_void,
symbol: *const ::c_char) -> *mut ::c_void;
pub fn dlclose(handle: *mut ::c_void) -> ::c_int;
}
// TODO: get rid of this #[cfg(not(...))]
#[cfg(not(target_os = "android"))]
extern {
pub fn getifaddrs(ifap: *mut *mut ifaddrs) -> c_int;
pub fn freeifaddrs(ifa: *mut ifaddrs);
pub fn glob(pattern: *const c_char,
flags: c_int,
errfunc: ::dox::Option<extern "C" fn(epath: *const c_char,
errno: c_int) -> c_int>,
pglob: *mut glob_t) -> c_int;
pub fn globfree(pglob: *mut glob_t);
pub fn posix_madvise(addr: *mut ::c_void, len: size_t, advice: c_int)
-> c_int;
pub fn shm_unlink(name: *const c_char) -> c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
link_name = "seekdir$INODE64")]
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "seekdir$INODE64$UNIX2003")]
pub fn seekdir(dirp: *mut ::DIR, loc: c_long);
#[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
link_name = "telldir$INODE64")]
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "telldir$INODE64$UNIX2003")]
pub fn telldir(dirp: *mut ::DIR) -> c_long;
pub fn getsid(pid: pid_t) -> pid_t;
pub fn madvise(addr: *mut ::c_void, len: size_t, advice: c_int)
-> c_int;
pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "putenv$UNIX2003")]
pub fn putenv(string: *mut c_char) -> c_int;
pub fn readlink(path: *const c_char,
buf: *mut c_char,
bufsz: size_t)
-> ssize_t;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "msync$UNIX2003")]
pub fn msync(addr: *mut ::c_void, len: size_t, flags: c_int) -> c_int;
pub fn sysconf(name: c_int) -> c_long;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "usleep$UNIX2003")]
pub fn usleep(secs: c_uint) -> c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "recvfrom$UNIX2003")]
pub fn recvfrom(socket: c_int, buf: *mut ::c_void, len: size_t,
flags: c_int, addr: *mut sockaddr,
addrlen: *mut socklen_t) -> ssize_t;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "send$UNIX2003")]
pub fn send(socket: c_int, buf: *const ::c_void, len: size_t,
flags: c_int) -> ssize_t;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "recv$UNIX2003")]
pub fn recv(socket: c_int, buf: *mut ::c_void, len: size_t,
flags: c_int) -> ssize_t;
pub fn mkfifo(path: *const c_char, mode: mode_t) -> c_int;
pub fn getpwuid_r(uid: ::uid_t,
pwd: *mut passwd,
buf: *mut ::c_char,
buflen: ::size_t,
result: *mut *mut passwd) -> ::c_int;
pub fn backtrace(buf: *mut *mut ::c_void,
sz: ::c_int) -> ::c_int;
pub fn posix_memalign(memptr: *mut *mut ::c_void,
align: ::size_t,
size: ::size_t) -> ::c_int;
pub fn sigemptyset(set: *mut sigset_t) -> ::c_int;
}
cfg_if! {

View File

@ -0,0 +1,8 @@
s! {
pub struct sigaction {
pub sa_sigaction: ::sighandler_t,
pub sa_mask: ::sigset_t,
pub sa_flags: ::c_ulong,
pub sa_restorer: Option<extern fn()>,
}
}

View File

@ -0,0 +1,8 @@
s! {
pub struct sigaction {
pub sa_flags: ::c_uint,
pub sa_sigaction: sighandler_t,
pub sa_mask: sigset_t,
_restorer: *mut ::c_void,
}
}

View File

@ -91,27 +91,6 @@ s! {
pub si_errno: ::c_int,
pub si_code: ::c_int,
pub _pad: [::c_int; 29],
_align: [u64; 0],
}
}
#[cfg(target_pointer_width = "32")]
s!{
pub struct sigaction {
pub sa_sigaction: sighandler_t,
pub sa_flags: libc::c_ulong,
_restorer: *mut libc::c_void,
pub sa_mask: sigset_t,
}
}
#[cfg(target_pointer_width = "64")]
s!{
pub struct sigaction {
pub sa_flags: libc::c_uint,
pub sa_sigaction: sighandler_t,
pub sa_mask: sigset_t,
_restorer: *mut libc::c_void,
}
}
@ -230,3 +209,17 @@ extern {
pub fn recv(socket: ::c_int, buf: *mut ::c_void, len: ::size_t,
flags: ::c_uint) -> ::ssize_t;
}
cfg_if! {
if #[cfg(target_pointer_width = "32")] {
mod b32;
pub use self::b32::*;
} else if #[cfg(target_pointer_width = "64")] {
mod b64;
pub use self::b64::*;
} else {
// ...
}
}