Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add and fix tests for {i686, aarch64}-linux-android targets #538

Merged
merged 11 commits into from
Mar 1, 2017
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ matrix:
- os: linux
env: TARGET=arm-linux-androideabi
rust: stable
- os: linux
env: TARGET=aarch64-linux-android
rust: stable
- os: linux
env: TARGET=i686-linux-android
rust: stable
- os: linux
env: TARGET=x86_64-unknown-linux-musl
rust: stable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,24 @@ set -ex

curl -O https://dl.google.com/android/repository/android-ndk-r13b-linux-x86_64.zip
unzip -q android-ndk-r13b-linux-x86_64.zip

case "$1" in
aarch64)
arch=arm64
;;

i686)
arch=x86
;;

*)
arch=$1
;;
esac;

android-ndk-r13b/build/tools/make_standalone_toolchain.py \
--install-dir /android/ndk-arm \
--arch arm \
--install-dir /android/ndk-$1 \
--arch $arch \
--api 24

rm -rf ./android-ndk-r13b-linux-x86_64.zip ./android-ndk-r13b
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,35 @@ set -ex
# which apparently magically accepts the licenses.

mkdir sdk
curl https://dl.google.com/android/android-sdk_r24.4.1-linux.tgz | \
tar xzf - -C sdk --strip-components=1
curl https://dl.google.com/android/repository/tools_r25.2.5-linux.zip -O
unzip -d sdk tools_r25.2.5-linux.zip

filter="platform-tools,android-21"
filter="$filter,sys-img-armeabi-v7a-android-21"
filter="platform-tools,android-24"

./accept-licenses.sh "android - update sdk -a --no-ui --filter $filter"
case "$1" in
arm | armv7)
abi=armeabi-v7a
;;

aarch64)
abi=arm64-v8a
;;

i686)
abi=x86
;;

*)
echo "invalid arch: $1"
exit 1
;;
esac;

filter="$filter,sys-img-$abi-android-24"

./android-accept-licenses.sh "android - update sdk -a --no-ui --filter $filter"

echo "no" | android create avd \
--name arm-21 \
--target android-21 \
--abi armeabi-v7a
--name $1 \
--target android-24 \
--abi $abi
32 changes: 32 additions & 0 deletions ci/docker/aarch64-linux-android/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM ubuntu:16.04

RUN dpkg --add-architecture i386 && \
apt-get update && \
apt-get install -y --no-install-recommends \
file \
curl \
ca-certificates \
python \
unzip \
expect \
openjdk-9-jre \
libstdc++6:i386 \
libpulse0 \
gcc \
libc6-dev

WORKDIR /android/
COPY android* /android/

ENV ANDROID_ARCH=aarch64
ENV PATH=$PATH:/android/ndk-$ANDROID_ARCH/bin:/android/sdk/tools:/android/sdk/platform-tools

