set -ex
if [ "$TRAVIS_OS_NAME" = "linux" ]; then
OS=unknown-linux-gnu
else
OS=apple-darwin
fi
export HOST=$ARCH-$OS
if [ "$TARGET" = "" ]; then
TARGET=$HOST
fi
MAIN_TARGETS=https://static.rust-lang.org/dist
DATE=$(echo $TRAVIS_RUST_VERSION | sed s/nightly-//)
if [ "$DATE" != "nightly" ]; then
MAIN_TARGETS=$MAIN_TARGETS/$DATE
TRAVIS_RUST_VERSION=nightly
fi
install() {
if [ "$TRAVIS" = "true" ]; then
sudo apt-get update
sudo apt-get install -y $@
fi
}
if [ "$QEMU" != "" ]; then
install qemu-kvm
tmpdir=/tmp/qemu-img-creation
mkdir -p $tmpdir
if [ ! -f $tmpdir/$QEMU ]; then
curl https://people.mozilla.org/~acrichton/libc-test/qemu/$QEMU.gz | \
gunzip -d > $tmpdir/$QEMU
fi
rm -rf $tmpdir/generated
mkdir -p $tmpdir/generated
CARGO_TARGET_DIR=$tmpdir/generated-build \
cargo build --manifest-path libc-test/generate-files/Cargo.toml
(cd libc-test && TARGET=$TARGET OUT_DIR=$tmpdir/generated SKIP_COMPILE=1 \
$tmpdir/generated-build/debug/generate-files)
rm -f $tmpdir/libc-test.img
dd if=/dev/null of=$tmpdir/libc-test.img bs=1M seek=5
mkfs.ext2 -F $tmpdir/libc-test.img
rm -rf $tmpdir/mount
mkdir $tmpdir/mount
sudo mount -t ext2 -o loop $tmpdir/libc-test.img $tmpdir/mount
sudo mkdir $tmpdir/mount/libc
sudo cp -r * $tmpdir/mount/libc/
sudo cp ci/run-qemu.sh $tmpdir/mount/run.sh
echo $TARGET | sudo tee -a $tmpdir/mount/TARGET
sudo cp $tmpdir/generated/* $tmpdir/mount/libc/libc-test
sudo cp libc-test/run-generated-Cargo.toml $tmpdir/mount/libc/libc-test/Cargo.toml
sudo umount $tmpdir/mount
if kvm-ok; then
program="sudo kvm"
else
program=qemu-system-x86_64
fi
$program \
-m 1024 \
-snapshot \
-drive if=virtio,file=$tmpdir/$QEMU \
-drive if=virtio,file=$tmpdir/libc-test.img \
-net nic,model=virtio \
-net user \
-nographic \
-vga none 2>&1 | tee out.log
exec grep "^PASSED .* tests" out.log
fi
mkdir -p .cargo
cp ci/cargo-config .cargo/config
if [ "$TRAVIS" = "true" ]; then
curl https://static.rust-lang.org/rustup.sh | \
sh -s -- --add-target=$TARGET --disable-sudo -y \
--prefix=`rustc --print sysroot`
fi
if [ "$DOCKER" != "" ]; then
args=""
case "$TARGET" in
mips-unknown-linux-gnu)
args="$args -e CC=mips-linux-gnu-gcc-5"
;;
*)
;;
esac
exec docker run \
--entrypoint bash \
-v `rustc --print sysroot`:/usr/local:ro \
-v `pwd`:/checkout \
-e LD_LIBRARY_PATH=/usr/local/lib \
-e CARGO_TARGET_DIR=/tmp \
$args \
-w /checkout \
-it $DOCKER \
ci/run.sh $TARGET
fi
case "$TARGET" in
x86_64-unknown-linux-musl)
install musl-tools
export CC=musl-gcc
;;
arm-unknown-linux-gnueabihf)
install gcc-4.7-arm-linux-gnueabihf qemu-user
export CC=arm-linux-gnueabihf-gcc-4.7
;;
aarch64-unknown-linux-gnu)
install gcc-aarch64-linux-gnu qemu-user
export CC=aarch64-linux-gnu-gcc
;;
*-apple-ios)
;;
*)
export CC=clang
if [ "$TARGET" = "i686-unknown-linux-gnu" ]; then
install gcc-multilib
fi
;;
esac
sh ci/run.sh $TARGET
if [ "$TARGET" = "x86_64-unknown-linux-gnu" ] && \
[ "$TRAVIS_RUST_VERSION" = "nightly" ] && \
[ "$TRAVIS_OS_NAME" = "linux" ]; then
sh ci/dox.sh
fi