-
Notifications
You must be signed in to change notification settings - Fork 6
/
build
executable file
·89 lines (71 loc) · 2.39 KB
/
build
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
#!/bin/bash
# Try to guess the location of the arc-mlir repository
if [[ -z "$ARC_MLIR" ]] ; then
ARC_MLIR=$(realpath $(dirname "$(which "$0")")/arc-mlir)
echo The arc-mlir repository is assumed to be at ${ARC_MLIR}, override by setting ARC_MLIR.
else
echo ARC_MLIR is ${ARC_MLIR}
fi
if [[ -z "$ARC_MLIR_BUILD" ]] ; then
echo "No build directory specified with ARC_MLIR_BUILD, assuming ${ARC_MLIR}/build"
ARC_MLIR_BUILD="${ARC_MLIR}/build"
else
echo "Will use $ARC_MLIR_BUILD as the scratch directory"
fi
if [ ! -f ${ARC_MLIR}/.guessed-arc-mlir ]; then
echo "Waiting 10s before proceeding, next run will proceed directly"
touch ${ARC_MLIR}/.guessed-arc-mlir
sleep 10
fi
# prefer gold if it is available
ARC_MLIR_LINKER_SELECTION=""
if command -v ld.gold >/dev/null 2>&1; then
echo "Will use gold"
ARC_MLIR_LINKER_SELECTION="-DLLVM_USE_LINKER=gold"
fi
LLVM_SRC_DIR="$ARC_MLIR/llvm-project"
LLVM_BUILD_DIR="$ARC_MLIR_BUILD/llvm-build/"
LLVM_INSTALL_DIR="$ARC_MLIR_BUILD/llvm-install"
ARC_LANG_SRC_DIR="${ARC_MLIR}/../arc-lang/"
ARC_LANG_BUILD_DIR="${ARC_MLIR_BUILD}/arc-lang/"
# default to a debug build
BUILD_FLAVOUR="${BUILD_FLAVOUR:-Debug}"
# Do we want assertions?
ARC_MLIR_ASSERTS="${ARC_MLIR_ASSERTS:+-DLLVM_ENABLE_ASSERTIONS=ON}"
# Do we want ccache?
ARC_MLIR_CCACHE="${ARC_MLIR_CCACHE:+-DLLVM_CCACHE_BUILD=1}"
echo "Will build a $BUILD_FLAVOUR build"
# Report a failure and exit
function fail {
echo "Failure: $*"
exit 1
}
function llvm-cmake {
mkdir -p $LLVM_BUILD_DIR || fail "creating $LLVM_BUILD_DIR"
cd $LLVM_BUILD_DIR
if [ -f compile_commands.json ]; then
echo "LLVM is already configured"
return
fi
CXX=clang++ CC=clang cmake \
-DCMAKE_GENERATOR="Ninja" \
-DCMAKE_INSTALL_PREFIX="$LLVM_INSTALL_DIR" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
-DCMAKE_BUILD_TYPE=$BUILD_FLAVOUR \
-DLLVM_TARGETS_TO_BUILD="host" \
$ARC_MLIR_LINKER_SELECTION \
$ARC_MLIR_ASSERTS \
-DBUILD_SHARED_LIBS=0 \
-DLLVM_USE_SPLIT_DWARF=ON \
$ARC_MLIR_CCACHE \
-DLLVM_BUILD_EXAMPLES=OFF \
-DLLVM_ENABLE_PROJECTS=mlir\
-DLLVM_EXTERNAL_PROJECTS="arc-mlir" \
-DLLVM_EXTERNAL_ARC_MLIR_SOURCE_DIR="$ARC_MLIR/src" \
$LLVM_SRC_DIR/llvm || fail "cmaking LLVM"
}
function llvm-build {
cmake --build $LLVM_BUILD_DIR || fail "building LLVM"
}
llvm-cmake
llvm-build