RUN sh /android/android-install-ndk.sh $ANDROID_ARCH
RUN sh /android/android-install-sdk.sh $ANDROID_ARCH
RUN mv /root/.android /tmp
RUN chmod 777 -R /tmp/.android
RUN chmod 755 /android/sdk/tools/* /android/sdk/tools/qemu/linux-x86_64/*

ENV PATH=$PATH:/rust/bin \
CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android-gcc \
HOME=/tmp
20 changes: 9 additions & 11 deletions ci/docker/arm-linux-androideabi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,22 @@ RUN dpkg --add-architecture i386 && \
expect \
openjdk-9-jre \
libstdc++6:i386 \
libpulse0 \
gcc \
libc6-dev

WORKDIR /android/
COPY android* /android/

COPY install-ndk.sh /android/
RUN sh /android/install-ndk.sh
ENV ANDROID_ARCH=arm
ENV PATH=$PATH:/android/ndk-$ANDROID_ARCH/bin:/android/sdk/tools:/android/sdk/platform-tools

ENV PATH=$PATH:/android/ndk-arm/bin:/android/sdk/tools:/android/sdk/platform-tools

COPY install-sdk.sh accept-licenses.sh /android/
RUN sh /android/install-sdk.sh
RUN sh /android/android-install-ndk.sh $ANDROID_ARCH
RUN sh /android/android-install-sdk.sh $ANDROID_ARCH
RUN mv /root/.android /tmp
RUN chmod 777 -R /tmp/.android
RUN chmod 755 /android/sdk/tools/* /android/sdk/tools/qemu/linux-x86_64/*

ENV PATH=$PATH:/rust/bin \
CARGO_TARGET_ARM_LINUX_ANDROIDEABI_LINKER=arm-linux-androideabi-gcc \
ANDROID_EMULATOR_FORCE_32BIT=1 \
HOME=/tmp
RUN chmod 755 /android/sdk/tools/*

RUN cp -r /root/.android /tmp
RUN chmod 777 -R /tmp/.android
32 changes: 32 additions & 0 deletions ci/docker/i686-linux-android/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM ubuntu:16.04

RUN dpkg --add-architecture i386 && \
apt-get update && \
apt-get install -y --no-install-recommends \
file \
curl \
ca-certificates \
python \
unzip \
expect \
openjdk-9-jre \
libstdc++6:i386 \
libpulse0 \
gcc \
libc6-dev

WORKDIR /android/
COPY android* /android/

ENV ANDROID_ARCH=i686
ENV PATH=$PATH:/android/ndk-$ANDROID_ARCH/bin:/android/sdk/tools:/android/sdk/platform-tools

RUN sh /android/android-install-ndk.sh $ANDROID_ARCH
RUN sh /android/android-install-sdk.sh $ANDROID_ARCH
RUN mv /root/.android /tmp
RUN chmod 777 -R /tmp/.android
RUN chmod 755 /android/sdk/tools/* /android/sdk/tools/qemu/linux-x86_64/*

ENV PATH=$PATH:/rust/bin \
CARGO_TARGET_I686_LINUX_ANDROID_LINKER=i686-linux-android-gcc \
HOME=/tmp
3 changes: 2 additions & 1 deletion ci/run-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ set -ex

run() {
echo $1
docker build -t libc ci/docker/$1
# use -f so we can use ci/ as build context
docker build -t libc -f ci/docker/$1/Dockerfile ci/
mkdir -p target
docker run \
--user `id -u`:`id -g` \
Expand Down
13 changes: 9 additions & 4 deletions ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,16 @@ case "$TARGET" in
esac

case "$TARGET" in
arm-linux-androideabi)
emulator @arm-21 -no-window &
arm-linux-androideabi | aarch64-linux-android | i686-linux-android)
# set SHELL so android can detect a 64bits system, see
# http://stackoverflow.com/a/41789144
# https://issues.jenkins-ci.org/browse/JENKINS-26930?focusedCommentId=230791&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-230791
export SHELL=/bin/dash
arch=$(echo $TARGET | cut -d- -f1)
emulator @$arch -no-window -no-accel &
adb wait-for-device
adb push $CARGO_TARGET_DIR/$TARGET/debug/libc-test /data/libc-test
adb shell /data/libc-test 2>&1 | tee /tmp/out
adb push $CARGO_TARGET_DIR/$TARGET/debug/libc-test /data/local/tmp/libc-test
adb shell /data/local/tmp/libc-test 2>&1 | tee /tmp/out
grep "^PASSED .* tests" /tmp/out
;;

Expand Down
7 changes: 6 additions & 1 deletion libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::env;

fn main() {
let target = env::var("TARGET").unwrap();
let aarch64 = target.contains("aarch64");
let x86_64 = target.contains("x86_64");
let windows = target.contains("windows");
let mingw = target.contains("windows-gnu");
Expand Down Expand Up @@ -105,8 +106,12 @@ fn main() {
}

if android {
if !aarch64 {
// time64_t is not define for aarch64
// If included it will generate the error 'Your time_t is already 64-bit'
cfg.header("time64.h");
}
cfg.header("arpa/inet.h");
cfg.header("time64.h");
cfg.header("xlocale.h");
cfg.header("utmp.h");
} else if !windows {
Expand Down
71 changes: 70 additions & 1 deletion src/unix/bsd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dox::mem;
use dox::{mem, Option};

pub type c_char = i8;
pub type wchar_t = i32;
Expand Down Expand Up @@ -359,6 +359,75 @@ extern {
pub fn getpeereid(socket: ::c_int,
euid: *mut ::uid_t,
egid: *mut ::gid_t) -> ::c_int;

#[cfg_attr(target_os = "macos", link_name = "glob$INODE64")]
#[cfg_attr(target_os = "netbsd", link_name = "__glob30")]
pub fn glob(pattern: *const ::c_char,
flags: ::c_int,
errfunc: Option<extern fn(epath: *const ::c_char,
errno: ::c_int) -> ::c_int>,
pglob: *mut ::glob_t) -> ::c_int;
#[cfg_attr(target_os = "netbsd", link_name = "__globfree30")]
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 madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int)
-> ::c_int;

#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "msync$UNIX2003")]
#[cfg_attr(target_os = "netbsd", link_name = "__msync13")]
pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::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;
pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int;
pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int;
pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char;

#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "bind$UNIX2003")]
pub fn bind(socket: ::c_int, address: *const ::sockaddr,
address_len: ::socklen_t) -> ::c_int;

#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "writev$UNIX2003")]
pub fn writev(fd: ::c_int,
iov: *const ::iovec,
iovcnt: ::c_int) -> ::ssize_t;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "readv$UNIX2003")]
pub fn readv(fd: ::c_int,
iov: *const ::iovec,
iovcnt: ::c_int) -> ::ssize_t;

#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "sendmsg$UNIX2003")]
pub fn sendmsg(fd: ::c_int,
msg: *const ::msghdr,
flags: ::c_int) -> ::ssize_t;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "recvmsg$UNIX2003")]
pub fn recvmsg(fd: ::c_int, msg: *mut ::msghdr, flags: ::c_int)
-> ::ssize_t;
}

cfg_if! {
Expand Down
45 changes: 44 additions & 1 deletion src/unix/haiku/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dox::mem;
use dox::{mem, Option};

pub type rlim_t = ::uintptr_t;
pub type sa_family_t = u8;
Expand Down Expand Up @@ -760,6 +760,49 @@ extern {
abstime: *const ::timespec) -> ::c_int;
pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,
options: ::c_int) -> ::c_int;

pub fn glob(pattern: *const ::c_char,
flags: ::c_int,
errfunc: Option<extern 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;

pub fn seekdir(dirp: *mut ::DIR, loc: ::c_long);

pub fn telldir(dirp: *mut ::DIR) -> ::c_long;
pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int)
-> ::c_int;

pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int;

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;
pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int;
pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int;
pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char;

pub fn bind(socket: ::c_int, address: *const ::sockaddr,
address_len: ::socklen_t) -> ::c_int;

pub fn writev(fd: ::c_int,
iov: *const ::iovec,
iovcnt: ::c_int) -> ::ssize_t;
pub fn readv(fd: ::c_int,
iov: *const ::iovec,
iovcnt: ::c_int) -> ::ssize_t;

pub fn sendmsg(fd: ::c_int,
msg: *const ::msghdr,
flags: ::c_int) -> ::ssize_t;
pub fn recvmsg(fd: ::c_int, msg: *mut ::msghdr, flags: ::c_int)
-> ::ssize_t;
}

cfg_if! {
Expand Down
Loading