Skip to content

Commit 18b0f88

Browse files
committed
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.
1 parent 536a900 commit 18b0f88

File tree

4 files changed

+165
-4
lines changed

4 files changed

+165
-4
lines changed

src/ci/docker/cross/Dockerfile

+24-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ FROM ubuntu:16.04
33
RUN apt-get update && apt-get install -y --no-install-recommends \
44
g++ \
55
make \
6+
ninja-build \
67
file \
78
curl \
89
ca-certificates \
9-
python2.7 \
10+
python2.7-dev \
1011
git \
11-
cmake \
1212
sudo \
1313
xz-utils \
1414
zlib1g-dev \
@@ -19,7 +19,15 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1919
bzip2 \
2020
patch \
2121
libssl-dev \
22-
pkg-config
22+
pkg-config \
23+
swig \
24+
libedit-dev \
25+
libncurses5-dev
26+
27+
# CMake 3.8.0 is the first version with official support for Fuchsia,
28+
# which is needed to build the Fuchsia toolchain.
29+
RUN curl -L https://cmake.org/files/v3.8/cmake-3.8.0-rc1-Linux-x86_64.tar.gz | \
30+
tar xzf - -C /usr/local --strip-components=1
2331

2432
ENV SCCACHE_DIGEST=7237e38e029342fa27b7ac25412cb9d52554008b12389727320bd533fd7f05b6a96d55485f305caf95e5c8f5f97c3313e10012ccad3e752aba2518f3522ba783
2533
RUN curl -L https://api.pub.build.mozilla.org/tooltool/sha512/$SCCACHE_DIGEST | \
@@ -31,6 +39,10 @@ RUN curl -OL https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-ini
3139
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
3240

3341
WORKDIR /tmp
42+
COPY shared.sh /tmp/
43+
44+
COPY build-fuchsia.sh /tmp/
45+
RUN ./build-fuchsia.sh
3446

3547
COPY build-rumprun.sh /tmp/
3648
RUN ./build-rumprun.sh
@@ -65,10 +77,18 @@ ENV TARGETS=$TARGETS,arm-unknown-linux-musleabi
6577
ENV TARGETS=$TARGETS,arm-unknown-linux-musleabihf
6678
ENV TARGETS=$TARGETS,armv7-unknown-linux-musleabihf
6779
ENV TARGETS=$TARGETS,sparc64-unknown-linux-gnu
80+
ENV TARGETS=$TARGETS,x86_64-unknown-fuchsia
81+
ENV TARGETS=$TARGETS,aarch64-unknown-fuchsia
6882

6983
ENV CC_mipsel_unknown_linux_musl=mipsel-openwrt-linux-gcc \
7084
CC_mips_unknown_linux_musl=mips-openwrt-linux-gcc \
71-
CC_sparc64_unknown_linux_gnu=sparc64-linux-gnu-gcc
85+
CC_sparc64_unknown_linux_gnu=sparc64-linux-gnu-gcc \
86+
AR_x86_64_unknown_fuchsia=x86_64-unknown-fuchsia-ar \
87+
CC_x86_64_unknown_fuchsia=x86_64-unknown-fuchsia-clang \
88+
CXX_x86_64_unknown_fuchsia=x86_64-unknown-fuchsia-clang++ \
89+
AR_aarch64_unknown_fuchsia=aarch64-unknown-fuchsia-ar \
90+
CC_aarch64_unknown_fuchsia=aarch64-unknown-fuchsia-clang \
91+
CXX_aarch64_unknown_fuchsia=aarch64-unknown-fuchsia-clang++
7292

7393
# Suppress some warnings in the openwrt toolchains we downloaded
7494
ENV STAGING_DIR=/tmp

