Skip to content

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

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

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
88 changes: 50 additions & 38 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,6 @@ extern {
link_name = "connect$UNIX2003")]
pub fn connect(socket: ::c_int, address: *const sockaddr,
len: socklen_t) -> ::c_int;
#[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 = "listen$UNIX2003")]
pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int;
Expand Down Expand Up @@ -680,16 +676,6 @@ extern {
#[cfg_attr(target_os = "netbsd", link_name = "__mknod50")]
pub fn mknod(pathname: *const ::c_char, mode: ::mode_t,
dev: ::dev_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;
pub fn uname(buf: *mut ::utsname) -> ::c_int;
pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int;
pub fn gethostname(name: *mut ::c_char, len: ::size_t) -> ::c_int;
Expand All @@ -709,14 +695,6 @@ extern {
link_name = "putenv$UNIX2003")]
#[cfg_attr(target_os = "netbsd", link_name = "__putenv50")]
pub fn putenv(string: *mut c_char) -> ::c_int;
#[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_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "poll$UNIX2003")]
pub fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: ::c_int) -> ::c_int;
Expand Down Expand Up @@ -750,6 +728,56 @@ extern {
-> ::c_int;
pub fn statvfs(path: *const c_char, buf: *mut statvfs) -> ::c_int;
pub fn fstatvfs(fd: ::c_int, buf: *mut statvfs) -> ::c_int;

pub fn readlink(path: *const c_char,
buf: *mut c_char,
bufsz: ::size_t)
-> ::ssize_t;

#[cfg_attr(target_os = "netbsd", link_name = "__sigemptyset14")]
pub fn sigemptyset(set: *mut sigset_t) -> ::c_int;
#[cfg_attr(target_os = "netbsd", link_name = "__sigaddset14")]
pub fn sigaddset(set: *mut sigset_t, signum: ::c_int) -> ::c_int;
#[cfg_attr(target_os = "netbsd", link_name = "__sigfillset14")]
pub fn sigfillset(set: *mut sigset_t) -> ::c_int;
#[cfg_attr(target_os = "netbsd", link_name = "__sigdelset14")]
pub fn sigdelset(set: *mut sigset_t, signum: ::c_int) -> ::c_int;
#[cfg_attr(target_os = "netbsd", link_name = "__sigismember14")]
pub fn sigismember(set: *const sigset_t, signum: ::c_int) -> ::c_int;

#[cfg_attr(target_os = "netbsd", link_name = "__timegm50")]
pub fn timegm(tm: *mut ::tm) -> time_t;
}

// Android has some weirdness in this definition
// See weirdness in src/unix/notbsd/android/mod.rs
#[cfg(any(not(target_os = "android"), // " if " -- appease style checker
not(target_arch = "aarch64")))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I unfortunately regret the block below this, but could we just duplicate these functions in lower modules to avoid this #[cfg] attribute?

extern {
#[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;
}

// TODO: get rid of this cfg(not(...))
Expand Down Expand Up @@ -785,10 +813,6 @@ extern {
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 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")]
Expand All @@ -802,16 +826,6 @@ extern {
addrlen: *mut socklen_t) -> ::ssize_t;
pub fn mkfifo(path: *const c_char, mode: mode_t) -> ::c_int;

#[cfg_attr(target_os = "netbsd", link_name = "__sigemptyset14")]
pub fn sigemptyset(set: *mut sigset_t) -> ::c_int;
#[cfg_attr(target_os = "netbsd", link_name = "__sigaddset14")]
pub fn sigaddset(set: *mut sigset_t, signum: ::c_int) -> ::c_int;
#[cfg_attr(target_os = "netbsd", link_name = "__sigfillset14")]
pub fn sigfillset(set: *mut sigset_t) -> ::c_int;
#[cfg_attr(target_os = "netbsd", link_name = "__sigdelset14")]
pub fn sigdelset(set: *mut sigset_t, signum: ::c_int) -> ::c_int;
#[cfg_attr(target_os = "netbsd", link_name = "__sigismember14")]
pub fn sigismember(set: *const sigset_t, signum: ::c_int) -> ::c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
link_name = "pselect$1050")]
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
Expand All @@ -827,8 +841,6 @@ extern {
offset: ::off_t,
whence: ::c_int) -> ::c_int;
pub fn ftello(stream: *mut ::FILE) -> ::off_t;
#[cfg_attr(target_os = "netbsd", link_name = "__timegm50")]
pub fn timegm(tm: *mut ::tm) -> time_t;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "tcdrain$UNIX2003")]
pub fn tcdrain(fd: ::c_int) -> ::c_int;
Expand Down
8 changes: 8 additions & 0 deletions src/unix/notbsd/android/b32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ pub type c_long = i32;
pub type c_ulong = u32;
pub type mode_t = u16;
pub type off64_t = ::c_longlong;
pub type sigset_t = ::c_ulong;
pub type socklen_t = i32;
pub type time64_t = i64;

s! {
pub struct sigaction {
Expand All @@ -11,6 +14,11 @@ s! {
pub sa_restorer: ::dox::Option<extern fn()>,
}

pub struct rlimit64 {
pub rlim_cur: u64,
pub rlim_max: u64,
}

pub struct stat {
pub st_dev: ::c_ulonglong,
__pad0: [::c_uchar; 4],
Expand Down
Loading