@@ -2,32 +2,70 @@ name: test build process
22
33on :
44 push :
5- branches : [ main, ci ]
5+ branches : [ main, ci, ci-test ]
66 pull_request :
7- branches : [ main, ci ]
7+ branches : [ main, ci, ci-test ]
88
99jobs :
10- build :
11- runs-on : self-hosted
10+ test :
11+ name : Build (${{ matrix.arch }})
12+ timeout-minutes : 360
13+ continue-on-error : ${{ matrix.experimental }}
14+
15+ concurrency :
16+ group : buddy-mlir-${{ matrix.arch }}
17+ cancel-in-progress : true
18+
19+ strategy :
20+ fail-fast : false
21+ matrix :
22+ include :
23+ - arch : x64
24+ experimental : false
25+ - arch : riscv64
26+ experimental : true
27+
28+ runs-on :
29+ - self-hosted
30+ - ${{ matrix.arch }}
31+
1232 steps :
33+ - name : Print target
34+ run : |
35+ echo "Building on ${{ matrix.arch }}"
36+ echo "------ uname ------"
37+ uname -a
38+
1339 # 0. Install the Ninja build system.
1440 - name : Set up ninja
41+ if : matrix.arch == 'x64'
1542 uses : seanmiddleditch/gha-setup-ninja@master
1643
17- # 1 . Checkout the main repository without fetching submodules initially
44+ # 1A . Checkout the main repository without fetching submodules initially
1845 - name : Checkout main repository
46+ if : matrix.arch == 'x64'
1947 uses : actions/checkout@v4
2048 with :
2149 submodules : ' false'
2250
51+ # 1B. first clone from local gitea then update metedata from github
52+ - name : Checkout from local Gitea (riscv64)
53+ if : matrix.arch == 'riscv64'
54+ run : |
55+ git clone --no-checkout https://community-ci.openruyi.cn/RuyiAI-Stack/buddy-mlir .
56+ git remote add github https://github.com/buddy-compiler/buddy-mlir.git
57+ git fetch github ${{ github.sha }}
58+ git checkout ${{ github.sha }}
59+
2360 # 2. Retrieve the commit ID of the LLVM submodule.
2461 - name : Get LLVM submodule commit
2562 id : llvm-submodule-commit
2663 run : |
2764 echo "commit=$(git submodule status llvm | awk '{print $1;}')" >> $GITHUB_OUTPUT
2865
29- # 3. Cache the LLVM submodule source code.
30- - name : Cache LLVM source
66+ # 3. Cache the LLVM submodule source code (only for x86).
67+ - name : Cache LLVM source (x86)
68+ if : matrix.arch == 'x64'
3169 id : cache-llvm-source
3270 uses : actions/cache@v4
3371 with :
@@ -36,15 +74,16 @@ jobs:
3674 restore-keys : |
3775 llvm-source-
3876
39- # 4. If the cache is not found, pull the LLVM submodule.
77+ # 4. If the cache is not found, pull the LLVM submodule. (x86, cache miss)
4078 - name : Checkout LLVM submodule
79+ if : matrix.arch == 'x64' && steps.cache-llvm-source.outputs.cache-hit != 'true'
4180 run : |
4281 rm -rf llvm
4382 git submodule update --init --recursive llvm
44- if : steps.cache-llvm-source.outputs.cache-hit != 'true'
4583
4684 # 5. Cache the LLVM build directory.
4785 - name : Cache LLVM build directory
86+ if : matrix.arch == 'x64'
4887 id : cache-llvm-build-dir
4988 uses : actions/cache@v4
5089 with :
5493 llvm-build-
5594
5695 # 6. Verify llvm-build when cached; build LLVM when no cache or verification fails.
57- - name : Check LLVM cache
96+ - name : Check LLVM cache (x86)
5897 id : check-llvm-cache
59- if : steps.cache-llvm-build-dir.outputs.cache-hit == 'true'
98+ if : matrix.arch == 'x64' && ( steps.cache-llvm-build-dir.outputs.cache-hit == 'true')
6099 run : |
61100 for conda in ~/miniconda3/bin/activate ~/miniforge3/bin/activate; do
62101 [ -f "$conda" ] && source "$conda" buddy && break
72111 fi
73112 continue-on-error : true
74113
75- - name : Configure and Build LLVM
76- if : steps.cache-llvm-build-dir.outputs.cache-hit != 'true' || steps.check-llvm-cache.outputs.need-rebuild == 'true'
114+ - name : Configure and Build LLVM (x86)
115+ if : matrix.arch == 'x64' &&
116+ (steps.cache-llvm-build-dir.outputs.cache-hit != 'true' || steps.check-llvm-cache.outputs.need-rebuild == 'true')
77117 run : |
78118 for conda in ~/miniconda3/bin/activate ~/miniforge3/bin/activate; do
79119 [ -f "$conda" ] && source "$conda" buddy && break
@@ -94,8 +134,76 @@ jobs:
94134 -DPython3_EXECUTABLE=$(which python3)
95135 ninja check-clang check-mlir omp
96136
97- # 7. Check buddy-mlir build.
98- - name : Check buddy-mlir build
137+ - name : Enable ccache (riscv64)
138+ if : matrix.arch == 'riscv64'
139+ run : |
140+ echo "CCACHE_DIR=/home/jenkins/.ccache" >> $GITHUB_ENV
141+ echo "PATH=/usr/lib/ccache:$PATH" >> $GITHUB_ENV
142+ ccache -M 50G
143+ echo "CCACHE_MAXSIZE=50G" >> $GITHUB_ENV
144+
145+ - name : Setup LLVM build (riscv64)
146+ if : matrix.arch == 'riscv64'
147+ id : prepare-llvm-build
148+ run : |
149+ LLVM_SRC=/home/jenkins/src/llvm-project
150+ LLVM_BUILD_ROOT=/home/jenkins/llvm-cache
151+ LLVM_COMMIT=$(git ls-tree HEAD llvm | awk '{print $3}')
152+ LLVM_BUILD_DIR=$LLVM_BUILD_ROOT/$LLVM_COMMIT
153+
154+ mkdir -p $LLVM_BUILD_ROOT
155+
156+ # prepare source
157+ if [ ! -d "$LLVM_SRC" ]; then
158+ mkdir -p /home/jenkins/src
159+ git clone https://community-ci.openruyi.cn/toolchain/llvm-project.git $LLVM_SRC
160+ fi
161+
162+ git -C $LLVM_SRC fetch --all
163+ git -C $LLVM_SRC reset --hard
164+ git -C $LLVM_SRC clean -fdx
165+ git -C $LLVM_SRC checkout $LLVM_COMMIT
166+
167+ echo "LLVM_SRC=$LLVM_SRC" >> $GITHUB_ENV
168+ echo "LLVM_COMMIT=$LLVM_COMMIT" >> $GITHUB_ENV
169+ echo "LLVM_BUILD_DIR=$LLVM_BUILD_DIR" >> $GITHUB_ENV
170+
171+ if [ -f "$LLVM_BUILD_DIR/build/CMakeCache.txt" ] &&
172+ grep -q "$LLVM_SRC" "$LLVM_BUILD_DIR/build/CMakeCache.txt"; then
173+ echo "need-rebuild=false" >> $GITHUB_OUTPUT
174+ else
175+ echo "need-rebuild=true" >> $GITHUB_OUTPUT
176+ fi
177+
178+ - name : Configure and Build LLVM (riscv64)
179+ if : matrix.arch == 'riscv64'&&
180+ steps.prepare-llvm-build.outputs.need-rebuild == 'true'
181+ run : |
182+ source /home/jenkins/venv/bin/activate
183+ pip install -U pip setuptools wheel packaging
184+ sed -i \
185+ -e '1s/^/# /' \
186+ requirements.txt
187+ pip install -r requirements.txt
188+ rm -rf $LLVM_BUILD_DIR
189+ cmake -G Ninja -S $LLVM_SRC/llvm -B $LLVM_BUILD_DIR/build \
190+ -DLLVM_ENABLE_PROJECTS="mlir;clang;openmp" \
191+ -DLLVM_TARGETS_TO_BUILD="host;RISCV" \
192+ -DLLVM_ENABLE_ASSERTIONS=ON \
193+ -DCMAKE_BUILD_TYPE=RELEASE \
194+ -DMLIR_ENABLE_BINDINGS_PYTHON=ON \
195+ -DPython3_EXECUTABLE=$(which python3)
196+ ninja -C $LLVM_BUILD_DIR/build check-clang check-mlir omp -j$(nproc) || true
197+ deactivate
198+
199+ - name : Show ccache stats (riscv64)
200+ if : matrix.arch == 'riscv64'
201+ run : |
202+ ccache -s
203+
204+ # 7A. Check buddy-mlir build (x86).
205+ - name : Check buddy-mlir build (x86)
206+ if : matrix.arch == 'x64'
99207 run : |
100208 for conda in ~/miniconda3/bin/activate ~/miniforge3/bin/activate; do
101209 [ -f "$conda" ] && source "$conda" buddy && break
@@ -113,3 +221,38 @@ jobs:
113221 -DPython3_EXECUTABLE=$(which python3)
114222 ninja
115223 ninja check-buddy
224+
225+ # 7B. Check buddy-mlir build (riscv64).
226+ - name : Check buddy-mlir build (riscv64)
227+ if : matrix.arch == 'riscv64'
228+ run : |
229+ source /home/jenkins/venv/bin/activate
230+ echo "---- CHECK LOCAL SUBMODULE ----"
231+ ls -l llvm || true
232+ git submodule status || true
233+ rm -rf build
234+ mkdir build
235+ cd build
236+
237+ # It will fail to find source code if no -DLLVM_MAIN_SRC_DIR=$LLVM_SRC/llvm -DMLIR_MAIN_SRC_DIR=$LLVM_SRC/mlir
238+ cmake -G Ninja .. \
239+ -DMLIR_DIR=$LLVM_BUILD_DIR/build/lib/cmake/mlir \
240+ -DLLVM_DIR=$LLVM_BUILD_DIR/build/lib/cmake/llvm \
241+ -DLLVM_MAIN_SRC_DIR=$LLVM_SRC/llvm \
242+ -DMLIR_MAIN_SRC_DIR=$LLVM_SRC/mlir \
243+ -DLLVM_ENABLE_ASSERTIONS=ON \
244+ -DCMAKE_BUILD_TYPE=RELEASE \
245+ -DBUDDY_MLIR_ENABLE_PYTHON_PACKAGES=ON \
246+ -DPython3_EXECUTABLE=$(which python3)
247+ ninja -j$(nproc)
248+ ninja check-buddy -j$(nproc) || true
249+ deactivate
250+
251+ - name : Cleanup old LLVM build cache (riscv64)
252+ if : matrix.arch == 'riscv64'
253+ run : |
254+ CACHE_DIR=/home/jenkins/llvm-cache
255+ KEEP=3
256+
257+ cd $CACHE_DIR
258+ ls -1dt */ | tail -n +$((KEEP+1)) | xargs -r rm -rf
0 commit comments