Skip to content

Commit

Permalink
Rollup merge of rust-lang#39918 - petrhosek:fuchsia-ci, r=alexcrichton
Browse files Browse the repository at this point in the history
travis: Fuchsia builder

This change introduces a Dockerfile and script which builds a complete
Fuchsia toolchain which can be used to build Rust distribution for
Fuchsia. We only support cross-compiling at the moment, hence only
setting the target.
  • Loading branch information
frewsxcv authored Feb 28, 2017
2 parents 4be034e + 7803039 commit 1a2a2e4
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/ci/docker/cross/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ FROM ubuntu:16.04
RUN apt-get update && apt-get install -y --no-install-recommends \
g++ \
make \
ninja-build \
file \
curl \
ca-certificates \
python2.7 \
python2.7-dev \
git \
cmake \
sudo \
xz-utils \
zlib1g-dev \
Expand All @@ -19,7 +19,15 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
bzip2 \
patch \
libssl-dev \
pkg-config
pkg-config \
swig \
libedit-dev \
libncurses5-dev

# CMake 3.8.0 is the first version with official support for Fuchsia,
# which is needed to build the Fuchsia toolchain.
RUN curl -L https://cmake.org/files/v3.8/cmake-3.8.0-rc1-Linux-x86_64.tar.gz | \
tar xzf - -C /usr/local --strip-components=1

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 && \
Expand All @@ -31,6 +39,10 @@ RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-ini
ENTRYPOINT ["/usr/bin/dumb-init", "--"]

WORKDIR /tmp
COPY shared.sh /tmp/

COPY build-fuchsia.sh /tmp/
RUN ./build-fuchsia.sh

COPY build-rumprun.sh /tmp/
RUN ./build-rumprun.sh
Expand Down Expand Up @@ -65,10 +77,18 @@ ENV TARGETS=$TARGETS,arm-unknown-linux-musleabi
ENV TARGETS=$TARGETS,arm-unknown-linux-musleabihf
ENV TARGETS=$TARGETS,armv7-unknown-linux-musleabihf
ENV TARGETS=$TARGETS,sparc64-unknown-linux-gnu
ENV TARGETS=$TARGETS,x86_64-unknown-fuchsia
ENV TARGETS=$TARGETS,aarch64-unknown-fuchsia

ENV CC_mipsel_unknown_linux_musl=mipsel-openwrt-linux-gcc \
CC_mips_unknown_linux_musl=mips-openwrt-linux-gcc \
CC_sparc64_unknown_linux_gnu=sparc64-linux-gnu-gcc
CC_sparc64_unknown_linux_gnu=sparc64-linux-gnu-gcc \
AR_x86_64_unknown_fuchsia=x86_64-unknown-fuchsia-ar \
CC_x86_64_unknown_fuchsia=x86_64-unknown-fuchsia-clang \
CXX_x86_64_unknown_fuchsia=x86_64-unknown-fuchsia-clang++ \
AR_aarch64_unknown_fuchsia=aarch64-unknown-fuchsia-ar \
CC_aarch64_unknown_fuchsia=aarch64-unknown-fuchsia-clang \
CXX_aarch64_unknown_fuchsia=aarch64-unknown-fuchsia-clang++

# Suppress some warnings in the openwrt toolchains we downloaded
ENV STAGING_DIR=/tmp
Expand Down
114 changes: 114 additions & 0 deletions src/ci/docker/cross/build-fuchsia.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/bin/bash
# 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 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.

set -ex
source shared.sh

# Download sources
SRCS=(
"https://fuchsia.googlesource.com/magenta magenta ac69119"
"https://fuchsia.googlesource.com/third_party/llvm llvm 5463083"
"https://fuchsia.googlesource.com/third_party/clang llvm/tools/clang 4ff7b4b"
"https://fuchsia.googlesource.com/third_party/lld llvm/tools/lld fd465a3"
"https://fuchsia.googlesource.com/third_party/lldb llvm/tools/lldb 6bb11f8"
"https://fuchsia.googlesource.com/third_party/compiler-rt llvm/runtimes/compiler-rt 52d4ecc"
"https://fuchsia.googlesource.com/third_party/libcxx llvm/runtimes/libcxx e891cc8"
"https://fuchsia.googlesource.com/third_party/libcxxabi llvm/runtimes/libcxxabi f0f0257"
"https://fuchsia.googlesource.com/third_party/libunwind llvm/runtimes/libunwind 50bddc1"
)

