diff --git a/src/ci/docker/android-ndk.sh b/src/ci/docker/android-ndk.sh new file mode 100644 index 0000000000000..4849f84300729 --- /dev/null +++ b/src/ci/docker/android-ndk.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# Copyright 2017 The Rust Project Developers. See the COPYRIGHT +# file at the top-level directory of this distribution and at +# http://rust-lang.org/COPYRIGHT. +# +# Licensed under the Apache License, Version 2.0 or the MIT license +# , at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. + +set -ex + +URL=https://dl.google.com/android/repository + +download_ndk() { + mkdir -p /android/ndk + cd /android/ndk + curl -O $URL/$1 + unzip -q $1 + rm $1 + mv android-ndk-* ndk +} + +make_standalone_toolchain() { + # See https://developer.android.com/ndk/guides/standalone_toolchain.htm + python2.7 /android/ndk/ndk/build/tools/make_standalone_toolchain.py \ + --install-dir /android/ndk/$1-$2 \ + --arch $1 \ + --api $2 +} + +remove_ndk() { + rm -rf /android/ndk/ndk +} diff --git a/src/ci/docker/arm-android/Dockerfile b/src/ci/docker/arm-android/Dockerfile index 04ca6d76c557b..86f0cc5d467d7 100644 --- a/src/ci/docker/arm-android/Dockerfile +++ b/src/ci/docker/arm-android/Dockerfile @@ -1,7 +1,6 @@ FROM ubuntu:16.04 -RUN dpkg --add-architecture i386 && \ - apt-get update && \ +RUN apt-get update && \ apt-get install -y --no-install-recommends \ g++ \ make \ @@ -12,35 +11,54 @@ RUN dpkg --add-architecture i386 && \ git \ cmake \ unzip \ - expect \ - openjdk-9-jre-headless \ sudo \ - libstdc++6:i386 \ xz-utils \ libssl-dev \ pkg-config -WORKDIR /android/ -ENV PATH=$PATH:/android/ndk-arm-9/bin:/android/sdk/tools:/android/sdk/platform-tools - -COPY install-ndk.sh install-sdk.sh accept-licenses.sh /android/ -RUN sh /android/install-ndk.sh -RUN sh /android/install-sdk.sh - RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb && \ dpkg -i dumb-init_*.deb && \ rm dumb-init_*.deb -COPY start-emulator.sh /android/ +RUN curl -o /usr/local/bin/sccache \ + https://s3.amazonaws.com/rust-lang-ci/rust-ci-mirror/2017-04-29-sccache-x86_64-unknown-linux-musl && \ + chmod +x /usr/local/bin/sccache -ENTRYPOINT ["/usr/bin/dumb-init", "--", "/android/start-emulator.sh"] +# Install NDK +COPY install-ndk.sh /tmp +RUN . /tmp/install-ndk.sh && \ + download_ndk android-ndk-r13b-linux-x86_64.zip && \ + make_standalone_toolchain arm 9 && \ + remove_ndk -RUN curl -o /usr/local/bin/sccache \ - https://s3.amazonaws.com/rust-lang-ci/rust-ci-mirror/2017-02-24-sccache-x86_64-unknown-linux-gnu && \ - chmod +x /usr/local/bin/sccache +# Install SDK +RUN dpkg --add-architecture i386 && \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + openjdk-9-jre-headless \ + tzdata \ + libstdc++6:i386 \ + libgl1-mesa-glx \ + libpulse0 + +COPY install-sdk.sh /tmp +RUN . /tmp/install-sdk.sh && \ + download_sdk tools_r25.2.5-linux.zip && \ + download_sysimage armeabi-v7a 18 && \ + create_avd armeabi-v7a 18 + +# Setup env +ENV PATH=$PATH:/android/sdk/tools +ENV PATH=$PATH:/android/sdk/platform-tools + +ENV TARGETS=arm-linux-androideabi ENV RUST_CONFIGURE_ARGS \ - --target=arm-linux-androideabi \ - --arm-linux-androideabi-ndk=/android/ndk-arm-9 + --target=$TARGETS \ + --arm-linux-androideabi-ndk=/android/ndk/arm-9 + +ENV SCRIPT python2.7 ../x.py test --target $TARGETS --verbose -ENV SCRIPT python2.7 ../x.py test --target arm-linux-androideabi +# Entrypoint +COPY start-emulator.sh /android/ +ENTRYPOINT ["/usr/bin/dumb-init", "--", "/android/start-emulator.sh"] diff --git a/src/ci/docker/arm-android/accept-licenses.sh b/src/ci/docker/arm-android/accept-licenses.sh deleted file mode 100755 index 8d8f60a5ec260..0000000000000 --- a/src/ci/docker/arm-android/accept-licenses.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/expect -f -# ignore-license - -set timeout 1800 -set cmd [lindex $argv 0] -set licenses [lindex $argv 1] - -spawn {*}$cmd -expect { - "Do you accept the license '*'*" { - exp_send "y\r" - exp_continue - } - eof -} diff --git a/src/ci/docker/arm-android/install-ndk.sh b/src/ci/docker/arm-android/install-ndk.sh index 389ec062110e0..8081872119983 100644 --- a/src/ci/docker/arm-android/install-ndk.sh +++ b/src/ci/docker/arm-android/install-ndk.sh @@ -11,23 +11,25 @@ set -ex -cpgdb() { - cp android-ndk-r11c/prebuilt/linux-x86_64/bin/gdb /android/$1/bin/$2-gdb - cp android-ndk-r11c/prebuilt/linux-x86_64/bin/gdb-orig /android/$1/bin/gdb-orig - cp -r android-ndk-r11c/prebuilt/linux-x86_64/share /android/$1/share +URL=https://dl.google.com/android/repository + +download_ndk() { + mkdir -p /android/ndk + cd /android/ndk + curl -O $URL/$1 + unzip -q $1 + rm $1 + mv android-ndk-* ndk } -# Prep the Android NDK -# -# See https://github.com/servo/servo/wiki/Building-for-Android -curl -O https://dl.google.com/android/repository/android-ndk-r11c-linux-x86_64.zip -unzip -q android-ndk-r11c-linux-x86_64.zip -bash android-ndk-r11c/build/tools/make-standalone-toolchain.sh \ - --platform=android-9 \ - --toolchain=arm-linux-androideabi-4.9 \ - --install-dir=/android/ndk-arm-9 \ - --ndk-dir=/android/android-ndk-r11c \ - --arch=arm -cpgdb ndk-arm-9 arm-linux-androideabi +make_standalone_toolchain() { + # See https://developer.android.com/ndk/guides/standalone_toolchain.html + python2.7 /android/ndk/ndk/build/tools/make_standalone_toolchain.py \ + --install-dir /android/ndk/$1-$2 \ + --arch $1 \ + --api $2 +} -rm -rf ./android-ndk-r11c-linux-x86_64.zip ./android-ndk-r11c +remove_ndk() { + rm -rf /android/ndk/ndk +} diff --git a/src/ci/docker/arm-android/install-sdk.sh b/src/ci/docker/arm-android/install-sdk.sh index 2db1d46ba2273..258fc47a7a692 100644 --- a/src/ci/docker/arm-android/install-sdk.sh +++ b/src/ci/docker/arm-android/install-sdk.sh @@ -1,5 +1,5 @@ #!/bin/sh -# Copyright 2016 The Rust Project Developers. See the COPYRIGHT +# Copyright 2017 The Rust Project Developers. See the COPYRIGHT # file at the top-level directory of this distribution and at # http://rust-lang.org/COPYRIGHT. # @@ -11,23 +11,39 @@ set -ex -# Prep the SDK and emulator -# -# Note that the update process requires that we accept a bunch of licenses, and -# we can't just pipe `yes` into it for some reason, so we take the same strategy -# located in https://github.com/appunite/docker by just wrapping it in a script -# which apparently magically accepts the licenses. +URL=https://dl.google.com/android/repository + +download_sdk() { + mkdir -p /android/sdk + cd /android/sdk + curl -O $URL/$1 + unzip -q $1 + rm -rf $1 +} + +download_sysimage() { + # See https://developer.android.com/studio/tools/help/android.html + abi=$1 + api=$2 + + filter="platform-tools,android-$api" + filter="$filter,sys-img-$abi-android-$api" -mkdir sdk -curl https://dl.google.com/android/android-sdk_r24.4-linux.tgz | \ - tar xzf - -C sdk --strip-components=1 + # Keep printing yes to accept the licenses + while true; do echo yes; sleep 10; done | \ + /android/sdk/tools/android update sdk -a --no-ui \ + --filter "$filter" +} -filter="platform-tools,android-18" -filter="$filter,sys-img-armeabi-v7a-android-18" +create_avd() { + # See https://developer.android.com/studio/tools/help/android.html + abi=$1 + api=$2 -./accept-licenses.sh "android - update sdk -a --no-ui --filter $filter" + echo no | \ + /android/sdk/tools/android create avd \ + --name $abi-$api \ + --target android-$api \ + --abi $abi +} -echo "no" | android create avd \ - --name arm-18 \ - --target android-18 \ - --abi armeabi-v7a diff --git a/src/ci/docker/arm-android/start-emulator.sh b/src/ci/docker/arm-android/start-emulator.sh index 4a73637e9ddbf..cd3369d5eaddc 100755 --- a/src/ci/docker/arm-android/start-emulator.sh +++ b/src/ci/docker/arm-android/start-emulator.sh @@ -14,5 +14,12 @@ set -ex # Setting SHELL to a file instead on a symlink helps android # emulator identify the system export SHELL=/bin/bash -nohup nohup emulator @arm-18 -no-window -partition-size 2047 0<&- &>/dev/null & + +# Using the default qemu2 engine makes time::tests::since_epoch fails because +# the emulator date is set to unix epoch (in armeabi-v7a-18 image). Using +# classic engine the emulator starts with the current date and the tests run +# fine. If another image is used, this need to be evaluated again. +nohup nohup emulator @armeabi-v7a-18 \ + -engine classic -no-window -partition-size 2047 0<&- &>/dev/null & + exec "$@" diff --git a/src/ci/docker/disabled/dist-aarch64-android/Dockerfile b/src/ci/docker/disabled/dist-aarch64-android/Dockerfile new file mode 100644 index 0000000000000..34e112a1f4f41 --- /dev/null +++ b/src/ci/docker/disabled/dist-aarch64-android/Dockerfile @@ -0,0 +1,49 @@ +FROM ubuntu:16.04 + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + g++ \ + make \ + file \ + curl \ + ca-certificates \ + python2.7 \ + git \ + cmake \ + unzip \ + sudo \ + xz-utils \ + libssl-dev \ + pkg-config + +RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb && \ + dpkg -i dumb-init_*.deb && \ + rm dumb-init_*.deb + +RUN curl -o /usr/local/bin/sccache \ + https://s3.amazonaws.com/rust-lang-ci/rust-ci-mirror/2017-04-29-sccache-x86_64-unknown-linux-musl && \ + chmod +x /usr/local/bin/sccache + +ENTRYPOINT ["/usr/bin/dumb-init", "--"] + +COPY android-ndk.sh / +RUN . /android-ndk.sh && \ + download_ndk android-ndk-r13b-linux-x86_64.zip && \ + make_standalone_toolchain arm64 21 && \ + remove_ndk + +ENV PATH=$PATH:/android/ndk/arm64-21/bin + +ENV DEP_Z_ROOT=/android/ndk/arm64-21/sysroot/usr/ + +ENV HOSTS=aarch64-linux-android + +ENV RUST_CONFIGURE_ARGS \ + --host=$HOSTS \ + --target=$HOSTS \ + --aarch64-linux-android-ndk=/android/ndk/arm64-21 \ + --disable-rpath \ + --enable-extended \ + --enable-cargo-openssl-static + +ENV SCRIPT python2.7 ../x.py dist --target $HOSTS --host $HOSTS diff --git a/src/ci/docker/disabled/dist-armv7-android/Dockerfile b/src/ci/docker/disabled/dist-armv7-android/Dockerfile new file mode 100644 index 0000000000000..34468969b88eb --- /dev/null +++ b/src/ci/docker/disabled/dist-armv7-android/Dockerfile @@ -0,0 +1,65 @@ +FROM ubuntu:16.04 + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + g++ \ + make \ + file \ + curl \ + ca-certificates \ + python2.7 \ + git \ + cmake \ + unzip \ + sudo \ + xz-utils \ + libssl-dev \ + pkg-config + +RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb && \ + dpkg -i dumb-init_*.deb && \ + rm dumb-init_*.deb + +RUN curl -o /usr/local/bin/sccache \ + https://s3.amazonaws.com/rust-lang-ci/rust-ci-mirror/2017-04-29-sccache-x86_64-unknown-linux-musl && \ + chmod +x /usr/local/bin/sccache + +ENTRYPOINT ["/usr/bin/dumb-init", "--"] + +COPY android-ndk.sh / +RUN . /android-ndk.sh && \ + download_ndk android-ndk-r13b-linux-x86_64.zip && \ + make_standalone_toolchain arm 9 && \ + make_standalone_toolchain arm 21 && \ + remove_ndk + +ENV PATH=$PATH:/android/ndk/arm-9/bin + +ENV DEP_Z_ROOT=/android/ndk/arm-9/sysroot/usr/ + +ENV HOSTS=armv7-linux-androideabi + +ENV RUST_CONFIGURE_ARGS \ + --host=$HOSTS \ + --target=$HOSTS \ + --armv7-linux-androideabi-ndk=/android/ndk/arm \ + --disable-rpath \ + --enable-extended \ + --enable-cargo-openssl-static + +# We support api level 9, but api level 21 is required to build llvm. To +# overcome this problem we use a ndk with api level 21 to build llvm and then +# switch to a ndk with api level 9 to complete the build. When the linker is +# invoked there are missing symbols (like sigsetempty, not available with api +# level 9), the default linker behavior is to generate an error, to allow the +# build to finish we use --warn-unresolved-symbols. Note that the missing +# symbols does not affect std, only the compiler (llvm) and cargo (openssl). +RUN chmod 777 /android/ndk && \ + ln -s /android/ndk/arm-21 /android/ndk/arm + +ENV SCRIPT \ + python2.7 ../x.py build src/llvm --host $HOSTS --target $HOSTS && \ + (export RUSTFLAGS="\"-C link-arg=-Wl,--warn-unresolved-symbols\""; \ + rm /android/ndk/arm && \ + ln -s /android/ndk/arm-9 /android/ndk/arm && \ + python2.7 ../x.py dist --host $HOSTS --target $HOSTS) diff --git a/src/ci/docker/disabled/dist-i686-android/Dockerfile b/src/ci/docker/disabled/dist-i686-android/Dockerfile new file mode 100644 index 0000000000000..cb9c76b22818c --- /dev/null +++ b/src/ci/docker/disabled/dist-i686-android/Dockerfile @@ -0,0 +1,65 @@ +FROM ubuntu:16.04 + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + g++ \ + make \ + file \ + curl \ + ca-certificates \ + python2.7 \ + git \ + cmake \ + unzip \ + sudo \ + xz-utils \ + libssl-dev \ + pkg-config + +RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb && \ + dpkg -i dumb-init_*.deb && \ + rm dumb-init_*.deb + +RUN curl -o /usr/local/bin/sccache \ + https://s3.amazonaws.com/rust-lang-ci/rust-ci-mirror/2017-04-29-sccache-x86_64-unknown-linux-musl && \ + chmod +x /usr/local/bin/sccache + +ENTRYPOINT ["/usr/bin/dumb-init", "--"] + +COPY android-ndk.sh / +RUN . /android-ndk.sh && \ + download_ndk android-ndk-r13b-linux-x86_64.zip && \ + make_standalone_toolchain x86 9 && \ + make_standalone_toolchain x86 21 && \ + remove_ndk + +ENV PATH=$PATH:/android/ndk/x86-9/bin + +ENV DEP_Z_ROOT=/android/ndk/x86-9/sysroot/usr/ + +ENV HOSTS=i686-linux-android + +ENV RUST_CONFIGURE_ARGS \ + --host=$HOSTS \ + --target=$HOSTS \ + --i686-linux-android-ndk=/android/ndk/x86 \ + --disable-rpath \ + --enable-extended \ + --enable-cargo-openssl-static + +# We support api level 9, but api level 21 is required to build llvm. To +# overcome this problem we use a ndk with api level 21 to build llvm and then +# switch to a ndk with api level 9 to complete the build. When the linker is +# invoked there are missing symbols (like sigsetempty, not available with api +# level 9), the default linker behavior is to generate an error, to allow the +# build to finish we use --warn-unresolved-symbols. Note that the missing +# symbols does not affect std, only the compiler (llvm) and cargo (openssl). +RUN chmod 777 /android/ndk && \ + ln -s /android/ndk/x86-21 /android/ndk/x86 + +ENV SCRIPT \ + python2.7 ../x.py build src/llvm --host $HOSTS --target $HOSTS && \ + (export RUSTFLAGS="\"-C link-arg=-Wl,--warn-unresolved-symbols\""; \ + rm /android/ndk/x86 && \ + ln -s /android/ndk/x86-9 /android/ndk/x86 && \ + python2.7 ../x.py dist --host $HOSTS --target $HOSTS) diff --git a/src/ci/docker/disabled/dist-x86_64-android/Dockerfile b/src/ci/docker/disabled/dist-x86_64-android/Dockerfile new file mode 100644 index 0000000000000..11a80abf8f9fc --- /dev/null +++ b/src/ci/docker/disabled/dist-x86_64-android/Dockerfile @@ -0,0 +1,49 @@ +FROM ubuntu:16.04 + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + g++ \ + make \ + file \ + curl \ + ca-certificates \ + python2.7 \ + git \ + cmake \ + unzip \ + sudo \ + xz-utils \ + libssl-dev \ + pkg-config + +RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb && \ + dpkg -i dumb-init_*.deb && \ + rm dumb-init_*.deb + +RUN curl -o /usr/local/bin/sccache \ + https://s3.amazonaws.com/rust-lang-ci/rust-ci-mirror/2017-04-29-sccache-x86_64-unknown-linux-musl && \ + chmod +x /usr/local/bin/sccache + +ENTRYPOINT ["/usr/bin/dumb-init", "--"] + +COPY android-ndk.sh / +RUN . /android-ndk.sh && \ + download_ndk android-ndk-r13b-linux-x86_64.zip && \ + make_standalone_toolchain x86_64 21 && \ + remove_ndk + +ENV PATH=$PATH:/android/ndk/x86_64-21/bin + +ENV DEP_Z_ROOT=/android/ndk/x86_64-21/sysroot/usr/ + +ENV HOSTS=x86_64-linux-android + +ENV RUST_CONFIGURE_ARGS \ + --host=$HOSTS \ + --target=$HOSTS \ + --x86_64-linux-android-ndk=/android/ndk/x86_64-21 \ + --disable-rpath \ + --enable-extended \ + --enable-cargo-openssl-static + +ENV SCRIPT python2.7 ../x.py dist --target $HOSTS --host $HOSTS diff --git a/src/ci/docker/dist-android/Dockerfile b/src/ci/docker/dist-android/Dockerfile index 1dd97fd4e0471..a3658225bc47c 100644 --- a/src/ci/docker/dist-android/Dockerfile +++ b/src/ci/docker/dist-android/Dockerfile @@ -1,7 +1,6 @@ FROM ubuntu:16.04 -RUN dpkg --add-architecture i386 && \ - apt-get update && \ +RUN apt-get update && \ apt-get install -y --no-install-recommends \ g++ \ make \ @@ -12,28 +11,30 @@ RUN dpkg --add-architecture i386 && \ git \ cmake \ unzip \ - expect \ - openjdk-9-jre \ sudo \ - libstdc++6:i386 \ xz-utils \ libssl-dev \ pkg-config -WORKDIR /android/ -ENV PATH=$PATH:/android/ndk-arm-9/bin:/android/sdk/tools:/android/sdk/platform-tools - -COPY install-ndk.sh /android/ -RUN sh /android/install-ndk.sh - RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb && \ dpkg -i dumb-init_*.deb && \ rm dumb-init_*.deb -ENTRYPOINT ["/usr/bin/dumb-init", "--"] RUN curl -o /usr/local/bin/sccache \ https://s3.amazonaws.com/rust-lang-ci/rust-ci-mirror/2017-04-29-sccache-x86_64-unknown-linux-musl && \ - chmod +x /usr/local/bin/sccache + chmod +x /usr/local/bin/sccache + +ENTRYPOINT ["/usr/bin/dumb-init", "--"] + +# Install NDK +COPY install-ndk.sh /tmp +RUN . /tmp/install-ndk.sh && \ + download_ndk android-ndk-r13b-linux-x86_64.zip && \ + make_standalone_toolchain arm 9 && \ + make_standalone_toolchain x86 9 && \ + make_standalone_toolchain arm64 21 && \ + make_standalone_toolchain x86_64 21 && \ + remove_ndk ENV TARGETS=arm-linux-androideabi ENV TARGETS=$TARGETS,armv7-linux-androideabi @@ -44,10 +45,10 @@ ENV TARGETS=$TARGETS,x86_64-linux-android ENV RUST_CONFIGURE_ARGS \ --target=$TARGETS \ --enable-extended \ - --arm-linux-androideabi-ndk=/android/ndk-arm-9 \ - --armv7-linux-androideabi-ndk=/android/ndk-arm-9 \ - --i686-linux-android-ndk=/android/ndk-x86-9 \ - --aarch64-linux-android-ndk=/android/ndk-arm64-21 \ - --x86_64-linux-android-ndk=/android/ndk-x86_64-21 + --arm-linux-androideabi-ndk=/android/ndk/arm-9 \ + --armv7-linux-androideabi-ndk=/android/ndk/arm-9 \ + --i686-linux-android-ndk=/android/ndk/x86-9 \ + --aarch64-linux-android-ndk=/android/ndk/arm64-21 \ + --x86_64-linux-android-ndk=/android/ndk/x86_64-21 ENV SCRIPT python2.7 ../x.py dist --target $TARGETS diff --git a/src/ci/docker/dist-android/install-ndk.sh b/src/ci/docker/dist-android/install-ndk.sh index d3a2d31754543..8081872119983 100644 --- a/src/ci/docker/dist-android/install-ndk.sh +++ b/src/ci/docker/dist-android/install-ndk.sh @@ -11,34 +11,25 @@ set -ex -# Prep the Android NDK -# -# See https://github.com/servo/servo/wiki/Building-for-Android -curl -O https://dl.google.com/android/repository/android-ndk-r11c-linux-x86_64.zip -unzip -q android-ndk-r11c-linux-x86_64.zip -bash android-ndk-r11c/build/tools/make-standalone-toolchain.sh \ - --platform=android-9 \ - --toolchain=arm-linux-androideabi-4.9 \ - --install-dir=/android/ndk-arm-9 \ - --ndk-dir=/android/android-ndk-r11c \ - --arch=arm -bash android-ndk-r11c/build/tools/make-standalone-toolchain.sh \ - --platform=android-21 \ - --toolchain=aarch64-linux-android-4.9 \ - --install-dir=/android/ndk-arm64-21 \ - --ndk-dir=/android/android-ndk-r11c \ - --arch=arm64 -bash android-ndk-r11c/build/tools/make-standalone-toolchain.sh \ - --platform=android-9 \ - --toolchain=x86-4.9 \ - --install-dir=/android/ndk-x86-9 \ - --ndk-dir=/android/android-ndk-r11c \ - --arch=x86 -bash android-ndk-r11c/build/tools/make-standalone-toolchain.sh \ - --platform=android-21 \ - --toolchain=x86_64-4.9 \ - --install-dir=/android/ndk-x86_64-21 \ - --ndk-dir=/android/android-ndk-r11c \ - --arch=x86_64 +URL=https://dl.google.com/android/repository + +download_ndk() { + mkdir -p /android/ndk + cd /android/ndk + curl -O $URL/$1 + unzip -q $1 + rm $1 + mv android-ndk-* ndk +} + +make_standalone_toolchain() { + # See https://developer.android.com/ndk/guides/standalone_toolchain.html + python2.7 /android/ndk/ndk/build/tools/make_standalone_toolchain.py \ + --install-dir /android/ndk/$1-$2 \ + --arch $1 \ + --api $2 +} -rm -rf ./android-ndk-r11c-linux-x86_64.zip ./android-ndk-r11c +remove_ndk() { + rm -rf /android/ndk/ndk +} diff --git a/src/ci/docker/run.sh b/src/ci/docker/run.sh index 59b93b784b2f6..6abbf0530afa6 100755 --- a/src/ci/docker/run.sh +++ b/src/ci/docker/run.sh @@ -21,11 +21,27 @@ root_dir="`dirname $src_dir`" source "$ci_dir/shared.sh" -retry docker \ - build \ - --rm \ - -t rust-ci \ - "`dirname "$script"`/$image" +if [ -f "$docker_dir/$image/Dockerfile" ]; then + retry docker \ + build \ + --rm \ + -t rust-ci \ + "$docker_dir/$image" +elif [ -f "$docker_dir/disabled/$image/Dockerfile" ]; then + if [ -n "$TRAVIS_OS_NAME" ]; then + echo Cannot run disabled images on travis! + exit 1 + fi + retry docker \ + build \ + --rm \ + -t rust-ci \ + -f "$docker_dir/disabled/$image/Dockerfile" \ + "$docker_dir" +else + echo Invalid image: $image + exit 1 +fi objdir=$root_dir/obj diff --git a/src/jemalloc b/src/jemalloc index 11bfb0dcf85f7..9986533a625b1 160000 --- a/src/jemalloc +++ b/src/jemalloc @@ -1 +1 @@ -Subproject commit 11bfb0dcf85f7aa92abd30524bb1e42e18d108c6 +Subproject commit 9986533a625b183f7900556c4d2caf87c3cfdf8d diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 6d85183faf75d..27ecefe043b1e 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -54,16 +54,33 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize; /// exception. If you need to mutate through an `Arc`, use [`Mutex`][mutex], /// [`RwLock`][rwlock], or one of the [`Atomic`][atomic] types. /// -/// `Arc` uses atomic operations for reference counting, so `Arc`s can be -/// sent between threads. In other words, `Arc` implements [`Send`] -/// as long as `T` implements [`Send`] and [`Sync`][sync]. The disadvantage is -/// that atomic operations are more expensive than ordinary memory accesses. -/// If you are not sharing reference-counted values between threads, consider -/// using [`rc::Rc`][`Rc`] for lower overhead. [`Rc`] is a safe default, because -/// the compiler will catch any attempt to send an [`Rc`] between threads. -/// However, a library might choose `Arc` in order to give library consumers +/// ## Thread Safety +/// +/// Unlike [`Rc`], `Arc` uses atomic operations for its reference +/// counting This means that it is thread-safe. The disadvantage is that +/// atomic operations are more expensive than ordinary memory accesses. If you +/// are not sharing reference-counted values between threads, consider using +/// [`Rc`] for lower overhead. [`Rc`] is a safe default, because the +/// compiler will catch any attempt to send an [`Rc`] between threads. +/// However, a library might choose `Arc` in order to give library consumers /// more flexibility. /// +/// `Arc` will implement [`Send`] and [`Sync`] as long as the `T` implements +/// [`Send`] and [`Sync`]. Why can't you put a non-thread-safe type `T` in an +/// `Arc` to make it thread-safe? This may be a bit counter-intuitive at +/// first: after all, isn't the point of `Arc` thread safety? The key is +/// this: `Arc` makes it thread safe to have multiple ownership of the same +/// data, but it doesn't add thread safety to its data. Consider +/// `Arc>`. `RefCell` isn't [`Sync`], and if `Arc` was always +/// [`Send`], `Arc>` would be as well. But then we'd have a problem: +/// `RefCell` is not thread safe; it keeps track of the borrowing count using +/// non-atomic operations. +/// +/// In the end, this means that you may need to pair `Arc` with some sort of +/// `std::sync` type, usually `Mutex`. +/// +/// ## Breaking cycles with `Weak` +/// /// The [`downgrade`][downgrade] method can be used to create a non-owning /// [`Weak`][weak] pointer. A [`Weak`][weak] pointer can be [`upgrade`][upgrade]d /// to an `Arc`, but this will return [`None`] if the value has already been @@ -74,6 +91,8 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize; /// strong `Arc` pointers from parent nodes to children, and [`Weak`][weak] /// pointers from children back to their parents. /// +/// ## `Deref` behavior +/// /// `Arc` automatically dereferences to `T` (via the [`Deref`][deref] trait), /// so you can call `T`'s methods on a value of type `Arc`. To avoid name /// clashes with `T`'s methods, the methods of `Arc` itself are [associated @@ -91,13 +110,13 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize; /// /// [arc]: struct.Arc.html /// [weak]: struct.Weak.html -/// [`Rc`]: ../../std/rc/struct.Rc.html +/// [`Rc`]: ../../std/rc/struct.Rc.html /// [clone]: ../../std/clone/trait.Clone.html#tymethod.clone /// [mutex]: ../../std/sync/struct.Mutex.html /// [rwlock]: ../../std/sync/struct.RwLock.html /// [atomic]: ../../std/sync/atomic/index.html /// [`Send`]: ../../std/marker/trait.Send.html -/// [sync]: ../../std/marker/trait.Sync.html +/// [`Sync`]: ../../std/marker/trait.Sync.html /// [deref]: ../../std/ops/trait.Deref.html /// [downgrade]: struct.Arc.html#method.downgrade /// [upgrade]: struct.Weak.html#method.upgrade diff --git a/src/liballoc_jemalloc/build.rs b/src/liballoc_jemalloc/build.rs index f3a0eebe6984d..859e414a6fe7c 100644 --- a/src/liballoc_jemalloc/build.rs +++ b/src/liballoc_jemalloc/build.rs @@ -93,29 +93,7 @@ fn main() { .env("AR", &ar) .env("RANLIB", format!("{} s", ar.display())); - if target.contains("windows") { - // A bit of history here, this used to be --enable-lazy-lock added in - // #14006 which was filed with jemalloc in jemalloc/jemalloc#83 which - // was also reported to MinGW: - // - // http://sourceforge.net/p/mingw-w64/bugs/395/ - // - // When updating jemalloc to 4.0, however, it was found that binaries - // would exit with the status code STATUS_RESOURCE_NOT_OWNED indicating - // that a thread was unlocking a mutex it never locked. Disabling this - // "lazy lock" option seems to fix the issue, but it was enabled by - // default for MinGW targets in 13473c7 for jemalloc. - // - // As a result of all that, force disabling lazy lock on Windows, and - // after reading some code it at least *appears* that the initialization - // of mutexes is otherwise ok in jemalloc, so shouldn't cause problems - // hopefully... - // - // tl;dr: make windows behave like other platforms by disabling lazy - // locking, but requires passing an option due to a historical - // default with jemalloc. - cmd.arg("--disable-lazy-lock"); - } else if target.contains("ios") { + if target.contains("ios") { cmd.arg("--disable-tls"); } else if target.contains("android") { // We force android to have prefixed symbols because apparently diff --git a/src/libcollections/benches/lib.rs b/src/libcollections/benches/lib.rs index 42064e9ca5750..9f356e4b57912 100644 --- a/src/libcollections/benches/lib.rs +++ b/src/libcollections/benches/lib.rs @@ -10,7 +10,9 @@ #![deny(warnings)] +#![feature(i128_type)] #![feature(rand)] +#![feature(repr_simd)] #![feature(sort_unstable)] #![feature(test)] diff --git a/src/libcollections/benches/slice.rs b/src/libcollections/benches/slice.rs index 7195a9f9bf2c6..0079f2d01036c 100644 --- a/src/libcollections/benches/slice.rs +++ b/src/libcollections/benches/slice.rs @@ -290,3 +290,28 @@ sort!(sort_unstable, sort_unstable_large_random, gen_random, 10000); sort!(sort_unstable, sort_unstable_large_big_random, gen_big_random, 10000); sort!(sort_unstable, sort_unstable_large_strings, gen_strings, 10000); sort_expensive!(sort_unstable_by, sort_unstable_large_random_expensive, gen_random, 10000); + +macro_rules! reverse { + ($name:ident, $ty:ty, $f:expr) => { + #[bench] + fn $name(b: &mut Bencher) { + // odd length and offset by 1 to be as unaligned as possible + let n = 0xFFFFF; + let mut v: Vec<_> = + (0..1+(n / mem::size_of::<$ty>() as u64)) + .map($f) + .collect(); + b.iter(|| black_box(&mut v[1..]).reverse()); + b.bytes = n; + } + } +} + +reverse!(reverse_u8, u8, |x| x as u8); +reverse!(reverse_u16, u16, |x| x as u16); +reverse!(reverse_u8x3, [u8;3], |x| [x as u8, (x>>8) as u8, (x>>16) as u8]); +reverse!(reverse_u32, u32, |x| x as u32); +reverse!(reverse_u64, u64, |x| x as u64); +reverse!(reverse_u128, u128, |x| x as u128); +#[repr(simd)] struct F64x4(f64, f64, f64, f64); +reverse!(reverse_simd_f64x4, F64x4, |x| { let x = x as f64; F64x4(x,x,x,x) }); diff --git a/src/libcollections/tests/slice.rs b/src/libcollections/tests/slice.rs index c3e5304fb2b35..1708f98b7ee47 100644 --- a/src/libcollections/tests/slice.rs +++ b/src/libcollections/tests/slice.rs @@ -379,6 +379,16 @@ fn test_reverse() { let mut v3 = Vec::::new(); v3.reverse(); assert!(v3.is_empty()); + + // check the 1-byte-types path + let mut v = (-50..51i8).collect::>(); + v.reverse(); + assert_eq!(v, (-50..51i8).rev().collect::>()); + + // check the 2-byte-types path + let mut v = (-50..51i16).collect::>(); + v.reverse(); + assert_eq!(v, (-50..51i16).rev().collect::>()); } #[test] diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 9e3bd9115468a..e15eb8f244409 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -539,6 +539,55 @@ impl SliceExt for [T] { fn reverse(&mut self) { let mut i: usize = 0; let ln = self.len(); + + // For very small types, all the individual reads in the normal + // path perform poorly. We can do better, given efficient unaligned + // load/store, by loading a larger chunk and reversing a register. + + // Ideally LLVM would do this for us, as it knows better than we do + // whether unaligned reads are efficient (since that changes between + // different ARM versions, for example) and what the best chunk size + // would be. Unfortunately, as of LLVM 4.0 (2017-05) it only unrolls + // the loop, so we need to do this ourselves. (Hypothesis: reverse + // is troublesome because the sides can be aligned differently -- + // will be, when the length is odd -- so there's no way of emitting + // pre- and postludes to use fully-aligned SIMD in the middle.) + + let fast_unaligned = + cfg!(any(target_arch = "x86", target_arch = "x86_64")); + + if fast_unaligned && mem::size_of::() == 1 { + // Use the llvm.bswap intrinsic to reverse u8s in a usize + let chunk = mem::size_of::(); + while i + chunk - 1 < ln / 2 { + unsafe { + let pa: *mut T = self.get_unchecked_mut(i); + let pb: *mut T = self.get_unchecked_mut(ln - i - chunk); + let va = ptr::read_unaligned(pa as *mut usize); + let vb = ptr::read_unaligned(pb as *mut usize); + ptr::write_unaligned(pa as *mut usize, vb.swap_bytes()); + ptr::write_unaligned(pb as *mut usize, va.swap_bytes()); + } + i += chunk; + } + } + + if fast_unaligned && mem::size_of::() == 2 { + // Use rotate-by-16 to reverse u16s in a u32 + let chunk = mem::size_of::() / 2; + while i + chunk - 1 < ln / 2 { + unsafe { + let pa: *mut T = self.get_unchecked_mut(i); + let pb: *mut T = self.get_unchecked_mut(ln - i - chunk); + let va = ptr::read_unaligned(pa as *mut u32); + let vb = ptr::read_unaligned(pb as *mut u32); + ptr::write_unaligned(pa as *mut u32, vb.rotate_left(16)); + ptr::write_unaligned(pb as *mut u32, va.rotate_left(16)); + } + i += chunk; + } + } + while i < ln / 2 { // Unsafe swap to avoid the bounds check in safe swap. unsafe { diff --git a/src/librustc/infer/error_reporting/note.rs b/src/librustc/infer/error_reporting/note.rs index 49952d81cbb0b..963c14c48c829 100644 --- a/src/librustc/infer/error_reporting/note.rs +++ b/src/librustc/infer/error_reporting/note.rs @@ -9,7 +9,7 @@ // except according to those terms. use infer::{self, InferCtxt, SubregionOrigin}; -use ty::Region; +use ty::{self, Region}; use ty::error::TypeError; use errors::DiagnosticBuilder; @@ -262,7 +262,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { "the type `{}` does not fulfill the required \ lifetime", self.ty_to_string(ty)); - self.tcx.note_and_explain_region(&mut err, "type must outlive ", sub, ""); + match *sub { + ty::ReStatic => { + self.tcx.note_and_explain_region(&mut err, "type must satisfy ", sub, "") + } + _ => { + self.tcx.note_and_explain_region(&mut err, "type must outlive ", sub, "") + } + } err } infer::RelateRegionParamBound(span) => { diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 9d66430bc9303..f4b9a8972e3ab 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -51,10 +51,17 @@ //! ``` //! use std::path::PathBuf; //! +//! // This way works... //! let mut path = PathBuf::from("c:\\"); +//! //! path.push("windows"); //! path.push("system32"); +//! //! path.set_extension("dll"); +//! +//! // ... but push is best used if you don't know everything up +//! // front. If you do, this way is better: +//! let path: PathBuf = ["c:\\", "windows", "system32.dll"].iter().collect(); //! ``` //! //! [`Component`]: ../../std/path/enum.Component.html @@ -63,6 +70,7 @@ //! [`Path`]: ../../std/path/struct.Path.html //! [`push`]: ../../std/path/struct.PathBuf.html#method.push //! [`String`]: ../../std/string/struct.String.html +//! //! [`str`]: ../../std/primitive.str.html //! [`OsString`]: ../../std/ffi/struct.OsString.html //! [`OsStr`]: ../../std/ffi/struct.OsStr.html @@ -1036,14 +1044,40 @@ impl<'a> cmp::Ord for Components<'a> { /// /// # Examples /// +/// You can use [`push`] to build up a `PathBuf` from +/// components: +/// /// ``` /// use std::path::PathBuf; /// -/// let mut path = PathBuf::from("c:\\"); +/// let mut path = PathBuf::new(); +/// +/// path.push(r"C:\"); /// path.push("windows"); /// path.push("system32"); +/// /// path.set_extension("dll"); /// ``` +/// +/// However, [`push`] is best used for dynamic situations. This is a better way +/// to do this when you know all of the components ahead of time: +/// +/// ``` +/// use std::path::PathBuf; +/// +/// let path: PathBuf = [r"C:\", "windows", "system32.dll"].iter().collect(); +/// ``` +/// +/// We can still do better than this! Since these are all strings, we can use +/// `From::from`: +/// +/// ``` +/// use std::path::PathBuf; +/// +/// let path = PathBuf::from(r"C:\windows\system32.dll"); +/// ``` +/// +/// Which method works best depends on what kind of situation you're in. #[derive(Clone)] #[stable(feature = "rust1", since = "1.0.0")] pub struct PathBuf { diff --git a/src/libstd/rt.rs b/src/libstd/rt.rs index 6c791cd336ded..acff7faf8a7d0 100644 --- a/src/libstd/rt.rs +++ b/src/libstd/rt.rs @@ -29,8 +29,7 @@ pub use panicking::{begin_panic, begin_panic_fmt, update_panic_count}; #[cfg(not(test))] #[lang = "start"] -fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize { - use mem; +fn lang_start(main: fn(), argc: isize, argv: *const *const u8) -> isize { use panic; use sys; use sys_common; @@ -54,7 +53,9 @@ fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize { sys::args::init(argc, argv); // Let's run some code! - let res = panic::catch_unwind(mem::transmute::<_, fn()>(main)); + let res = panic::catch_unwind(|| { + ::sys_common::backtrace::__rust_begin_short_backtrace(main) + }); sys_common::cleanup(); res.is_err() }; diff --git a/src/libstd/sys_common/backtrace.rs b/src/libstd/sys_common/backtrace.rs index 04fe5f78b03ce..617218fe7a5a6 100644 --- a/src/libstd/sys_common/backtrace.rs +++ b/src/libstd/sys_common/backtrace.rs @@ -93,11 +93,47 @@ fn _print(w: &mut Write, format: PrintFormat) -> io::Result<()> { Ok(()) } -fn filter_frames(_frames: &[Frame], - _format: PrintFormat, - _context: &BacktraceContext) -> (usize, usize) +/// Returns a number of frames to remove at the beginning and at the end of the +/// backtrace, according to the backtrace format. +fn filter_frames(frames: &[Frame], + format: PrintFormat, + context: &BacktraceContext) -> (usize, usize) { - (0, 0) + if format == PrintFormat::Full { + return (0, 0); + } + + let skipped_before = 0; + + let skipped_after = frames.len() - frames.iter().position(|frame| { + let mut is_marker = false; + let _ = resolve_symname(*frame, |symname| { + if let Some(mangled_symbol_name) = symname { + // Use grep to find the concerned functions + if mangled_symbol_name.contains("__rust_begin_short_backtrace") { + is_marker = true; + } + } + Ok(()) + }, context); + is_marker + }).unwrap_or(frames.len()); + + if skipped_before + skipped_after >= frames.len() { + // Avoid showing completely empty backtraces + return (0, 0); + } + + (skipped_before, skipped_after) +} + + +/// Fixed frame used to clean the backtrace with `RUST_BACKTRACE=1`. +#[inline(never)] +pub fn __rust_begin_short_backtrace(f: F) -> T + where F: FnOnce() -> T, F: Send + 'static, T: Send + 'static +{ + f() } /// Controls how the backtrace should be formated. diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 1bb0d9f3babfd..6e0ad0789e420 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -96,41 +96,6 @@ //! The [`thread::current`] function is available even for threads not spawned //! by the APIs of this module. //! -//! ## Blocking support: park and unpark -//! -//! Every thread is equipped with some basic low-level blocking support, via the -//! [`thread::park`][`park`] function and [`thread::Thread::unpark()`][`unpark`] -//! method. [`park`] blocks the current thread, which can then be resumed from -//! another thread by calling the [`unpark`] method on the blocked thread's handle. -//! -//! Conceptually, each [`Thread`] handle has an associated token, which is -//! initially not present: -//! -//! * The [`thread::park`][`park`] function blocks the current thread unless or until -//! the token is available for its thread handle, at which point it atomically -//! consumes the token. It may also return *spuriously*, without consuming the -//! token. [`thread::park_timeout`] does the same, but allows specifying a -//! maximum time to block the thread for. -//! -//! * The [`unpark`] method on a [`Thread`] atomically makes the token available -//! if it wasn't already. -//! -//! In other words, each [`Thread`] acts a bit like a semaphore with initial count -//! 0, except that the semaphore is *saturating* (the count cannot go above 1), -//! and can return spuriously. -//! -//! The API is typically used by acquiring a handle to the current thread, -//! placing that handle in a shared data structure so that other threads can -//! find it, and then `park`ing. When some desired condition is met, another -//! thread calls [`unpark`] on the handle. -//! -//! The motivation for this design is twofold: -//! -//! * It avoids the need to allocate mutexes and condvars when building new -//! synchronization primitives; the threads already provide basic blocking/signaling. -//! -//! * It can be implemented very efficiently on many platforms. -//! //! ## Thread-local storage //! //! This module also provides an implementation of thread-local storage for Rust @@ -365,7 +330,9 @@ impl Builder { } unsafe { thread_info::set(imp::guard::current(), their_thread); - let try_result = panic::catch_unwind(panic::AssertUnwindSafe(f)); + let try_result = panic::catch_unwind(panic::AssertUnwindSafe(|| { + ::sys_common::backtrace::__rust_begin_short_backtrace(f) + })); *their_packet.get() = Some(try_result); } }; @@ -566,23 +533,72 @@ pub fn sleep(dur: Duration) { /// Blocks unless or until the current thread's token is made available. /// -/// Every thread is equipped with some basic low-level blocking support, via -/// the `park()` function and the [`unpark`][unpark] method. These can be -/// used as a more CPU-efficient implementation of a spinlock. +/// A call to `park` does not guarantee that the thread will remain parked +/// forever, and callers should be prepared for this possibility. +/// +/// # park and unpark +/// +/// Every thread is equipped with some basic low-level blocking support, via the +/// [`thread::park`][`park`] function and [`thread::Thread::unpark`][`unpark`] +/// method. [`park`] blocks the current thread, which can then be resumed from +/// another thread by calling the [`unpark`] method on the blocked thread's +/// handle. +/// +/// Conceptually, each [`Thread`] handle has an associated token, which is +/// initially not present: /// -/// [unpark]: struct.Thread.html#method.unpark +/// * The [`thread::park`][`park`] function blocks the current thread unless or +/// until the token is available for its thread handle, at which point it +/// atomically consumes the token. It may also return *spuriously*, without +/// consuming the token. [`thread::park_timeout`] does the same, but allows +/// specifying a maximum time to block the thread for. +/// +/// * The [`unpark`] method on a [`Thread`] atomically makes the token available +/// if it wasn't already. +/// +/// In other words, each [`Thread`] acts a bit like a spinlock that can be +/// locked and unlocked using `park` and `unpark`. /// /// The API is typically used by acquiring a handle to the current thread, /// placing that handle in a shared data structure so that other threads can -/// find it, and then parking (in a loop with a check for the token actually -/// being acquired). +/// find it, and then `park`ing. When some desired condition is met, another +/// thread calls [`unpark`] on the handle. /// -/// A call to `park` does not guarantee that the thread will remain parked -/// forever, and callers should be prepared for this possibility. +/// The motivation for this design is twofold: +/// +/// * It avoids the need to allocate mutexes and condvars when building new +/// synchronization primitives; the threads already provide basic +/// blocking/signaling. /// -/// See the [module documentation][thread] for more detail. +/// * It can be implemented very efficiently on many platforms. /// -/// [thread]: index.html +/// # Examples +/// +/// ``` +/// use std::thread; +/// use std::time::Duration; +/// +/// let parked_thread = thread::Builder::new() +/// .spawn(|| { +/// println!("Parking thread"); +/// thread::park(); +/// println!("Thread unparked"); +/// }) +/// .unwrap(); +/// +/// // Let some time pass for the thread to be spawned. +/// thread::sleep(Duration::from_millis(10)); +/// +/// println!("Unpark the thread"); +/// parked_thread.thread().unpark(); +/// +/// parked_thread.join().unwrap(); +/// ``` +/// +/// [`Thread`]: ../../std/thread/struct.Thread.html +/// [`park`]: ../../std/thread/fn.park.html +/// [`unpark`]: ../../std/thread/struct.Thread.html#method.unpark +/// [`thread::park_timeout`]: ../../std/thread/fn.park_timeout.html // // The implementation currently uses the trivial strategy of a Mutex+Condvar // with wakeup flag, which does not actually allow spurious wakeups. In the @@ -599,21 +615,21 @@ pub fn park() { *guard = false; } -/// Use [park_timeout]. +/// Use [`park_timeout`]. /// /// Blocks unless or until the current thread's token is made available or /// the specified duration has been reached (may wake spuriously). /// -/// The semantics of this function are equivalent to `park()` except that the -/// thread will be blocked for roughly no longer than `ms`. This method -/// should not be used for precise timing due to anomalies such as +/// The semantics of this function are equivalent to [`park`] except +/// that the thread will be blocked for roughly no longer than `dur`. This +/// method should not be used for precise timing due to anomalies such as /// preemption or platform differences that may not cause the maximum /// amount of time waited to be precisely `ms` long. /// -/// See the [module documentation][thread] for more detail. +/// See the [park documentation][`park`] for more detail. /// -/// [thread]: index.html -/// [park_timeout]: fn.park_timeout.html +/// [`park_timeout`]: fn.park_timeout.html +/// [`park`]: ../../std/thread/fn.park.html #[stable(feature = "rust1", since = "1.0.0")] #[rustc_deprecated(since = "1.6.0", reason = "replaced by `std::thread::park_timeout`")] pub fn park_timeout_ms(ms: u32) { @@ -623,13 +639,13 @@ pub fn park_timeout_ms(ms: u32) { /// Blocks unless or until the current thread's token is made available or /// the specified duration has been reached (may wake spuriously). /// -/// The semantics of this function are equivalent to `park()` except that the -/// thread will be blocked for roughly no longer than `dur`. This method -/// should not be used for precise timing due to anomalies such as +/// The semantics of this function are equivalent to [`park`][park] except +/// that the thread will be blocked for roughly no longer than `dur`. This +/// method should not be used for precise timing due to anomalies such as /// preemption or platform differences that may not cause the maximum /// amount of time waited to be precisely `dur` long. /// -/// See the module doc for more detail. +/// See the [park dococumentation][park] for more details. /// /// # Platform behavior /// @@ -654,6 +670,8 @@ pub fn park_timeout_ms(ms: u32) { /// park_timeout(timeout); /// } /// ``` +/// +/// [park]: fn.park.html #[stable(feature = "park_timeout", since = "1.4.0")] pub fn park_timeout(dur: Duration) { let thread = current(); @@ -775,22 +793,36 @@ impl Thread { /// Atomically makes the handle's token available if it is not already. /// - /// See the module doc for more detail. + /// Every thread is equipped with some basic low-level blocking support, via + /// the [`park`][park] function and the `unpark()` method. These can be + /// used as a more CPU-efficient implementation of a spinlock. + /// + /// See the [park documentation][park] for more details. /// /// # Examples /// /// ``` /// use std::thread; + /// use std::time::Duration; /// - /// let handler = thread::Builder::new() + /// let parked_thread = thread::Builder::new() /// .spawn(|| { - /// let thread = thread::current(); - /// thread.unpark(); + /// println!("Parking thread"); + /// thread::park(); + /// println!("Thread unparked"); /// }) /// .unwrap(); /// - /// handler.join().unwrap(); + /// // Let some time pass for the thread to be spawned. + /// thread::sleep(Duration::from_millis(10)); + /// + /// println!("Unpark the thread"); + /// parked_thread.thread().unpark(); + /// + /// parked_thread.join().unwrap(); /// ``` + /// + /// [park]: fn.park.html #[stable(feature = "rust1", since = "1.0.0")] pub fn unpark(&self) { let mut guard = self.inner.lock.lock().unwrap(); diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 35f2fbca69f8d..0d615db3deb47 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -1314,12 +1314,16 @@ pub fn convert_benchmarks_to_tests(tests: Vec) -> Vec { DynTestFn(Box::new(move |()| { - bench::run_once(|b| bench.run(b)) + bench::run_once(|b| { + __rust_begin_short_backtrace(|| bench.run(b)) + }) })) } StaticBenchFn(benchfn) => { DynTestFn(Box::new(move |()| { - bench::run_once(|b| benchfn(b)) + bench::run_once(|b| { + __rust_begin_short_backtrace(|| benchfn(b)) + }) })) } f => f, @@ -1425,12 +1429,24 @@ pub fn run_test(opts: &TestOpts, monitor_ch.send((desc, TrMetrics(mm), Vec::new())).unwrap(); return; } - DynTestFn(f) => run_test_inner(desc, monitor_ch, opts.nocapture, f), - StaticTestFn(f) => run_test_inner(desc, monitor_ch, opts.nocapture, - Box::new(move |()| f())), + DynTestFn(f) => { + let cb = move |()| { + __rust_begin_short_backtrace(|| f.call_box(())) + }; + run_test_inner(desc, monitor_ch, opts.nocapture, Box::new(cb)) + } + StaticTestFn(f) => + run_test_inner(desc, monitor_ch, opts.nocapture, + Box::new(move |()| __rust_begin_short_backtrace(f))), } } +/// Fixed frame used to clean the backtrace with `RUST_BACKTRACE=1`. +#[inline(never)] +fn __rust_begin_short_backtrace(f: F) { + f() +} + fn calc_result(desc: &TestDesc, task_result: Result<(), Box>) -> TestResult { match (&desc.should_panic, task_result) { (&ShouldPanic::No, Ok(())) | diff --git a/src/test/ui/static-lifetime.rs b/src/test/ui/static-lifetime.rs new file mode 100644 index 0000000000000..7b1887b2d1a29 --- /dev/null +++ b/src/test/ui/static-lifetime.rs @@ -0,0 +1,16 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub trait Arbitrary: Sized + 'static {} + +impl<'a, A: Clone> Arbitrary for ::std::borrow::Cow<'a, A> {} + +fn main() { +} \ No newline at end of file diff --git a/src/test/ui/static-lifetime.stderr b/src/test/ui/static-lifetime.stderr new file mode 100644 index 0000000000000..f73dff4f73d0e --- /dev/null +++ b/src/test/ui/static-lifetime.stderr @@ -0,0 +1,10 @@ +error[E0477]: the type `std::borrow::Cow<'a, A>` does not fulfill the required lifetime + --> $DIR/static-lifetime.rs:13:20 + | +13 | impl<'a, A: Clone> Arbitrary for ::std::borrow::Cow<'a, A> {} + | ^^^^^^^^^ + | + = note: type must satisfy the static lifetime + +error: aborting due to previous error + diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index a044282666da0..7fe8c1041a729 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -570,7 +570,7 @@ actual:\n\ format!("-command={}", debugger_script.to_str().unwrap())]; let mut gdb_path = tool_path; - gdb_path.push_str(&format!("/bin/{}-gdb", self.config.target)); + gdb_path.push_str("/bin/gdb"); let procsrv::Result { out, err,