forked from andrew-d/docker-rust-musl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·116 lines (88 loc) · 2.96 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
set -e
set -o pipefail
set -x
CPU_COUNT="$(grep -c processor /proc/cpuinfo)"
BUILD_DIR=/build
function install_musl() {
echo "** Installing musl"
cd "${BUILD_DIR}"
if [ -d "/usr/local/musl" ]; then
return
fi
curl -L "http://www.musl-libc.org/releases/musl-${MUSL_VERSION}.tar.gz" | tar zxf -
cd "musl-${MUSL_VERSION}"
./configure
make -j"${CPU_COUNT}"
make install
}
function build_llvm_components() {
cd "${BUILD_DIR}"
if [ -f "/usr/local/musl/lib/libunwind.a" ]; then
return
fi
echo "** Fetching sources"
curl "http://releases.llvm.org/${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.xz" | tar xJf -
curl "http://releases.llvm.org/${LLVM_VERSION}/libunwind-${LLVM_VERSION}.src.tar.xz" | tar xJf -
mv "llvm-${LLVM_VERSION}.src" llvm
mv "libunwind-${LLVM_VERSION}.src" libunwind
echo "** Building libunwind"
cd "${BUILD_DIR}/libunwind"
ln -s "${BUILD_DIR}/libcxxabi/include/__cxxabi_config.h" ./include/__cxxabi_config.h
mkdir build && cd build
cmake -DLLVM_PATH="${BUILD_DIR}/llvm" -DLIBUNWIND_ENABLE_SHARED=OFF ..
make
echo "** Copying to output"
cp ./lib/libunwind.a /usr/local/musl/lib/
}
function build_rust() {
echo "** Building rust"
cd "${BUILD_DIR}"
if [ ! -d "${BUILD_DIR}/rust" ]; then
curl "https://static.rust-lang.org/dist/rustc-${RUST_VERSION}-src.tar.gz" | tar xzf -
mv "rustc-${RUST_VERSION}-src" rust
cd rust
./configure \
--disable-docs \
--target=x86_64-unknown-linux-musl \
--musl-root=/usr/local/musl/
else
cd rust
fi
# These environment variables are set from the Dockerfile and control what
# we build and whether we install the compiler.
make -j"${CPU_COUNT}" "${RUST_BUILD_TARGET}"
if [ "x${RUST_BUILD_INSTALL}" == "xtrue" ]; then
make install
fi
# FIXME: temporary fix, make install does not install musl libraries properly
mkdir -p /usr/local/lib/rustlib/x86_64-unknown-linux-musl/lib
cp /build/rust/build/x86_64-unknown-linux-gnu/stage2-std/x86_64-unknown-linux-musl/release/deps/* /usr/local/lib/rustlib/x86_64-unknown-linux-musl/lib
cp /usr/local/musl/lib/* /usr/local/lib/rustlib/x86_64-unknown-linux-musl/lib
}
function install_cargo() {
echo "** Installing Cargo"
if [ -f "/usr/local/bin/cargo" ]; then
return
fi
cd "${BUILD_DIR}"
curl -L "https://static.rust-lang.org/cargo-dist/cargo-nightly-x86_64-unknown-linux-gnu.tar.gz" | tar zxf -
USER=root ./cargo-nightly-x86_64-unknown-linux-gnu/install.sh
}
function cleanup() {
if [ "x${RUST_BUILD_CLEAN}" == "xtrue" ]; then
rm -rf "${BUILD_DIR}"
apt-get clean
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
fi
}
function main() {
mkdir -p "${BUILD_DIR}" && cd "${BUILD_DIR}"
install_musl
build_llvm_components
build_rust
install_cargo
cleanup
echo "** Done"
}
main