blob: e6d6c81562c9dba12b0b8d50e8092e00f9df50e3 [file] [log] [blame]
Alex Crichtond9962f42015-09-17 17:45:10 -07001# Entry point for all travis builds, this will set up the Travis environment by
2# downloading any dependencies. It will then execute the `run.sh` script to
3# build and execute all tests.
Alex Crichtond820c4a2016-01-18 11:16:38 -08004#
5# For a full description of how all tests are run, see `ci/README.md`
Alex Crichtond9962f42015-09-17 17:45:10 -07006
Alex Crichton83a30492015-09-12 16:15:48 -07007set -ex
8
Alex Crichtone47a4502015-09-12 16:42:49 -07009if [ "$TRAVIS_OS_NAME" = "linux" ]; then
Alex Crichton83a30492015-09-12 16:15:48 -070010 OS=unknown-linux-gnu
11else
12 OS=apple-darwin
13fi
14
15export HOST=$ARCH-$OS
Alex Crichton657eeec2015-10-29 10:06:09 -070016if [ "$TARGET" = "" ]; then
17 TARGET=$HOST
18fi
Alex Crichton83a30492015-09-12 16:15:48 -070019
Alex Crichton2fe6de42015-09-14 14:07:49 -070020MAIN_TARGETS=https://static.rust-lang.org/dist
Alex Crichton49d7bca2015-11-27 09:40:37 -080021DATE=$(echo $TRAVIS_RUST_VERSION | sed s/nightly-//)
22EXTRA_TARGETS=https://people.mozilla.org/~acrichton/libc-test/$DATE
Alex Crichton23ab70b2015-09-13 23:38:27 -070023
Alex Crichtonb66b8a42015-09-17 20:55:52 -070024install() {
Alex Crichton8dce9ad2015-12-03 11:44:14 -080025 if [ "$TRAVIS" = "true" ]; then
26 sudo apt-get update
27 sudo apt-get install -y $@
28 fi
Alex Crichtonb66b8a42015-09-17 20:55:52 -070029}
30
Alex Crichtond820c4a2016-01-18 11:16:38 -080031# If we're going to run tests inside of a qemu image, then we don't need any of
32# the scripts below. Instead, download the image, prepare a filesystem which has
33# the current state of this repository, and then run the image.
34#
35# It's assume that all images, when run with two disks, will run the `run.sh`
36# script from the second which we place inside.
37if [ "$QEMU" != "" ]; then
38 # Acquire QEMU and the base OS image
39 install qemu-kvm
40 tmpdir=/tmp/qemu-img-creation
41 mkdir -p $tmpdir
42 if [ ! -f $tmpdir/$QEMU ]; then
43 curl https://people.mozilla.org/~acrichton/libc-test/qemu/$QEMU.gz | \
44 gunzip -d > $tmpdir/$QEMU
45 fi
46
47 # Generate all.{c,rs} on the host which will be compiled inside QEMU. Do this
48 # here because compiling syntex_syntax in QEMU would time out basically
49 # everywhere.
50 rm -rf $tmpdir/generated
51 mkdir -p $tmpdir/generated
52 CARGO_TARGET_DIR=$tmpdir/generated-build \
53 cargo build --manifest-path libc-test/generate-files/Cargo.toml
54 (cd libc-test && TARGET=$TARGET OUT_DIR=$tmpdir/generated SKIP_COMPILE=1 \
55 $tmpdir/generated-build/debug/generate-files)
56
57 # Create a mount a fresh new filesystem image that we'll later pass to QEMU,
58 # this contains the checkout of libc and will be able to run all tests
59 rm -f $tmpdir/libc-test.img
60 dd if=/dev/null of=$tmpdir/libc-test.img bs=1M seek=5
61 mkfs.ext2 -F $tmpdir/libc-test.img
62 rm -rf $tmpdir/mount
63 mkdir $tmpdir/mount
64 sudo mount -t ext2 -o loop $tmpdir/libc-test.img $tmpdir/mount
65
66 # Copy this folder into the mounted image, the `run.sh` entry point, and
67 # overwrite the standard libc-test Cargo.toml with the overlay one which will
68 # assume the all.{c,rs} test files have already been generated
69 sudo mkdir $tmpdir/mount/libc
70 sudo cp -r * $tmpdir/mount/libc/
71 sudo cp ci/run-qemu.sh $tmpdir/mount/run.sh
72 echo $TARGET | sudo tee -a $tmpdir/mount/TARGET
73 sudo cp $tmpdir/generated/* $tmpdir/mount/libc/libc-test
74 sudo cp libc-test/run-generated-Cargo.toml $tmpdir/mount/libc/libc-test/Cargo.toml
75
76 sudo umount $tmpdir/mount
77
78 # If we can use kvm, prefer that, otherwise just fall back to user-space
79 # emulation.
80 if kvm-ok; then
81 program="sudo kvm"
82 else
83 program=qemu-system-x86_64
84 fi
85
86 # Pass -snapshot to prevent tampering with the disk images, this helps when
87 # running this script in development. The two drives are then passed next,
88 # first is the OS and second is the one we just made. Next the network is
89 # configured to work (I'm not entirely sure how), and then finally we turn off
90 # graphics and redirect the serial console output to out.log.
91 $program \
92 -m 1024 \
93 -snapshot \
94 -drive if=virtio,file=$tmpdir/$QEMU \
95 -drive if=virtio,file=$tmpdir/libc-test.img \
96 -net nic,model=virtio \
97 -net user \
98 -nographic \
99 -vga none 2>&1 | tee out.log
100 exec grep "^PASSED .* tests" out.log
101fi
102
Alex Crichton49d7bca2015-11-27 09:40:37 -0800103mkdir -p .cargo
104cp ci/cargo-config .cargo/config
105
Alex Crichtond820c4a2016-01-18 11:16:38 -0800106# Next up we need to install the standard library for the version of Rust that
107# we're testing. Get fancy targets from the EXTRA_TARGETS URL and otherwise get
108# all others from the official distribution.
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800109if [ "$TRAVIS" = "true" ]; then
110 case "$TARGET" in
Alex Crichton36ae2352016-02-01 11:43:49 -0800111 *-rumprun-*)
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800112 curl -s $EXTRA_TARGETS/$TARGET.tar.gz | \
113 tar xzf - -C `rustc --print sysroot`/lib/rustlib
114 ;;
Alex Crichton657eeec2015-10-29 10:06:09 -0700115
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800116 *)
Alex Crichtona5d830a2016-01-10 14:36:27 -0800117 # Download the rustlib folder from the relevant portion of main
118 # distribution's tarballs.
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800119 dir=rust-std-$TARGET
120 pkg=rust-std
121 if [ "$TRAVIS_RUST_VERSION" = "1.0.0" ]; then
122 pkg=rust
123 dir=rustc
124 fi
125 curl -s $MAIN_TARGETS/$pkg-$TRAVIS_RUST_VERSION-$TARGET.tar.gz | \
126 tar xzf - -C $HOME/rust/lib/rustlib --strip-components=4 \
127 $pkg-$TRAVIS_RUST_VERSION-$TARGET/$dir/lib/rustlib/$TARGET
128 ;;
Alex Crichton657eeec2015-10-29 10:06:09 -0700129
Alex Crichton8dce9ad2015-12-03 11:44:14 -0800130 esac
131fi
Alex Crichton657eeec2015-10-29 10:06:09 -0700132
Alex Crichtond820c4a2016-01-18 11:16:38 -0800133# If we're testing with a docker image, then run tests entirely within that
134# image. Note that this is using the same rustc installation that travis has
135# (sharing it via `-v`) and otherwise the tests run entirely within the
136# container.
137#
138# For the docker build we mount the entire current directory at /checkout, set
139# up some environment variables to let it run, and then run the standard run.sh
140# script.
Alex Crichton49d7bca2015-11-27 09:40:37 -0800141if [ "$DOCKER" != "" ]; then
Alex Crichtona5d830a2016-01-10 14:36:27 -0800142 args=""
143
144 case "$TARGET" in
145 mips-unknown-linux-gnu)
146 args="$args -e CC=mips-linux-gnu-gcc-5"
147 ;;
148
149 *)
150 ;;
151 esac
152
Alex Crichton49d7bca2015-11-27 09:40:37 -0800153 exec docker run \
154 --entrypoint bash \
155 -v `rustc --print sysroot`:/usr/local:ro \
156 -v `pwd`:/checkout \
157 -e LD_LIBRARY_PATH=/usr/local/lib \
158 -e CARGO_TARGET_DIR=/tmp \
Alex Crichtona5d830a2016-01-10 14:36:27 -0800159 $args \
Alex Crichton49d7bca2015-11-27 09:40:37 -0800160 -w /checkout \
161 -it $DOCKER \
162 ci/run.sh $TARGET
163fi
Alex Crichtona4d78c42015-09-14 13:52:51 -0700164
Alex Crichtond820c4a2016-01-18 11:16:38 -0800165# If we're not running docker or qemu, then we may still need some packages
166# and/or tools with various configurations here and there.
Alex Crichton49d7bca2015-11-27 09:40:37 -0800167case "$TARGET" in
Alex Crichton22f3c5e2015-09-18 17:30:58 -0700168 x86_64-unknown-linux-musl)
Alex Crichton22f3c5e2015-09-18 17:30:58 -0700169 install musl-tools
170 export CC=musl-gcc
171 ;;
Alex Crichtona4d78c42015-09-14 13:52:51 -0700172
Alex Crichton22f3c5e2015-09-18 17:30:58 -0700173 arm-unknown-linux-gnueabihf)
Alex Crichton22f3c5e2015-09-18 17:30:58 -0700174 install gcc-4.7-arm-linux-gnueabihf qemu-user
175 export CC=arm-linux-gnueabihf-gcc-4.7
176 ;;
Alex Crichtond86471c2015-09-17 17:46:58 -0700177
Alex Crichton22f3c5e2015-09-18 17:30:58 -0700178 aarch64-unknown-linux-gnu)
Alex Crichton22f3c5e2015-09-18 17:30:58 -0700179 install gcc-aarch64-linux-gnu qemu-user
180 export CC=aarch64-linux-gnu-gcc
181 ;;
182
Alex Crichtonbaef6112015-09-19 23:20:53 -0700183 *-apple-ios)
Alex Crichtonbaef6112015-09-19 23:20:53 -0700184 ;;
185
Alex Crichton22f3c5e2015-09-18 17:30:58 -0700186 *)
Alex Crichton22f3c5e2015-09-18 17:30:58 -0700187 # clang has better error messages and implements alignof more broadly
188 export CC=clang
189
190 if [ "$TARGET" = "i686-unknown-linux-gnu" ]; then
191 install gcc-multilib
192 fi
193 ;;
194
195esac
Alex Crichton944a7332015-09-14 11:27:10 -0700196
Alex Crichtond820c4a2016-01-18 11:16:38 -0800197# Finally, if we've gotten this far, actually run the tests.
Alex Crichton944a7332015-09-14 11:27:10 -0700198sh ci/run.sh $TARGET
Alex Crichton9eca4682015-09-17 00:48:36 -0700199
200if [ "$TARGET" = "x86_64-unknown-linux-gnu" ] && \
201 [ "$TRAVIS_RUST_VERSION" = "nightly" ] && \
202 [ "$TRAVIS_OS_NAME" = "linux" ]; then
203 sh ci/dox.sh
204fi