Skip to content

Commit 5d089af

Browse files
authored
Update Lua version in Android build workflow
0 parents  commit 5d089af

1 file changed

Lines changed: 121 additions & 0 deletions

File tree

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Build Android Lua for Multiple Architectures
2+
3+
on:
4+
workflow_dispatch: # 允许手动触发
5+
6+
env:
7+
LUA_VERSION: 5.4.8
8+
ANDROID_NDK_VERSION: r26b
9+
ANDROID_API_LEVEL: 21
10+
11+
jobs:
12+
build-android:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
architecture: [armeabi-v7a, arm64-v8a, x86, x86_64]
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up environment
23+
run: |
24+
sudo apt-get update
25+
sudo apt-get install -y wget unzip make gcc
26+
27+
- name: Download and extract Android NDK
28+
run: |
29+
wget https://dl.google.com/android/repository/android-ndk-${{ env.ANDROID_NDK_VERSION }}-linux.zip
30+
unzip -q android-ndk-${{ env.ANDROID_NDK_VERSION }}-linux.zip
31+
export ANDROID_NDK_HOME=$PWD/android-ndk-${{ env.ANDROID_NDK_VERSION }}
32+
echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME" >> $GITHUB_ENV
33+
34+
- name: Download Lua source code
35+
run: |
36+
wget https://www.lua.org/ftp/lua-${{ env.LUA_VERSION }}.tar.gz
37+
tar -xzf lua-${{ env.LUA_VERSION }}.tar.gz
38+
cd lua-${{ env.LUA_VERSION }}
39+
40+
- name: Setup toolchain
41+
id: set_toolchain
42+
run: |
43+
case "${{ matrix.architecture }}" in
44+
"armeabi-v7a")
45+
export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi${{ env.ANDROID_API_LEVEL }}-clang
46+
export ARCH=arm
47+
;;
48+
"arm64-v8a")
49+
export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android${{ env.ANDROID_API_LEVEL }}-clang
50+
export ARCH=aarch64
51+
;;
52+
"x86")
53+
export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android${{ env.ANDROID_API_LEVEL }}-clang
54+
export ARCH=i686
55+
;;
56+
"x86_64")
57+
export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android${{ env.ANDROID_API_LEVEL }}-clang
58+
export ARCH=x86_64
59+
;;
60+
esac
61+
echo "TOOLCHAIN=$TOOLCHAIN" >> $GITHUB_ENV
62+
echo "ARCH=$ARCH" >> $GITHUB_ENV
63+
64+
- name: Build Lua for Android
65+
run: |
66+
cd lua-${{ env.LUA_VERSION }}
67+
make clean
68+
69+
# Create custom Makefile for Android
70+
cat > src/Makefile.android << 'EOF'
71+
CC=${{ env.TOOLCHAIN }}
72+
AR=${{ env.TOOLCHAIN }}ar
73+
RANLIB=${{ env.TOOLCHAIN }}ranlib
74+
MYCFLAGS=-fPIC -O2 -I$(LUA_INC) -DLUA_USE_DLOPEN
75+
MYLDFLAGS=-shared
76+
PLAT= generic
77+
78+
CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
79+
lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o \
80+
lvm.o lzio.o
81+
LIB_O= lauxlib.o lbaselib.o lcorolib.o ldblib.o liolib.o lmathlib.o loslib.o lstrlib.o \
82+
ltablib.o linit.o
83+
84+
LUA_T= liblua.so
85+
LUA_O= lua.o
86+
87+
LUAC_T= luac
88+
LUAC_O= luac.o
89+
90+
ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)
91+
ALL_T= $(LUA_T) $(LUAC_T)
92+
93+
all: $(ALL_T)
94+
95+
o: $(ALL_O)
96+
97+
$(LUA_T): $(CORE_O) $(LIB_O)
98+
$(CC) -o $@ $(MYLDFLAGS) $(CORE_O) $(LIB_O) $(MYLIBS)
99+
100+
$(LUAC_T): $(LUAC_O) $(LIB_O)
101+
$(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LIB_O) $(CORE_O) $(MYLIBS)
102+
103+
clean:
104+
$(RM) $(ALL_T) $(ALL_O)
105+
106+
.c.o:
107+
$(CC) $(MYCFLAGS) -c $<
108+
EOF
109+
110+
# Build Lua
111+
make -C src -f Makefile.android
112+
113+
# Create output directory
114+
mkdir -p ../output/android/${{ matrix.architecture }}
115+
cp src/liblua.so ../output/android/${{ matrix.architecture }}/
116+
117+
- name: Upload artifacts
118+
uses: actions/upload-artifact@v4
119+
with:
120+
name: lua-android-${{ matrix.architecture }}
121+
path: output/android/${{ matrix.architecture }}/liblua.so

0 commit comments

Comments
 (0)