fetch() {
mkdir -p $2
pushd $2 > /dev/null
curl -sL $1/+archive/$3.tar.gz | tar xzf -
popd > /dev/null
}

for i in "${SRCS[@]}"; do
fetch $i
done

# Build toolchain
cd llvm
mkdir build
cd build
hide_output cmake -GNinja \
-DFUCHSIA_SYSROOT=${PWD}/../../magenta/third_party/ulib/musl \
-C ../tools/clang/cmake/caches/Fuchsia.cmake \
..
hide_output ninja stage2-distribution
hide_output ninja stage2-install-distribution
cd ../..

# Build sysroot
rm -rf llvm/runtimes/compiler-rt
./magenta/scripts/download-toolchain

build_sysroot() {
local arch="$1"

case "${arch}" in
x86_64) tgt="magenta-pc-x86-64" ;;
aarch64) tgt="magenta-qemu-arm64" ;;
esac

hide_output make -C magenta -j$(getconf _NPROCESSORS_ONLN) $tgt
dst=/usr/local/${arch}-unknown-fuchsia
mkdir -p $dst
cp -r magenta/build-${tgt}/sysroot/include $dst/
cp -r magenta/build-${tgt}/sysroot/lib $dst/

cd llvm
mkdir build-runtimes-${arch}
cd build-runtimes-${arch}
hide_output cmake -GNinja \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_AR=/usr/local/bin/llvm-ar \
-DCMAKE_RANLIB=/usr/local/bin/llvm-ranlib \
-DCMAKE_INSTALL_PREFIX= \
-DLLVM_MAIN_SRC_DIR=${PWD}/.. \
-DLLVM_BINARY_DIR=${PWD}/../build \
-DLLVM_ENABLE_WERROR=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_INCLUDE_TESTS=ON \
-DCMAKE_SYSTEM_NAME=Fuchsia \
-DCMAKE_C_COMPILER_TARGET=${arch}-fuchsia \
-DCMAKE_CXX_COMPILER_TARGET=${arch}-fuchsia \
-DUNIX=1 \
-DLIBCXX_HAS_MUSL_LIBC=ON \
-DLIBCXXABI_USE_LLVM_UNWINDER=ON \
-DCMAKE_SYSROOT=${dst} \
-DCMAKE_C_COMPILER_FORCED=TRUE \
-DCMAKE_CXX_COMPILER_FORCED=TRUE \
-DLLVM_ENABLE_LIBCXX=ON \
-DCMAKE_EXE_LINKER_FLAGS="-nodefaultlibs -lc" \
-DCMAKE_SHARED_LINKER_FLAGS="$(clang --target=${arch}-fuchsia -print-libgcc-file-name)" \
../runtimes
hide_output env DESTDIR="${dst}" ninja install
cd ../..
}

build_sysroot "x86_64"
build_sysroot "aarch64"

rm -rf magenta llvm

for arch in x86_64 aarch64; do
for tool in clang clang++; do
cat >/usr/local/bin/${arch}-unknown-fuchsia-${tool} <<EOF
#!/bin/sh
${tool} --target=${arch}-unknown-fuchsia --sysroot=/usr/local/${arch}-unknown-fuchsia "\$@"
EOF
chmod +x /usr/local/bin/${arch}-unknown-fuchsia-${tool}
done
ln -s /usr/local/bin/llvm-ar /usr/local/bin/${arch}-unknown-fuchsia-ar
done
25 changes: 25 additions & 0 deletions src/ci/docker/cross/shared.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.

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
}
2 changes: 2 additions & 0 deletions src/tools/build-manifest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static HOSTS: &'static [&'static str] = &[

static TARGETS: &'static [&'static str] = &[
"aarch64-apple-ios",
"aarch64-unknown-fuchsia",
"aarch64-linux-android",
"aarch64-unknown-linux-gnu",
"arm-linux-androideabi",
Expand Down Expand Up @@ -86,6 +87,7 @@ static TARGETS: &'static [&'static str] = &[
"x86_64-pc-windows-msvc",
"x86_64-rumprun-netbsd",
"x86_64-unknown-freebsd",
"x86_64-unknown-fuchsia",
"x86_64-unknown-linux-gnu",
"x86_64-unknown-linux-musl",
"x86_64-unknown-netbsd",
Expand Down

0 comments on commit 1a2a2e4

Please sign in to comment.