-
Notifications
You must be signed in to change notification settings - Fork 26
/
build.sh
executable file
·148 lines (130 loc) · 3.95 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
set -ex
ROOT=$PWD
VERSION=$1
BINUTILS_GCC_VERSION=9.2.0
CMAKE_EXTRA_ARGS=
LLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi"
LLVM_EXPERIMENTAL_TARGETS_TO_BUILD=
BASENAME=clang
NINJA_TARGET=install
case $VERSION in
autonsdmi-trunk)
BRANCH=experiments
URL=https://github.com/cor3ntin/llvm-project.git
VERSION=autonsdmi-trunk-$(date +%Y%m%d)
CMAKE_EXTRA_ARGS=-DLLVM_OPTIMIZED_TABLEGEN=ON
;;
cppx-trunk)
BRANCH=compiler-explorer
URL=https://github.com/lock3/meta.git
VERSION=cppx-trunk-$(date +%Y%m%d)
;;
embed-trunk)
BRANCH=feature/embed
URL=https://github.com/ThePhD/llvm-project.git
VERSION=embed-trunk-$(date +%Y%m%d)
;;
lifetime-trunk)
BRANCH=lifetime
URL=https://github.com/mgehre/llvm-project.git
VERSION=lifetime-trunk-$(date +%Y%m%d)
LLVM_ENABLE_PROJECTS="clang"
;;
llvmflang-trunk)
BRANCH=master
URL=https://github.com/llvm/llvm-project.git
VERSION=llvmflang-trunk-$(date +%Y%m%d)
LLVM_ENABLE_PROJECTS="mlir;flang"
CMAKE_EXTRA_ARGS=-DCMAKE_CXX_STANDARD=17
;;
relocatable-trunk)
BRANCH=trivially-relocatable
URL=https://github.com/Quuxplusone/llvm-project.git
VERSION=relocatable-trunk-$(date +%Y%m%d)
;;
llvm-*)
BASENAME=llvm
NINJA_TARGET=install-llvm-headers
# strip prefix from front of version
VERSION=${VERSION#llvm-}
if [[ "${VERSION}" == "trunk" ]]; then
BRANCH=master
VERSION=trunk-$(date +%Y%m%d)
else
TAG=llvmorg-${VERSION}
fi
URL=https://github.com/llvm/llvm-project.git
;;
*)
if [[ "${VERSION}" == "trunk" ]]; then
BRANCH=master
VERSION=trunk-$(date +%Y%m%d)
else
TAG=llvmorg-${VERSION}
fi
URL=https://github.com/llvm/llvm-project.git
LLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi;compiler-rt;lld;polly;clang-tools-extra;openmp"
LLVM_EXPERIMENTAL_TARGETS_TO_BUILD="RISCV;WebAssembly"
;;
esac
# use tag name as branch if otherwise unspecified
BRANCH=${BRANCH-$TAG}
# some builds checkout a tag instead of a branch
# these builds have a different prefix for ls-remote
REF=refs/heads/${BRANCH}
if [[ ! -z "${TAG}" ]]; then
REF=refs/tags/${TAG}
fi
# determine build revision
LLVMORG_REVISION=$(git ls-remote "${URL}" "${REF}" | cut -f 1)
REVISION="llvmorg-${LLVMORG_REVISION}-gcc-${BINUTILS_GCC_VERSION}"
LAST_REVISION="${3}"
echo "ce-build-revision:${REVISION}"
if [[ "${REVISION}" == "${LAST_REVISION}" ]]; then
echo "ce-build-status:SKIPPED"
exit
fi
# Grab CE's GCC for its binutils
mkdir -p /opt/compiler-explorer
pushd /opt/compiler-explorer
curl -sL https://s3.amazonaws.com/compiler-explorer/opt/gcc-${BINUTILS_GCC_VERSION}.tar.xz | tar Jxf -
popd
FULLNAME=${BASENAME}-${VERSION}
OUTPUT=${ROOT}/${FULLNAME}.tar.xz
S3OUTPUT=
if [[ $2 =~ ^s3:// ]]; then
S3OUTPUT=$2
else
if [[ -d "${2}" ]]; then
OUTPUT=$2/${FULLNAME}.tar.xz
else
OUTPUT=${2-$OUTPUT}
fi
fi
BUILD_DIR=${ROOT}/build
STAGING_DIR=${ROOT}/staging
rm -rf "${STAGING_DIR}"
mkdir -p "${STAGING_DIR}"
mkdir -p "${ROOT}/build"
# Setup llvm-project checkout
git clone --depth 1 --single-branch -b "${BRANCH}" "${URL}" "${ROOT}/llvm-project"
# Setup build directory and build configuration
mkdir -p "${ROOT}/build"
cd "${ROOT}/build"
cmake \
-G "Ninja" "${ROOT}/llvm-project/llvm" \
-DLLVM_ENABLE_PROJECTS="${LLVM_ENABLE_PROJECTS}" \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DCMAKE_INSTALL_PREFIX:PATH="${STAGING_DIR}" \
-DLLVM_BINUTILS_INCDIR:PATH="/opt/compiler-explorer/gcc-${BINUTILS_GCC_VERSION}/lib/gcc/x86_64-linux-gnu/${BINUTILS_GCC_VERSION}/plugin/include" \
-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD}" \
${CMAKE_EXTRA_ARGS}
# Build and install artifacts
ninja ${NINJA_TARGET}
# Don't try to compress the binaries as they don't like it
export XZ_DEFAULTS="-T 0"
tar Jcf ${OUTPUT} --transform "s,^./,./${FULLNAME}/," -C ${STAGING_DIR} .
if [[ ! -z "${S3OUTPUT}" ]]; then
s3cmd put --rr ${OUTPUT} ${S3OUTPUT}
fi