Skip to content

Commit f2aa6cf

Browse files
committed
[Build script] Add compilation script
In some cases, when using different versions of the compiler/libc to build the llvm-project and other parts of the project, linking errors occur. To avoid this, a new compilation script has been added that will build the llvm project in the specified environment. Also external projects will be saved in the externals folder so that the user can delete the build directory separately from the external projects. Signed-off-by: Dmitrii Makarenko <[email protected]>
1 parent 51ac048 commit f2aa6cf

File tree

2 files changed

+89
-9
lines changed

2 files changed

+89
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.*/
22
!.github/
33
build/
4+
externals/
45
compile_commands.json

scripts/compile.sh

Lines changed: 88 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,107 @@
11
#!/bin/bash -e
22

33
repo=intel/graph-compiler
4+
set -ex
5+
6+
function print_usage() {
7+
echo "Usage:"
8+
echo "$0 [-d]"
9+
echo " -d Use dev build, build LLVM in current env and place all to 'external' dir"
10+
}
11+
12+
DEV_BUILD=false
13+
while getopts 'd' flag; do
14+
case "${flag}" in
15+
d)
16+
DEV_BUILD=true
17+
;;
18+
*)
19+
echo $flag
20+
print_usage
21+
exit 1
22+
;;
23+
esac
24+
done
25+
shift $((OPTIND-1))
426

527
cd $(dirname "$0")/..
6-
llvm_dir=$(cd ..; pwd -P)/install/llvm
28+
project_dir=$PWD
729
llvm_hash=$(cat cmake/llvm-version.txt)
830

9-
get_llvm() (
31+
function load_llvm() {
32+
local mlir_dir=$1
1033
local run_id
1134

1235
run_id=$(gh run list -w "LLVM Build" --repo $repo --json databaseId --jq '.[0].databaseId')
1336

1437
gh run download "$run_id" \
15-
--repo "$repo" \
16-
--pattern "llvm-$llvm_hash" \
17-
--dir "$llvm_dir"
38+
--repo "$repo" \
39+
--pattern "llvm-$llvm_hash" \
40+
--dir "$llvm_dir"
1841
cd "$llvm_dir"
1942
tar -zxf "llvm-$llvm_hash"/llvm.tgz
20-
)
2143

22-
test -f "$llvm_dir/llvm-$llvm_hash"/llvm.tgz || get_llvm
44+
eval $mlir_dir="$PWD/lib/cmake/mlir"
45+
cd "$project_dir"
46+
return 0
47+
}
48+
49+
function build_llvm() {
50+
local mlir_dir=$1
51+
52+
if ! [ -d "llvm-project" ]; then
53+
git clone https://github.com/llvm/llvm-project.git
54+
fi
55+
56+
cd llvm-project
57+
git checkout ${llvm_hash}
58+
59+
cmake -G Ninja llvm -B build \
60+
-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=true \
61+
-DLLVM_ENABLE_PROJECTS="mlir" -DLLVM_TARGETS_TO_BUILD="X86" \
62+
-DLLVM_INSTALL_UTILS=true -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
63+
-DLLVM_INSTALL_GTEST=ON
64+
cmake --build build
65+
66+
eval $mlir_dir="$PWD/build/lib/cmake/mlir"
67+
cd ..
68+
return 0
69+
}
70+
71+
function get_llvm() {
72+
local ret_val=$1
73+
74+
if [[ "$DEV_BUILD" == 'true' ]]; then
75+
mkdir -p externals
76+
cd externals
77+
build_llvm val
78+
echo "val = " $val
79+
eval $ret_val=\$val
80+
cd ..
81+
return 0
82+
fi
83+
84+
if [[ -f "$llvm_dir/llvm-$llvm_hash"/llvm.tgz ]]; then
85+
llvm_dir=$project_dir/../install/llvm
86+
load_llvm val
87+
echo "val = " $val
88+
eval $ret_val=\$val
89+
fi
90+
return 0
91+
}
92+
93+
get_llvm mlir_dir
94+
95+
fetch_dir=$project_dir/build/_deps
96+
if [[ "$DEV_BUILD" == 'true' ]]; then
97+
fetch_dir=$project_dir/externals
98+
fi
2399

24100
cmake -S . -G Ninja -B build \
25101
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
26-
-DMLIR_DIR=$llvm_dir/lib/cmake/mlir \
27-
-DLLVM_EXTERNAL_LIT=$(which lit)
102+
-DMLIR_DIR=$mlir_dir \
103+
-DLLVM_EXTERNAL_LIT=$(which lit) \
104+
-DFETCHCONTENT_BASE_DIR=$fetch_dir
105+
# \
106+
# -DGC_DEV_LINK_LLVM_DYLIB="ON"
28107
cmake --build build --parallel $(nproc)

0 commit comments

Comments
 (0)