src/ci/docker/cross/build-fuchsia.sh

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/bin/bash
2+
# Copyright 2017 The Rust Project Developers. See the COPYRIGHT
3+
# file at the top-level directory of this distribution and at
4+
# http://rust-lang.org/COPYRIGHT.
5+
#
6+
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
7+
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8+
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
9+
# option. This file may not be copied, modified, or distributed
10+
# except according to those terms.
11+
12+
set -ex
13+
source shared.sh
14+
15+
# Download sources
16+
SRCS=(
17+
"https://fuchsia.googlesource.com/magenta magenta 29f09e6"
18+
"https://fuchsia.googlesource.com/third_party/llvm llvm 0f6af23"
19+
"https://fuchsia.googlesource.com/third_party/clang llvm/tools/clang 71b73d0"
20+
"https://fuchsia.googlesource.com/third_party/lld llvm/tools/lld af25ab9"
21+
"https://fuchsia.googlesource.com/third_party/lldb llvm/tools/lldb 90fe975"
22+
"https://fuchsia.googlesource.com/third_party/compiler-rt llvm/runtimes/compiler-rt 2edda55"
23+
"https://fuchsia.googlesource.com/third_party/libcxx llvm/runtimes/libcxx b7fd0be"
24+
"https://fuchsia.googlesource.com/third_party/libcxxabi llvm/runtimes/libcxxabi 66c8647"
25+
"https://fuchsia.googlesource.com/third_party/libunwind llvm/runtimes/libunwind 43ce8ac"
26+
)
27+
28+
fetch() {
29+
mkdir -p $2
30+
pushd $2 > /dev/null
31+
curl -sL $1/+archive/$3.tar.gz | tar xzf -
32+
popd > /dev/null
33+
}
34+
35+
for i in "${SRCS[@]}"; do
36+
fetch $i
37+
done
38+
39+
# Build toolchain
40+
cd llvm
41+
mkdir build
42+
cd build
43+
hide_output cmake -GNinja \
44+
-DFUCHSIA_SYSROOT=${PWD}/../../magenta/third_party/ulib/musl \
45+
-C ../tools/clang/cmake/caches/Fuchsia.cmake \
46+
..
47+
hide_output ninja stage2-distribution
48+
hide_output ninja stage2-install-distribution
49+
cd ../..
50+
51+
# Build sysroot
52+
rm -rf llvm/runtimes/compiler-rt
53+
./magenta/scripts/download-toolchain
54+
55+
build_sysroot() {
56+
local arch="$1"
57+
58+
case "${arch}" in
59+
x86_64) tgt="magenta-pc-x86-64" ;;
60+
aarch64) tgt="magenta-qemu-arm64" ;;
61+
esac
62+
63+
hide_output make -C magenta -j$(getconf _NPROCESSORS_ONLN) $tgt
64+
dst=/usr/local/${arch}-unknown-fuchsia
65+
mkdir -p $dst
66+
cp -r magenta/build-${tgt}/sysroot/include $dst/
67+
cp -r magenta/build-${tgt}/sysroot/lib $dst/
68+
69+
cd llvm
70+
mkdir build-runtimes-${arch}
71+
cd build-runtimes-${arch}
72+
hide_output cmake -GNinja \
73+
-DCMAKE_C_COMPILER=clang \
74+
-DCMAKE_CXX_COMPILER=clang++ \
75+
-DCMAKE_AR=/usr/local/bin/llvm-ar \
76+
-DCMAKE_RANLIB=/usr/local/bin/llvm-ranlib \
77+
-DCMAKE_INSTALL_PREFIX= \
78+
-DLLVM_MAIN_SRC_DIR=${PWD}/.. \
79+
-DLLVM_BINARY_DIR=${PWD}/../build \
80+
-DLLVM_ENABLE_WERROR=OFF \
81+
-DCMAKE_BUILD_TYPE=Release \
82+
-DLLVM_INCLUDE_TESTS=ON \
83+
-DCMAKE_SYSTEM_NAME=Fuchsia \
84+
-DCMAKE_C_COMPILER_TARGET=${arch}-fuchsia \
85+
-DCMAKE_CXX_COMPILER_TARGET=${arch}-fuchsia \
86+
-DUNIX=1 \
87+
-DLIBCXX_HAS_MUSL_LIBC=ON \
88+
-DLIBCXXABI_USE_LLVM_UNWINDER=ON \
89+
-DCMAKE_SYSROOT=${dst} \
90+
-DCMAKE_C_COMPILER_FORCED=TRUE \
91+
-DCMAKE_CXX_COMPILER_FORCED=TRUE \
92+
-DLLVM_ENABLE_LIBCXX=ON \
93+
-DCMAKE_EXE_LINKER_FLAGS="-nodefaultlibs -lc" \
94+
-DCMAKE_SHARED_LINKER_FLAGS="$(clang --target=${arch}-fuchsia -print-libgcc-file-name)" \
95+
../runtimes
96+
hide_output env DESTDIR="${dst}" ninja install
97+
cd ../..
98+
}
99+
100+
build_sysroot "x86_64"
101+
build_sysroot "aarch64"
102+
103+
rm -rf magenta llvm
104+
105+
for arch in x86_64 aarch64; do
106+
for tool in clang clang++; do
107+
cat >/usr/local/bin/${arch}-unknown-fuchsia-${tool} <<EOF
108+
#!/bin/sh
109+
${tool} --target=${arch}-unknown-fuchsia --sysroot=/usr/local/${arch}-unknown-fuchsia "\$@"
110+
EOF
111+
chmod +x /usr/local/bin/${arch}-unknown-fuchsia-${tool}
112+
done
113+
ln -s /usr/local/bin/llvm-ar /usr/local/bin/${arch}-unknown-fuchsia-ar
114+
done

src/ci/docker/cross/shared.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
# file at the top-level directory of this distribution and at
3+
# http://rust-lang.org/COPYRIGHT.
4+
#
5+
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
# option. This file may not be copied, modified, or distributed
9+
# except according to those terms.
10+
11+
hide_output() {
12+
set +x
13+
on_err="
14+
echo ERROR: An error was encountered with the build.
15+
cat /tmp/build.log
16+
exit 1
17+
"
18+
trap "$on_err" ERR
19+
bash -c "while true; do sleep 30; echo \$(date) - building ...; done" &
20+
PING_LOOP_PID=$!
21+
"$@" &> /tmp/build.log
22+
trap - ERR
23+
kill $PING_LOOP_PID
24+
set -x
25+
}

src/tools/build-manifest/src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ static HOSTS: &'static [&'static str] = &[
4545

4646
static TARGETS: &'static [&'static str] = &[
4747
"aarch64-apple-ios",
48+
"aarch64-unknown-fuchsia",
4849
"aarch64-linux-android",
4950
"aarch64-unknown-linux-gnu",
5051
"arm-linux-androideabi",
@@ -86,6 +87,7 @@ static TARGETS: &'static [&'static str] = &[
8687
"x86_64-pc-windows-msvc",
8788
"x86_64-rumprun-netbsd",
8889
"x86_64-unknown-freebsd",
90+
"x86_64-unknown-fuchsia",
8991
"x86_64-unknown-linux-gnu",
9092
"x86_64-unknown-linux-musl",
9193
"x86_64-unknown-netbsd",

0 commit comments

Comments
 (0)