33repo=intel/graph-compiler
44
55# Uncomment for script debug
6- # set -ex
6+ # set -x
77
8- function print_usage() {
8+ print_usage () {
99 echo " Usage:"
1010 echo " $0 "
1111 echo " [ -d | --dev ] Dev build, build LLVM in current env and place all to 'external' dir"
1212 echo " [ -l | --dyn ] Dynamical linking, requires rebuild of LLVM, activates 'dev' option"
1313 echo " [ -h | --help ] Print this message"
1414}
1515
16- args=$( getopt -a -o dlh --long dev,dyn,help -- " $@ " )
17- if [[ $? -gt 0 ]]; then
18- echo " first"
19- print_usage
20- fi
21-
2216DEV_BUILD=false
2317DYN_LINK=false
24- eval set -- ${args}
25- while :
26- do
27- case $1 in
18+ for arg in " $@ " ; do
19+ case $arg in
2820 -d | --dev)
2921 DEV_BUILD=true
30- shift ;;
22+ ;;
3123 -l | --dyn)
3224 DEV_BUILD=true
3325 DYN_LINK=true
34- shift ;;
26+ ;;
3527 -h | --help)
36- echo " in help"
3728 print_usage
38- shift ;;
29+ exit 0
30+ ;;
3931 # -- means the end of the arguments; drop this, and break out of the while loop
40- --) shift ; break ;;
41- * ) >&2 echo Unsupported option: $1
42- echo " in unsup"
43- print_usage ;;
32+ * )
33+ echo Unsupported option: $arg
34+ print_usage
35+ exit 1
36+ ;;
4437 esac
4538done
4639
4740cd $( dirname " $0 " ) /..
48- project_dir =$PWD
49- llvm_hash =$( cat cmake/llvm-version.txt)
41+ PROJECT_DIR =$PWD
42+ LLVM_HASH =$( cat cmake/llvm-version.txt)
5043
51- function load_llvm() {
52- local mlir_dir=$1
44+ load_llvm () {
5345 local run_id
5446
5547 run_id=$( gh run list -w " LLVM Build" --repo $repo --json databaseId --jq ' .[0].databaseId' )
5648
5749 gh run download " $run_id " \
5850 --repo " $repo " \
59- --pattern " llvm-$llvm_hash " \
51+ --pattern " llvm-$LLVM_HASH " \
6052 --dir " $llvm_dir "
6153 cd " $llvm_dir "
62- tar -zxf " llvm-$llvm_hash " /llvm.tgz
54+ tar -zxf " llvm-$LLVM_HASH " /llvm.tgz
6355
64- eval $mlir_dir =" $PWD /lib/cmake/mlir"
65- cd " $project_dir "
66- return 0
56+ MLIR_DIR=" $PWD /lib/cmake/mlir"
57+ cd " $PROJECT_DIR "
6758}
6859
69- function build_llvm() {
70- local mlir_dir=$1
71-
60+ build_llvm () {
7261 if ! [ -d " llvm-project" ]; then
7362 git clone https://github.com/llvm/llvm-project.git
7463 fi
7564
7665 cd llvm-project
77- git checkout ${llvm_hash }
66+ git checkout ${LLVM_HASH }
7867
7968 dylib=OFF
80- if [[ " $DYN_LINK " == ' true' ] ]; then
69+ if [ " $DYN_LINK " = ' true' ]; then
8170 dylib=ON
8271 fi
8372
@@ -88,56 +77,54 @@ function build_llvm() {
8877 -DLLVM_INSTALL_GTEST=ON -DLLVM_BUILD_LLVM_DYLIB=$dylib -DLLVM_LINK_LLVM_DYLIB=$dylib
8978 cmake --build build
9079
91- eval $mlir_dir =" $PWD /build/lib/cmake/mlir"
80+ MLIR_DIR =" $PWD /build/lib/cmake/mlir"
9281 cd ..
93- return 0
9482}
9583
96- function get_llvm() {
97- local ret_val=$1
98-
99- if [[ " $DEV_BUILD " == ' true' ]]; then
84+ # MLIR_DIR is set on all passes
85+ get_llvm () {
86+ if [ " $DEV_BUILD " = ' true' ]; then
10087 mkdir -p externals
10188 cd externals
102- build_llvm val
103- eval $ret_val =\$ val
89+ build_llvm
10490 cd ..
10591 return 0
10692 fi
10793
108- llvm_dir=$project_dir /../install/llvm
109- if ! [ -f " $llvm_dir /llvm-$llvm_hash " /llvm.tgz ]; then
110- load_llvm val
111- eval $ret_val =\$ val
94+ llvm_dir=$PROJECT_DIR /../install/llvm
95+ if ! [ -f " $llvm_dir /llvm-$LLVM_HASH " /llvm.tgz ]; then
96+ load_llvm
97+ else
98+ MLIR_DIR=" $llvm_dir /lib/cmake/mlir"
11299 fi
113- eval $ret_val =" $llvm_dir /lib/cmake/mlir"
114100 return 0
115101}
116102
117- get_llvm mlir_dir
103+ get_llvm
118104
119- fetch_dir= $project_dir /build/_deps
120- dylib =OFF
121- lit_path= " "
122- if [[ $( which lit) ]] ; then
123- lit_path= $( which lit )
124- fi
125- if [[ " $DEV_BUILD " == ' true ' ]] ; then
126- fetch_dir= $project_dir /externals
127- lit_path= $project_dir /externals/llvm-project/build/bin/llvm-lit
105+ FETCH_DIR= $PROJECT_DIR /build/_deps
106+ DYLIB =OFF
107+ # written in this form to set LIT_PATH in any case
108+ if ! LIT_PATH= $( which lit) ; then
109+ if [ " $DEV_BUILD " != ' true ' ] ; then
110+ echo " ========Warning======= "
111+ echo " Lit not found. "
112+ echo " ====================== "
113+ fi
128114fi
129- if [[ " $DYN_LINK " == ' true' ]]; then
130- dylib=ON
115+ if [ " $DEV_BUILD " = ' true' ]; then
116+ FETCH_DIR=$PROJECT_DIR /externals
117+ LIT_PATH=$PROJECT_DIR /externals/llvm-project/build/bin/llvm-lit
131118fi
132- if [ -z " $lit_path " ]; then
133- echo " ========Warning======="
134- echo " Lit not found. "
119+ if [ " $DYN_LINK " = ' true' ]; then
120+ DYLIB=ON
135121fi
136122
137123cmake -S . -G Ninja -B build \
138124 -DCMAKE_BUILD_TYPE=RelWithDebInfo \
139- -DMLIR_DIR=$mlir_dir \
140- -DLLVM_EXTERNAL_LIT=$lit_path \
141- -DFETCHCONTENT_BASE_DIR=$fetch_dir \
142- -DGC_DEV_LINK_LLVM_DYLIB=$dylib
125+ -DMLIR_DIR=$MLIR_DIR \
126+ -DLLVM_EXTERNAL_LIT=$LIT_PATH \
127+ -DFETCHCONTENT_BASE_DIR=$FETCH_DIR \
128+ -DGC_DEV_LINK_LLVM_DYLIB=$DYLIB
129+
143130cmake --build build --parallel $( nproc)
0 commit comments