forked from alisw/alidist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclang.sh
105 lines (96 loc) · 3.7 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
package: Clang
version: "v15.0.7"
tag: "llvmorg-15.0.7"
source: https://github.com/llvm/llvm-project
requires:
- "GCC-Toolchain:(?!osx)"
build_requires:
- "Python:slc.*"
- "Python-system:(?!slc.*)"
- CMake
- curl
- ninja
---
#!/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
cmake --build . -- ${JOBS:+-j$JOBS} install
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/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"