| Alex Crichton | d9962f4 | 2015-09-17 17:45:10 -0700 | [diff] [blame] | 1 | # 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 Crichton | d820c4a | 2016-01-18 11:16:38 -0800 | [diff] [blame] | 4 | # |
| 5 | # For a full description of how all tests are run, see `ci/README.md` |
| Alex Crichton | d9962f4 | 2015-09-17 17:45:10 -0700 | [diff] [blame] | 6 | |
| Alex Crichton | 83a3049 | 2015-09-12 16:15:48 -0700 | [diff] [blame] | 7 | set -ex |
| 8 | |
| Alex Crichton | e47a450 | 2015-09-12 16:42:49 -0700 | [diff] [blame] | 9 | if [ "$TRAVIS_OS_NAME" = "linux" ]; then |
| Alex Crichton | 83a3049 | 2015-09-12 16:15:48 -0700 | [diff] [blame] | 10 | OS=unknown-linux-gnu |
| 11 | else |
| 12 | OS=apple-darwin |
| 13 | fi |
| 14 | |
| 15 | export HOST=$ARCH-$OS |
| Alex Crichton | 657eeec | 2015-10-29 10:06:09 -0700 | [diff] [blame] | 16 | if [ "$TARGET" = "" ]; then |
| 17 | TARGET=$HOST |
| 18 | fi |
| Alex Crichton | 83a3049 | 2015-09-12 16:15:48 -0700 | [diff] [blame] | 19 | |
| Alex Crichton | 2fe6de4 | 2015-09-14 14:07:49 -0700 | [diff] [blame] | 20 | MAIN_TARGETS=https://static.rust-lang.org/dist |
| Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 21 | DATE=$(echo $TRAVIS_RUST_VERSION | sed s/nightly-//) |
| 22 | EXTRA_TARGETS=https://people.mozilla.org/~acrichton/libc-test/$DATE |
| Alex Crichton | 23ab70b | 2015-09-13 23:38:27 -0700 | [diff] [blame] | 23 | |
| Alex Crichton | b66b8a4 | 2015-09-17 20:55:52 -0700 | [diff] [blame] | 24 | install() { |
| Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 25 | if [ "$TRAVIS" = "true" ]; then |
| 26 | sudo apt-get update |
| 27 | sudo apt-get install -y $@ |
| 28 | fi |
| Alex Crichton | b66b8a4 | 2015-09-17 20:55:52 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| Alex Crichton | d820c4a | 2016-01-18 11:16:38 -0800 | [diff] [blame] | 31 | # 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. |
| 37 | if [ "$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 |
| 101 | fi |
| 102 | |
| Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 103 | mkdir -p .cargo |
| 104 | cp ci/cargo-config .cargo/config |
| 105 | |
| Alex Crichton | d820c4a | 2016-01-18 11:16:38 -0800 | [diff] [blame] | 106 | # 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 Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 109 | if [ "$TRAVIS" = "true" ]; then |
| 110 | case "$TARGET" in |
| Alex Crichton | 36ae235 | 2016-02-01 11:43:49 -0800 | [diff] [blame] | 111 | *-rumprun-*) |
| Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 112 | curl -s $EXTRA_TARGETS/$TARGET.tar.gz | \ |
| 113 | tar xzf - -C `rustc --print sysroot`/lib/rustlib |
| 114 | ;; |
| Alex Crichton | 657eeec | 2015-10-29 10:06:09 -0700 | [diff] [blame] | 115 | |
| Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 116 | *) |
| Alex Crichton | a5d830a | 2016-01-10 14:36:27 -0800 | [diff] [blame] | 117 | # Download the rustlib folder from the relevant portion of main |
| 118 | # distribution's tarballs. |
| Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 119 | 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 Crichton | 657eeec | 2015-10-29 10:06:09 -0700 | [diff] [blame] | 129 | |
| Alex Crichton | 8dce9ad | 2015-12-03 11:44:14 -0800 | [diff] [blame] | 130 | esac |
| 131 | fi |
| Alex Crichton | 657eeec | 2015-10-29 10:06:09 -0700 | [diff] [blame] | 132 | |
| Alex Crichton | d820c4a | 2016-01-18 11:16:38 -0800 | [diff] [blame] | 133 | # 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 Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 141 | if [ "$DOCKER" != "" ]; then |
| Alex Crichton | a5d830a | 2016-01-10 14:36:27 -0800 | [diff] [blame] | 142 | 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 Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 153 | 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 Crichton | a5d830a | 2016-01-10 14:36:27 -0800 | [diff] [blame] | 159 | $args \ |
| Alex Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 160 | -w /checkout \ |
| 161 | -it $DOCKER \ |
| 162 | ci/run.sh $TARGET |
| 163 | fi |
| Alex Crichton | a4d78c4 | 2015-09-14 13:52:51 -0700 | [diff] [blame] | 164 | |
| Alex Crichton | d820c4a | 2016-01-18 11:16:38 -0800 | [diff] [blame] | 165 | # 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 Crichton | 49d7bca | 2015-11-27 09:40:37 -0800 | [diff] [blame] | 167 | case "$TARGET" in |
| Alex Crichton | 22f3c5e | 2015-09-18 17:30:58 -0700 | [diff] [blame] | 168 | x86_64-unknown-linux-musl) |
| Alex Crichton | 22f3c5e | 2015-09-18 17:30:58 -0700 | [diff] [blame] | 169 | install musl-tools |
| 170 | export CC=musl-gcc |
| 171 | ;; |
| Alex Crichton | a4d78c4 | 2015-09-14 13:52:51 -0700 | [diff] [blame] | 172 | |
| Alex Crichton | 22f3c5e | 2015-09-18 17:30:58 -0700 | [diff] [blame] | 173 | arm-unknown-linux-gnueabihf) |
| Alex Crichton | 22f3c5e | 2015-09-18 17:30:58 -0700 | [diff] [blame] | 174 | install gcc-4.7-arm-linux-gnueabihf qemu-user |
| 175 | export CC=arm-linux-gnueabihf-gcc-4.7 |
| 176 | ;; |
| Alex Crichton | d86471c | 2015-09-17 17:46:58 -0700 | [diff] [blame] | 177 | |
| Alex Crichton | 22f3c5e | 2015-09-18 17:30:58 -0700 | [diff] [blame] | 178 | aarch64-unknown-linux-gnu) |
| Alex Crichton | 22f3c5e | 2015-09-18 17:30:58 -0700 | [diff] [blame] | 179 | install gcc-aarch64-linux-gnu qemu-user |
| 180 | export CC=aarch64-linux-gnu-gcc |
| 181 | ;; |
| 182 | |
| Alex Crichton | baef611 | 2015-09-19 23:20:53 -0700 | [diff] [blame] | 183 | *-apple-ios) |
| Alex Crichton | baef611 | 2015-09-19 23:20:53 -0700 | [diff] [blame] | 184 | ;; |
| 185 | |
| Alex Crichton | 22f3c5e | 2015-09-18 17:30:58 -0700 | [diff] [blame] | 186 | *) |
| Alex Crichton | 22f3c5e | 2015-09-18 17:30:58 -0700 | [diff] [blame] | 187 | # 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 | |
| 195 | esac |
| Alex Crichton | 944a733 | 2015-09-14 11:27:10 -0700 | [diff] [blame] | 196 | |
| Alex Crichton | d820c4a | 2016-01-18 11:16:38 -0800 | [diff] [blame] | 197 | # Finally, if we've gotten this far, actually run the tests. |
| Alex Crichton | 944a733 | 2015-09-14 11:27:10 -0700 | [diff] [blame] | 198 | sh ci/run.sh $TARGET |
| Alex Crichton | 9eca468 | 2015-09-17 00:48:36 -0700 | [diff] [blame] | 199 | |
| 200 | if [ "$TARGET" = "x86_64-unknown-linux-gnu" ] && \ |
| 201 | [ "$TRAVIS_RUST_VERSION" = "nightly" ] && \ |
| 202 | [ "$TRAVIS_OS_NAME" = "linux" ]; then |
| 203 | sh ci/dox.sh |
| 204 | fi |