diff --git a/.github/workflows/build-android-lua.yml b/.github/workflows/build-android-lua.yml index d74ac54..f1146c6 100644 --- a/.github/workflows/build-android-lua.yml +++ b/.github/workflows/build-android-lua.yml @@ -208,9 +208,114 @@ jobs: path: output/android/${{ matrix.architecture }}/ retention-days: 7 + build-linux: + runs-on: ubuntu-latest + strategy: + matrix: + architecture: [x86_64, arm64] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Cache Lua source code + id: cache-lua-linux + 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-linux.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-linux + 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-linux.outputs.cache-hit != 'true' + run: | + git clone --depth 1 --branch ${{ env.LUA_CJSON_VERSION }} \ + https://github.com/openresty/lua-cjson.git + + - name: Install Linux build dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu + + - name: Setup Linux toolchain + run: | + case "${{ matrix.architecture }}" in + "x86_64") + echo "CC=gcc" >> $GITHUB_ENV + echo "AR=ar" >> $GITHUB_ENV + echo "RANLIB=ranlib" >> $GITHUB_ENV + ;; + "arm64") + echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV + echo "AR=aarch64-linux-gnu-ar" >> $GITHUB_ENV + echo "RANLIB=aarch64-linux-gnu-ranlib" >> $GITHUB_ENV + ;; + esac + + - name: Build Lua for Linux + run: | + cd lua-${{ env.LUA_VERSION }} + make clean + make linux CC="${{ env.CC }}" AR="${{ env.AR }} rcu" RANLIB="${{ env.RANLIB }}" MYCFLAGS="-fPIC -O2" MYLDFLAGS="-Wl,-E" + + ${{ env.CC }} -shared -o src/liblua.so \ + src/lapi.o src/lcode.o src/lctype.o src/ldebug.o src/ldo.o src/ldump.o src/lfunc.o \ + src/lgc.o src/llex.o src/lmem.o src/lobject.o src/lopcodes.o src/lparser.o src/lstate.o \ + src/lstring.o src/ltable.o src/ltm.o src/lundump.o src/lvm.o src/lzio.o \ + src/lauxlib.o src/lbaselib.o src/ldblib.o src/liolib.o src/lmathlib.o src/loslib.o \ + src/ltablib.o src/lstrlib.o src/lutf8lib.o src/loadlib.o src/lcorolib.o src/linit.o \ + -ldl -lm + + OUTPUT_NAME=liblua-${{ env.LUA_VERSION }}-linux-${{ matrix.architecture }}.so + mkdir -p ../output/linux/${{ matrix.architecture }} + cp src/liblua.so ../output/linux/${{ matrix.architecture }}/$OUTPUT_NAME + cp src/liblua.so ../output/linux/${{ matrix.architecture }}/liblua.so + echo "Built: $OUTPUT_NAME" + + - name: Build lua-cjson for Linux + run: | + LUA_SRC=$PWD/lua-${{ env.LUA_VERSION }} + CJSON_SRC=$PWD/lua-cjson + + cd $CJSON_SRC + make clean || true + + ${{ env.CC }} -fPIC -O2 -shared \ + -I$LUA_SRC/src \ + -DLUA_USE_DLOPEN \ + -o cjson.so \ + lua_cjson.c strbuf.c fpconv.c \ + -lm + + OUTPUT_NAME=cjson-${{ env.LUA_CJSON_VERSION }}-linux-${{ matrix.architecture }}.so + mkdir -p ../output/linux/${{ matrix.architecture }} + cp cjson.so ../output/linux/${{ matrix.architecture }}/$OUTPUT_NAME + + echo "Built cjson.so for linux-${{ matrix.architecture }}" + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: lua-${{ env.LUA_VERSION }}-linux-${{ matrix.architecture }} + path: output/linux/${{ matrix.architecture }}/ + retention-days: 7 + create-release: runs-on: ubuntu-latest - needs: build-android + needs: [build-android, build-linux] if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' steps: @@ -221,7 +326,7 @@ jobs: uses: actions/download-artifact@v4 with: path: artifacts - pattern: lua-*-android-* + pattern: lua-*-* merge-multiple: true - name: List downloaded files (debug) @@ -232,11 +337,13 @@ jobs: - 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 + name: Lua ${{ env.LUA_VERSION }} for Android and Linux + tag_name: Lua-v${{ env.LUA_VERSION }}-for-Android-and-Linux files: | artifacts/**/liblua-*-android-*.so artifacts/**/cjson-*-android-*.so + artifacts/**/liblua-*-linux-*.so + artifacts/**/cjson-*-linux-*.so generate_release_notes: false draft: false prerelease: false