Skip to content

Commit 6c5a72c

Browse files
committed
ci: build Linux Lua artifacts for x86_64 and arm64
1 parent 4603d93 commit 6c5a72c

1 file changed

Lines changed: 111 additions & 4 deletions

File tree

.github/workflows/build-android-lua.yml

Lines changed: 111 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,114 @@ jobs:
208208
path: output/android/${{ matrix.architecture }}/
209209
retention-days: 7
210210

211+
build-linux:
212+
runs-on: ubuntu-latest
213+
strategy:
214+
matrix:
215+
architecture: [x86_64, arm64]
216+
217+
steps:
218+
- name: Checkout repository
219+
uses: actions/checkout@v4
220+
221+
- name: Cache Lua source code
222+
id: cache-lua-linux
223+
uses: actions/cache@v4
224+
with:
225+
path: lua-${{ env.LUA_VERSION }}
226+
key: lua-source-${{ env.LUA_VERSION }}
227+
228+
- name: Download Lua source code (if not cached)
229+
if: steps.cache-lua-linux.outputs.cache-hit != 'true'
230+
run: |
231+
wget -q https://www.lua.org/ftp/lua-${{ env.LUA_VERSION }}.tar.gz
232+
tar -xzf lua-${{ env.LUA_VERSION }}.tar.gz
233+
rm lua-${{ env.LUA_VERSION }}.tar.gz
234+
235+
- name: Cache lua-cjson source
236+
id: cache-lua-cjson-linux
237+
uses: actions/cache@v4
238+
with:
239+
path: lua-cjson
240+
key: lua-cjson-${{ env.LUA_CJSON_VERSION }}
241+
242+
- name: Download lua-cjson (if not cached)
243+
if: steps.cache-lua-cjson-linux.outputs.cache-hit != 'true'
244+
run: |
245+
git clone --depth 1 --branch ${{ env.LUA_CJSON_VERSION }} \
246+
https://github.com/openresty/lua-cjson.git
247+
248+
- name: Install Linux build dependencies
249+
run: |
250+
sudo apt-get update
251+
sudo apt-get install -y build-essential gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
252+
253+
- name: Setup Linux toolchain
254+
run: |
255+
case "${{ matrix.architecture }}" in
256+
"x86_64")
257+
echo "CC=gcc" >> $GITHUB_ENV
258+
echo "AR=ar" >> $GITHUB_ENV
259+
echo "RANLIB=ranlib" >> $GITHUB_ENV
260+
;;
261+
"arm64")
262+
echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
263+
echo "AR=aarch64-linux-gnu-ar" >> $GITHUB_ENV
264+
echo "RANLIB=aarch64-linux-gnu-ranlib" >> $GITHUB_ENV
265+
;;
266+
esac
267+
268+
- name: Build Lua for Linux
269+
run: |
270+
cd lua-${{ env.LUA_VERSION }}
271+
make clean
272+
make linux CC="${{ env.CC }}" AR="${{ env.AR }} rcu" RANLIB="${{ env.RANLIB }}" MYCFLAGS="-fPIC -O2" MYLDFLAGS="-Wl,-E"
273+
274+
${{ env.CC }} -shared -o src/liblua.so \
275+
src/lapi.o src/lcode.o src/lctype.o src/ldebug.o src/ldo.o src/ldump.o src/lfunc.o \
276+
src/lgc.o src/llex.o src/lmem.o src/lobject.o src/lopcodes.o src/lparser.o src/lstate.o \
277+
src/lstring.o src/ltable.o src/ltm.o src/lundump.o src/lvm.o src/lzio.o \
278+
src/lauxlib.o src/lbaselib.o src/ldblib.o src/liolib.o src/lmathlib.o src/loslib.o \
279+
src/ltablib.o src/lstrlib.o src/lutf8lib.o src/loadlib.o src/lcorolib.o src/linit.o \
280+
-ldl -lm
281+
282+
OUTPUT_NAME=liblua-${{ env.LUA_VERSION }}-linux-${{ matrix.architecture }}.so
283+
mkdir -p ../output/linux/${{ matrix.architecture }}
284+
cp src/liblua.so ../output/linux/${{ matrix.architecture }}/$OUTPUT_NAME
285+
cp src/liblua.so ../output/linux/${{ matrix.architecture }}/liblua.so
286+
echo "Built: $OUTPUT_NAME"
287+
288+
- name: Build lua-cjson for Linux
289+
run: |
290+
LUA_SRC=$PWD/lua-${{ env.LUA_VERSION }}
291+
CJSON_SRC=$PWD/lua-cjson
292+
293+
cd $CJSON_SRC
294+
make clean || true
295+
296+
${{ env.CC }} -fPIC -O2 -shared \
297+
-I$LUA_SRC/src \
298+
-DLUA_USE_DLOPEN \
299+
-o cjson.so \
300+
lua_cjson.c strbuf.c fpconv.c \
301+
-lm
302+
303+
OUTPUT_NAME=cjson-${{ env.LUA_CJSON_VERSION }}-linux-${{ matrix.architecture }}.so
304+
mkdir -p ../output/linux/${{ matrix.architecture }}
305+
cp cjson.so ../output/linux/${{ matrix.architecture }}/$OUTPUT_NAME
306+
307+
echo "Built cjson.so for linux-${{ matrix.architecture }}"
308+
309+
- name: Upload artifacts
310+
uses: actions/upload-artifact@v4
311+
with:
312+
name: lua-${{ env.LUA_VERSION }}-linux-${{ matrix.architecture }}
313+
path: output/linux/${{ matrix.architecture }}/
314+
retention-days: 7
315+
211316
create-release:
212317
runs-on: ubuntu-latest
213-
needs: build-android
318+
needs: [build-android, build-linux]
214319
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
215320

216321
steps:
@@ -221,7 +326,7 @@ jobs:
221326
uses: actions/download-artifact@v4
222327
with:
223328
path: artifacts
224-
pattern: lua-*-android-*
329+
pattern: lua-*-*
225330
merge-multiple: true
226331

227332
- name: List downloaded files (debug)
@@ -232,11 +337,13 @@ jobs:
232337
- name: Create Release
233338
uses: softprops/action-gh-release@v1
234339
with:
235-
name: Lua ${{ env.LUA_VERSION }} for Android
236-
tag_name: Lua-v${{ env.LUA_VERSION }}-for-Android
340+
name: Lua ${{ env.LUA_VERSION }} for Android and Linux
341+
tag_name: Lua-v${{ env.LUA_VERSION }}-for-Android-and-Linux
237342
files: |
238343
artifacts/**/liblua-*-android-*.so
239344
artifacts/**/cjson-*-android-*.so
345+
artifacts/**/liblua-*-linux-*.so
346+
artifacts/**/cjson-*-linux-*.so
240347
generate_release_notes: false
241348
draft: false
242349
prerelease: false

0 commit comments

Comments
 (0)