diff --git a/src/ci/docker/dist-i686-freebsd/Dockerfile b/src/ci/docker/dist-i686-freebsd/Dockerfile index b82d227b3ef2..686afc97289b 100644 --- a/src/ci/docker/dist-i686-freebsd/Dockerfile +++ b/src/ci/docker/dist-i686-freebsd/Dockerfile @@ -1,7 +1,7 @@ FROM ubuntu:16.04 RUN apt-get update && apt-get install -y --no-install-recommends \ - g++ \ + clang \ make \ file \ curl \ @@ -16,16 +16,16 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libssl-dev \ pkg-config -COPY dist-i686-freebsd/build-toolchain.sh /tmp/ -RUN /tmp/build-toolchain.sh i686 +COPY scripts/freebsd-toolchain.sh /tmp/ +RUN /tmp/freebsd-toolchain.sh i686 COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh ENV \ AR_i686_unknown_freebsd=i686-unknown-freebsd10-ar \ - CC_i686_unknown_freebsd=i686-unknown-freebsd10-gcc \ - CXX_i686_unknown_freebsd=i686-unknown-freebsd10-g++ + CC_i686_unknown_freebsd=i686-unknown-freebsd10-clang \ + CXX_i686_unknown_freebsd=i686-unknown-freebsd10-clang++ ENV HOSTS=i686-unknown-freebsd diff --git a/src/ci/docker/dist-i686-freebsd/build-toolchain.sh b/src/ci/docker/dist-i686-freebsd/build-toolchain.sh deleted file mode 100755 index 8343327c33bf..000000000000 --- a/src/ci/docker/dist-i686-freebsd/build-toolchain.sh +++ /dev/null @@ -1,112 +0,0 @@ -#!/bin/bash -# 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. - -set -ex - -ARCH=$1 -BINUTILS=2.25.1 -GCC=6.4.0 - -hide_output() { - set +x - on_err=" -echo ERROR: An error was encountered with the build. -cat /tmp/build.log -exit 1 -" - trap "$on_err" ERR - bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & - PING_LOOP_PID=$! - $@ &> /tmp/build.log - trap - ERR - kill $PING_LOOP_PID - set -x -} - -mkdir binutils -cd binutils - -# First up, build binutils -curl https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS.tar.bz2 | tar xjf - -mkdir binutils-build -cd binutils-build -hide_output ../binutils-$BINUTILS/configure \ - --target=$ARCH-unknown-freebsd10 -hide_output make -j10 -hide_output make install -cd ../.. -rm -rf binutils - -# Next, download the FreeBSD libc and relevant header files - -mkdir freebsd -case "$ARCH" in - x86_64) - URL=ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/10.2-RELEASE/base.txz - ;; - i686) - URL=ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/10.2-RELEASE/base.txz - ;; -esac -curl $URL | tar xJf - -C freebsd ./usr/include ./usr/lib ./lib - -dst=/usr/local/$ARCH-unknown-freebsd10 - -cp -r freebsd/usr/include $dst/ -cp freebsd/usr/lib/crt1.o $dst/lib -cp freebsd/usr/lib/Scrt1.o $dst/lib -cp freebsd/usr/lib/crti.o $dst/lib -cp freebsd/usr/lib/crtn.o $dst/lib -cp freebsd/usr/lib/libc.a $dst/lib -cp freebsd/usr/lib/libutil.a $dst/lib -cp freebsd/usr/lib/libutil_p.a $dst/lib -cp freebsd/usr/lib/libm.a $dst/lib -cp freebsd/usr/lib/librt.so.1 $dst/lib -cp freebsd/usr/lib/libexecinfo.so.1 $dst/lib -cp freebsd/lib/libc.so.7 $dst/lib -cp freebsd/lib/libm.so.5 $dst/lib -cp freebsd/lib/libutil.so.9 $dst/lib -cp freebsd/lib/libthr.so.3 $dst/lib/libpthread.so - -ln -s libc.so.7 $dst/lib/libc.so -ln -s libm.so.5 $dst/lib/libm.so -ln -s librt.so.1 $dst/lib/librt.so -ln -s libutil.so.9 $dst/lib/libutil.so -ln -s libexecinfo.so.1 $dst/lib/libexecinfo.so -rm -rf freebsd - -# Finally, download and build gcc to target FreeBSD -mkdir gcc -cd gcc -curl https://ftp.gnu.org/gnu/gcc/gcc-$GCC/gcc-$GCC.tar.gz | tar xzf - -cd gcc-$GCC -./contrib/download_prerequisites - -mkdir ../gcc-build -cd ../gcc-build -hide_output ../gcc-$GCC/configure \ - --enable-languages=c,c++ \ - --target=$ARCH-unknown-freebsd10 \ - --disable-multilib \ - --disable-nls \ - --disable-libgomp \ - --disable-libquadmath \ - --disable-libssp \ - --disable-libvtv \ - --disable-libcilkrts \ - --disable-libada \ - --disable-libsanitizer \ - --disable-libquadmath-support \ - --disable-lto -hide_output make -j10 -hide_output make install -cd ../.. -rm -rf gcc diff --git a/src/ci/docker/dist-x86_64-freebsd/Dockerfile b/src/ci/docker/dist-x86_64-freebsd/Dockerfile index b7c00df4db24..7483d395622c 100644 --- a/src/ci/docker/dist-x86_64-freebsd/Dockerfile +++ b/src/ci/docker/dist-x86_64-freebsd/Dockerfile @@ -1,7 +1,7 @@ FROM ubuntu:16.04 RUN apt-get update && apt-get install -y --no-install-recommends \ - g++ \ + clang \ make \ file \ curl \ @@ -16,16 +16,16 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libssl-dev \ pkg-config -COPY dist-x86_64-freebsd/build-toolchain.sh /tmp/ -RUN /tmp/build-toolchain.sh x86_64 +COPY scripts/freebsd-toolchain.sh /tmp/ +RUN /tmp/freebsd-toolchain.sh x86_64 COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh ENV \ AR_x86_64_unknown_freebsd=x86_64-unknown-freebsd10-ar \ - CC_x86_64_unknown_freebsd=x86_64-unknown-freebsd10-gcc \ - CXX_x86_64_unknown_freebsd=x86_64-unknown-freebsd10-g++ + CC_x86_64_unknown_freebsd=x86_64-unknown-freebsd10-clang \ + CXX_x86_64_unknown_freebsd=x86_64-unknown-freebsd10-clang++ ENV HOSTS=x86_64-unknown-freebsd diff --git a/src/ci/docker/dist-x86_64-freebsd/build-toolchain.sh b/src/ci/docker/dist-x86_64-freebsd/build-toolchain.sh deleted file mode 100755 index 8343327c33bf..000000000000 --- a/src/ci/docker/dist-x86_64-freebsd/build-toolchain.sh +++ /dev/null @@ -1,112 +0,0 @@ -#!/bin/bash -# 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. - -set -ex - -ARCH=$1 -BINUTILS=2.25.1 -GCC=6.4.0 - -hide_output() { - set +x - on_err=" -echo ERROR: An error was encountered with the build. -cat /tmp/build.log -exit 1 -" - trap "$on_err" ERR - bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & - PING_LOOP_PID=$! - $@ &> /tmp/build.log - trap - ERR - kill $PING_LOOP_PID - set -x -} - -mkdir binutils -cd binutils - -# First up, build binutils -curl https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS.tar.bz2 | tar xjf - -mkdir binutils-build -cd binutils-build -hide_output ../binutils-$BINUTILS/configure \ - --target=$ARCH-unknown-freebsd10 -hide_output make -j10 -hide_output make install -cd ../.. -rm -rf binutils - -# Next, download the FreeBSD libc and relevant header files - -mkdir freebsd -case "$ARCH" in - x86_64) - URL=ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/10.2-RELEASE/base.txz - ;; - i686) - URL=ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/10.2-RELEASE/base.txz - ;; -esac -curl $URL | tar xJf - -C freebsd ./usr/include ./usr/lib ./lib - -dst=/usr/local/$ARCH-unknown-freebsd10 - -cp -r freebsd/usr/include $dst/ -cp freebsd/usr/lib/crt1.o $dst/lib -cp freebsd/usr/lib/Scrt1.o $dst/lib -cp freebsd/usr/lib/crti.o $dst/lib -cp freebsd/usr/lib/crtn.o $dst/lib -cp freebsd/usr/lib/libc.a $dst/lib -cp freebsd/usr/lib/libutil.a $dst/lib -cp freebsd/usr/lib/libutil_p.a $dst/lib -cp freebsd/usr/lib/libm.a $dst/lib -cp freebsd/usr/lib/librt.so.1 $dst/lib -cp freebsd/usr/lib/libexecinfo.so.1 $dst/lib -cp freebsd/lib/libc.so.7 $dst/lib -cp freebsd/lib/libm.so.5 $dst/lib -cp freebsd/lib/libutil.so.9 $dst/lib -cp freebsd/lib/libthr.so.3 $dst/lib/libpthread.so - -ln -s libc.so.7 $dst/lib/libc.so -ln -s libm.so.5 $dst/lib/libm.so -ln -s librt.so.1 $dst/lib/librt.so -ln -s libutil.so.9 $dst/lib/libutil.so -ln -s libexecinfo.so.1 $dst/lib/libexecinfo.so -rm -rf freebsd - -# Finally, download and build gcc to target FreeBSD -mkdir gcc -cd gcc -curl https://ftp.gnu.org/gnu/gcc/gcc-$GCC/gcc-$GCC.tar.gz | tar xzf - -cd gcc-$GCC -./contrib/download_prerequisites - -mkdir ../gcc-build -cd ../gcc-build -hide_output ../gcc-$GCC/configure \ - --enable-languages=c,c++ \ - --target=$ARCH-unknown-freebsd10 \ - --disable-multilib \ - --disable-nls \ - --disable-libgomp \ - --disable-libquadmath \ - --disable-libssp \ - --disable-libvtv \ - --disable-libcilkrts \ - --disable-libada \ - --disable-libsanitizer \ - --disable-libquadmath-support \ - --disable-lto -hide_output make -j10 -hide_output make install -cd ../.. -rm -rf gcc diff --git a/src/ci/docker/scripts/freebsd-toolchain.sh b/src/ci/docker/scripts/freebsd-toolchain.sh new file mode 100755 index 000000000000..15ed318f8ce8 --- /dev/null +++ b/src/ci/docker/scripts/freebsd-toolchain.sh @@ -0,0 +1,103 @@ +#!/bin/bash +# Copyright 2016-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 -eux + +arch=$1 +binutils_version=2.25.1 +freebsd_version=10.3 +triple=$arch-unknown-freebsd10 +sysroot=/usr/local/$triple + +hide_output() { + set +x + local on_err=" +echo ERROR: An error was encountered with the build. +cat /tmp/build.log +exit 1 +" + trap "$on_err" ERR + bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & + local ping_loop_pid=$! + $@ &> /tmp/build.log + trap - ERR + kill $ping_loop_pid + set -x +} + +# First up, build binutils +mkdir binutils +cd binutils +curl https://ftp.gnu.org/gnu/binutils/binutils-${binutils_version}.tar.bz2 | tar xjf - +mkdir binutils-build +cd binutils-build +hide_output ../binutils-${binutils_version}/configure \ + --target="$triple" --with-sysroot="$sysroot" +hide_output make -j"$(getconf _NPROCESSORS_ONLN)" +hide_output make install +cd ../.. +rm -rf binutils + +# Next, download the FreeBSD libraries and header files +mkdir -p "$sysroot" +case $arch in + (x86_64) freebsd_arch=amd64 ;; + (i686) freebsd_arch=i386 ;; +esac + +files_to_extract=( +"./usr/include" +"./usr/lib/*crt*.o" +) +# Try to unpack only the libraries the build needs, to save space. +for lib in c cxxrt gcc_s m thr util; do + files_to_extract=("${files_to_extract[@]}" "./lib/lib${lib}.*" "./usr/lib/lib${lib}.*") +done +for lib in c++ c_nonshared compiler_rt execinfo gcc pthread rt ssp_nonshared; do + files_to_extract=("${files_to_extract[@]}" "./usr/lib/lib${lib}.*") +done + +URL=https://download.freebsd.org/ftp/releases/${freebsd_arch}/${freebsd_version}-RELEASE/base.txz +curl "$URL" | tar xJf - -C "$sysroot" --wildcards "${files_to_extract[@]}" + +# Fix up absolute symlinks from the system image. This can be removed +# for FreeBSD 11. (If there's an easy way to make them relative +# symlinks instead, feel free to change this.) +set +x +find "$sysroot" -type l | while read symlink_path; do + symlink_target=$(readlink "$symlink_path") + case $symlink_target in + (/*) + echo "Fixing symlink ${symlink_path} -> ${sysroot}${symlink_target}" >&2 + ln -nfs "${sysroot}${symlink_target}" "${symlink_path}" ;; + esac +done +set -x + +# Clang can do cross-builds out of the box, if we give it the right +# flags. (The local binutils seem to work, but they set the ELF +# header "OS/ABI" (EI_OSABI) field to SysV rather than FreeBSD, so +# there might be other problems.) +# +# The --target option is last because the cross-build of LLVM uses +# --target without an OS version ("-freebsd" vs. "-freebsd10"). This +# makes Clang default to libstdc++ (which no longer exists), and also +# controls other features, like GNU-style symbol table hashing and +# anything predicated on the version number in the __FreeBSD__ +# preprocessor macro. +for tool in clang clang++; do + tool_path=/usr/local/bin/${triple}-${tool} + cat > "$tool_path" <