-
Notifications
You must be signed in to change notification settings - Fork 161
/
clang.sh
128 lines (118 loc) · 4.49 KB
/
clang.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
package: Clang
version: "v18.1.8"
tag: "llvmorg-18.1.8-alice2"
source: https://github.com/alisw/llvm-project-reduced
requires:
- "GCC-Toolchain:(?!osx)"
build_requires:
- "Python:slc.*"
- "Python-system:(?!slc.*)"
- CMake
- curl
- ninja
env:
LLVM_ROOT: "$CLANG_ROOT" # needed by LLVMAlt
---
#!/bin/bash -e
# Unsetting default compiler flags in order to make sure that no debug
# information is compiled into the objects which make the build artifacts very
# big.
unset CXXFLAGS
unset CFLAGS
unset LDFLAGS
case $ARCHITECTURE in
# Needed to have the C headers
osx_*) DEFAULT_SYSROOT=$(xcrun --show-sdk-path) ;;
*) DEFAULT_SYSROOT= ;;
esac
case $ARCHITECTURE in
*_x86-64) LLVM_TARGETS_TO_BUILD=X86 ;;
*_arm64) LLVM_TARGETS_TO_BUILD=AArch64 ;;
*_aarch64) LLVM_TARGETS_TO_BUILD=AArch64 ;;
*) echo 'Unknown LLVM target for architecture' >&2; exit 1 ;;
esac
# BUILD_SHARED_LIBS=ON is needed for e.g. adding dynamic plugins to clang-tidy.
# Apache Arrow needs LLVM_ENABLE_RTTI=ON.
cmake "$SOURCEDIR/llvm" \
-G Ninja \
-DLLVM_ENABLE_PROJECTS='clang;clang-tools-extra;compiler-rt' \
-DLLVM_ENABLE_RUNTIMES='libcxx;libcxxabi' \
-DLLVM_TARGETS_TO_BUILD="${LLVM_TARGETS_TO_BUILD:?}" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX:PATH="$INSTALLROOT" \
-DLLVM_INSTALL_UTILS=ON \
-DPYTHON_EXECUTABLE="$(which python3)" \
-DDEFAULT_SYSROOT="$DEFAULT_SYSROOT" \
-DLLVM_BUILD_LLVM_DYLIB=ON \
-DLLVM_ENABLE_RTTI=ON \
-DBUILD_SHARED_LIBS=OFF \
-DLIBCXXABI_USE_LLVM_UNWINDER=OFF \
${GCC_TOOLCHAIN_ROOT:+-DGCC_INSTALL_PREFIX=$GCC_TOOLCHAIN_ROOT}
cmake --build . -- ${JOBS:+-j$JOBS} install
if [[ $PKGVERSION == v18.1.* ]]; then
SPIRV_TRANSLATOR_VERSION="v18.1.3"
else
SPIRV_TRANSLATOR_VERSION="${PKGVERSION%%.*}.0.0"
fi
git clone -b "$SPIRV_TRANSLATOR_VERSION" https://github.com/KhronosGroup/SPIRV-LLVM-Translator
mkdir SPIRV-LLVM-Translator/build
pushd SPIRV-LLVM-Translator/build
cmake ../ \
-G Ninja \
-DLLVM_DIR="$INSTALLROOT/lib/cmake/llvm" \
-DLLVM_BUILD_TOOLS=ON \
-DLLVM_INCLUDE_TESTS=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX:PATH="$INSTALLROOT"
cmake --build . -- ${JOBS:+-j$JOBS} install
popd
case $ARCHITECTURE in
osx*)
# Add correct rpath to dylibs on Mac as long as there is no better way to
# control rpath in the LLVM CMake.
# Add rpath to all libraries in lib and change their IDs to be absolute paths.
find "$INSTALLROOT/lib" -name '*.dylib' -not -name '*ios*.dylib' \
-exec install_name_tool -add_rpath "$INSTALLROOT/lib" '{}' \; \
-exec install_name_tool -id '{}' '{}' \;
# In lib/clang/*/lib/darwin, the relative rpath is wrong and needs to be
# corrected from "@loader_path/../lib" to "@loader_path/../darwin".
find "$INSTALLROOT"/lib/clang/*/lib/darwin -name '*.dylib' -not -name '*ios*.dylib' \
-exec install_name_tool -rpath '@loader_path/../lib' '@loader_path/../darwin' '{}' \;
# Needed to be able to find C++ headers.
ln -sf "$(xcrun --show-sdk-path)/usr/include/c++" "$INSTALLROOT/include/c++" ;;
esac
# We do not want to have the clang executables in path
# to avoid issues with system clang on macOS.
# We **MUST NOT** add bin-safe to the build path. Runtime
# path is fine.
mkdir "$INSTALLROOT/bin-safe"
mv "$INSTALLROOT"/bin/clang* "$INSTALLROOT/bin-safe/"
mv "$INSTALLROOT"/bin/llvm-spirv* "$INSTALLROOT/bin-safe/" # Install llvm-spirv tool
mv "$INSTALLROOT"/bin/git-clang* "$INSTALLROOT/bin-safe/" # we also need git-clang-format in runtime
sed -i.bak -e "s|bin/clang|bin-safe/clang|g" "$INSTALLROOT/lib/cmake/clang/ClangTargets-release.cmake"
rm "$INSTALLROOT"/lib/cmake/clang/*.bak
# Check it actually works
cat << \EOF > test.cc
#include <iostream>
EOF
"$INSTALLROOT/bin-safe/clang++" -v -c test.cc
# Modulefile
mkdir -p etc/modulefiles
cat > "etc/modulefiles/$PKGNAME" <<EoF
#%Module1.0
proc ModulesHelp { } {
global version
puts stderr "ALICE Modulefile for $PKGNAME $PKGVERSION-@@PKGREVISION@$PKGHASH@@"
}
set version $PKGVERSION-@@PKGREVISION@$PKGHASH@@
module-whatis "ALICE Modulefile for $PKGNAME $PKGVERSION-@@PKGREVISION@$PKGHASH@@"
# Dependencies
module load BASE/1.0 \\
${GCC_TOOLCHAIN_REVISION:+GCC-Toolchain/$GCC_TOOLCHAIN_VERSION-$GCC_TOOLCHAIN_REVISION}
# Our environment
set CLANG_ROOT \$::env(BASEDIR)/$PKGNAME/\$version
prepend-path PATH \$CLANG_ROOT/bin-safe
prepend-path LD_LIBRARY_PATH \$CLANG_ROOT/lib
EoF
mkdir -p "$INSTALLROOT/etc/modulefiles"
rsync -a --delete etc/modulefiles/ "$INSTALLROOT/etc/modulefiles"