-
Notifications
You must be signed in to change notification settings - Fork 0
244 lines (201 loc) · 8.04 KB
/
build-android-lua.yml
File metadata and controls
244 lines (201 loc) · 8.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
name: Build and Release Android Lua Libraries
# 仓库写入权限
permissions:
contents: write
on:
workflow_dispatch: # 允许手动触发
push:
tags:
- 'android-lua-v*' # 当推送标签时自动触发发布
env:
LUA_VERSION: 5.4.8
LUA_CJSON_VERSION: 2.1.0.15
ANDROID_NDK_VERSION: r26b
ANDROID_API_LEVEL: 21
CACHE_VERSION: v1 # 缓存版本,当NDK或工具链更新时修改此值
jobs:
build-android:
runs-on: ubuntu-latest
strategy:
matrix:
architecture: [armeabi-v7a, arm64-v8a, x86, x86_64]
outputs:
output_dir: ${{ steps.set_outputs.outputs.output_dir }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cache Android NDK
id: cache-ndk
uses: actions/cache@v4
with:
path: android-ndk-${{ env.ANDROID_NDK_VERSION }}
key: android-ndk-${{ env.ANDROID_NDK_VERSION }}-${{ env.CACHE_VERSION }}
- name: Download and extract Android NDK (if not cached)
if: steps.cache-ndk.outputs.cache-hit != 'true'
run: |
wget -q https://dl.google.com/android/repository/android-ndk-${{ env.ANDROID_NDK_VERSION }}-linux.zip
unzip -q android-ndk-${{ env.ANDROID_NDK_VERSION }}-linux.zip
rm android-ndk-${{ env.ANDROID_NDK_VERSION }}-linux.zip
- name: Set NDK environment
run: |
export ANDROID_NDK_HOME=$PWD/android-ndk-${{ env.ANDROID_NDK_VERSION }}
echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME" >> $GITHUB_ENV
- name: Cache Lua source code
id: cache-lua
uses: actions/cache@v4
with:
path: lua-${{ env.LUA_VERSION }}
key: lua-source-${{ env.LUA_VERSION }}
- name: Download Lua source code (if not cached)
if: steps.cache-lua.outputs.cache-hit != 'true'
run: |
wget -q https://www.lua.org/ftp/lua-${{ env.LUA_VERSION }}.tar.gz
tar -xzf lua-${{ env.LUA_VERSION }}.tar.gz
rm lua-${{ env.LUA_VERSION }}.tar.gz
- name: Cache lua-cjson source
id: cache-lua-cjson
uses: actions/cache@v4
with:
path: lua-cjson
key: lua-cjson-${{ env.LUA_CJSON_VERSION }}
- name: Download lua-cjson (if not cached)
if: steps.cache-lua-cjson.outputs.cache-hit != 'true'
run: |
git clone --depth 1 --branch ${{ env.LUA_CJSON_VERSION }} \
https://github.com/openresty/lua-cjson.git
- name: Setup toolchain
id: set_toolchain
run: |
case "${{ matrix.architecture }}" in
"armeabi-v7a")
export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi${{ env.ANDROID_API_LEVEL }}-clang
export ARCH=arm
export STRIP=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip
;;
"arm64-v8a")
export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android${{ env.ANDROID_API_LEVEL }}-clang
export ARCH=aarch64
export STRIP=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip
;;
"x86")
export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android${{ env.ANDROID_API_LEVEL }}-clang
export ARCH=i686
export STRIP=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip
;;
"x86_64")
export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android${{ env.ANDROID_API_LEVEL }}-clang
export ARCH=x86_64
export STRIP=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip
;;
esac
echo "TOOLCHAIN=$TOOLCHAIN" >> $GITHUB_ENV
echo "ARCH=$ARCH" >> $GITHUB_ENV
echo "STRIP=$STRIP" >> $GITHUB_ENV
- name: Build Lua for Android
run: |
cd lua-${{ env.LUA_VERSION }}
make clean
# Create custom Makefile for Android
cat > src/Makefile.android << 'EOF'
CC=${{ env.TOOLCHAIN }}
AR=${{ env.TOOLCHAIN }}ar
RANLIB=${{ env.TOOLCHAIN }}ranlib
STRIP=${{ env.STRIP }}
MYCFLAGS=-fPIC -O2 -I$(LUA_INC) -DLUA_USE_DLOPEN
MYLDFLAGS=-shared -Wl,-z,global
MYLIBS=-ldl -lm
PLAT= generic
CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \
lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \
ltm.o lundump.o lvm.o lzio.o
LIB_O= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o lstrlib.o \
lutf8lib.o loadlib.o lcorolib.o linit.o
LUA_T= liblua.so
LUA_O= lua.o
LUAC_T= luac
LUAC_O= luac.o
ALL_T= $(CORE_T) $(LUA_T)
ALL_O= $(CORE_O) $(LUA_O) $(LIB_O)
ALL_A= $(CORE_T)
all: $(ALL_T)
o: $(ALL_O)
$(LUA_T): $(CORE_O) $(LIB_O)
$(CC) -o $@ $(MYLDFLAGS) $(CORE_O) $(LIB_O) $(MYLIBS)
$(STRIP) --strip-unneeded $@
$(LUAC_T): $(LUAC_O) $(LIB_O)
$(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LIB_O) $(CORE_O) $(MYLIBS)
clean:
$(RM) $(ALL_T) $(ALL_O)
.c.o:
$(CC) $(MYCFLAGS) -c $<
EOF
# Build Lua
make -C src -f Makefile.android
# Create output directory with version in name
OUTPUT_NAME=liblua-${{ env.LUA_VERSION }}-android-${{ matrix.architecture }}.so
mkdir -p ../output/android/${{ matrix.architecture }}
cp src/liblua.so ../output/android/${{ matrix.architecture }}/$OUTPUT_NAME
# Also keep the original name for compatibility
cp src/liblua.so ../output/android/${{ matrix.architecture }}/liblua.so
echo "Built: $OUTPUT_NAME"
- name: Build lua-cjson for Android
run: |
LUA_SRC=$PWD/lua-${{ env.LUA_VERSION }}
CJSON_SRC=$PWD/lua-cjson
cd $CJSON_SRC
make clean || true
# 编译 cjson
${{ env.TOOLCHAIN }} \
-fPIC -O2 -shared \
-I$LUA_SRC/src \
-DLUA_USE_DLOPEN \
-o cjson.so \
lua_cjson.c strbuf.c fpconv.c \
-lm
# Strip
${{ env.STRIP }} --strip-unneeded cjson.so
# 输出
OUTPUT_NAME=cjson-${{ env.LUA_CJSON_VERSION }}-android-${{ matrix.architecture }}.so
mkdir -p ../output/android/${{ matrix.architecture }}
cp cjson.so ../output/android/${{ matrix.architecture }}/$OUTPUT_NAME
echo "Built cjson.so for ${{ matrix.architecture }}"
- name: Set output variables
id: set_outputs
run: |
echo "output_dir=output" >> $GITHUB_OUTPUT
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: lua-${{ env.LUA_VERSION }}-android-${{ matrix.architecture }}
path: output/android/${{ matrix.architecture }}/
retention-days: 7
create-release:
runs-on: ubuntu-latest
needs: build-android
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
pattern: lua-*-android-*
merge-multiple: true
- name: List downloaded files (debug)
run: |
echo "Downloaded artifacts:"
find artifacts -type f
- name: Create Release
uses: softprops/action-gh-release@v1
with:
name: Lua ${{ env.LUA_VERSION }} for Android
tag_name: Lua-v${{ env.LUA_VERSION }}-for-Android
files: |
artifacts/**/liblua-*-android-*.so
artifacts/**/cjson-*-android-*.so
generate_release_notes: false
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}