From 77ca2683dab187b23cc81475b757c83289b81df2 Mon Sep 17 00:00:00 2001 From: septs Date: Sat, 16 Mar 2024 15:40:31 +0800 Subject: [PATCH] improve build.sh (#52) --- .github/workflows/build.yaml | 75 ++++++++++++++++++------------------ README.md | 8 ++-- scripts/build.sh | 54 ++++++++++++++------------ scripts/setup-debian.sh | 4 ++ scripts/setup-linux.sh | 5 --- 5 files changed, 75 insertions(+), 71 deletions(-) create mode 100755 scripts/setup-debian.sh delete mode 100755 scripts/setup-linux.sh diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 364ed0a..7ed10e9 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -9,59 +9,58 @@ on: branches: [main] jobs: - build-linux: - name: Build on Linux - runs-on: ubuntu-latest + build: + name: Build for ${{ matrix.build.name }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + build: + - {variant: make, name: Linux, artifact: linux-x64} + - {variant: debian, name: Debian, artifact: debian-x64} + - {variant: mingw, name: Windows with MinGW, artifact: windows-x64} + - {variant: woa-mingw, name: Windows on ARM with MinGW, artifact: windows-arm64} + include: + - os: macos-14 + build: {variant: make, name: macOS, artifact: macos-universal} steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Toolchain - run: ./scripts/setup-linux.sh - - name: Build for Linux - run: ./scripts/build.sh linux - - name: Build for Debian - run: ./scripts/build.sh debian - - name: Build for Windows with MinGW - run: ./scripts/build.sh mingw - - name: Build for Windows on ARM with MinGW - run: ./scripts/build.sh woa-mingw - - name: Build for Windows on ARM with Zig - run: ./scripts/build.sh woa-zig - - name: Upload Artifacts + run: ./scripts/setup-debian.sh + if: runner.os == 'Linux' + - name: Build for ${{ matrix.build.name }} + run: ./scripts/build.sh ${{ matrix.build.variant }} + - name: Upload ${{ matrix.build.name }} to Artifact uses: actions/upload-artifact@v4 with: - name: artifact-linux - path: | - lpac-*.deb - lpac-*.zip - build-macos: - name: Build on macOS - runs-on: macos-14 - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Build for macOS - run: ./scripts/build.sh macos - - name: Upload Artifacts - uses: actions/upload-artifact@v4 - with: - name: artifact-macos - path: lpac-*.zip + name: ${{ matrix.build.artifact }} + path: lpac-*.* release: name: Release runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/v') - needs: [build-linux, build-macos] + needs: build permissions: contents: write steps: - name: Download Artifact uses: actions/download-artifact@v4 with: - pattern: artifact-* + merge-multiple: true + pattern: '*' + - name: Run SHA1SUM + id: checksum + run: | + echo 'sha1sum<> $GITHUB_OUTPUT + sha1sum * >> $GITHUB_OUTPUT + echo 'EOF' >> $GITHUB_OUTPUT - name: Release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: - files: | - lpac-*.deb - lpac-*.zip + body: | + ```plain + ${{ steps.checksum.outputs.sha1sum }} + ``` + append_body: true + files: '*' diff --git a/README.md b/README.md index f40578e..e6b2a7d 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ lpac is dynamic-linked, Release is built by Github action, if you can't run it y sudo apt install build-essential cmake git g++ libpcsclite-dev libcurl4-openssl-dev git clone --depth=1 https://github.com/estkme-group/lpac cd lpac -./scripts/build.sh linux +./scripts/build.sh make ``` then execute `./output/lpac` to use. @@ -52,7 +52,7 @@ Same as normal Debian/Ubuntu, however, in order to build the GBinder backends, y ```bash git clone --depth=1 https://github.com/estkme-group/lpac cd lpac -./scripts/build.sh macos +./scripts/build.sh make ``` @@ -74,7 +74,7 @@ cd lpac - Build on Windows(MSYS2) ```bash -pacman -S mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja mingw-w64-x86_64-gcc +pacman -S mingw-w64-x86_64-cmake mingw-w64-x86_64-gcc git clone --depth=1 https://github.com/estkme-group/lpac cd lpac ./scripts/build.sh mingw @@ -120,7 +120,7 @@ cd lpac It is possible to build on **WoA devices** with [MSYS2 ARM64 Support](https://www.msys2.org/wiki/arm64/) -You may need to install `mingw-w64-clang-aarch64-cmake`, `mingw-w64-clang-aarch64-ninja`,`mingw-w64-clang-aarch64-clang` and modify `cmake/linux-mingw64.cmake`(replace toolchain). +You may need to install `mingw-w64-clang-aarch64-cmake`, `mingw-w64-clang-aarch64-clang` and modify `cmake/linux-mingw64.cmake`(replace toolchain). Download prebuilt curl dll is also needed. Refer to the previous compilation steps. diff --git a/scripts/build.sh b/scripts/build.sh index 6a9d3f9..fe085eb 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,6 +1,7 @@ #!/bin/bash set -euo pipefail WORKSPACE="$(pwd)" +KERNEL="$(uname -s)" MATCHINE="$(uname -m)" CURL_VERSION="8.6.0_1" WOA_TOOLCHAIN_VERSION="2024-02-08" @@ -8,6 +9,16 @@ MINGW_CURL_WIN64_BLOB="https://curl.se/windows/dl-$CURL_VERSION/curl-$CURL_VERSI MINGW_CURL_WIN64A_BLOB="https://curl.se/windows/dl-$CURL_VERSION/curl-$CURL_VERSION-win64a-mingw.zip" MINGW32_TOOLCHAIN_BLOB="https://github.com/Windows-on-ARM-Experiments/mingw-woarm64-build/releases/download/$WOA_TOOLCHAIN_VERSION/aarch64-w64-mingw32-msvcrt-toolchain.tar.gz" +case "$KERNEL" in +Linux) + KERNEL="linux" + ;; +Darwin) + KERNEL="darwin" + MATCHINE="universal" + ;; +esac + function download { URL="$1" SAVED_PATH="$(mktemp)" @@ -32,51 +43,46 @@ function download { set -x -rm -rf build -mkdir build -cd build || exit 1 +BUILD="$(mktemp -d)" +cd "$BUILD" || exit 1 case "${1:-}" in -linux) - cmake .. -GNinja - ninja - chmod +x output/lpac - zip -r -j "$WORKSPACE/lpac-linux-$MATCHINE.zip" output/* +make) + cmake "$WORKSPACE" + make -j + zip -r -j "$WORKSPACE/lpac-$KERNEL-$MATCHINE.zip" output/* ;; debian) - cmake .. -GNinja -DCPACK_GENERATOR=DEB - ninja package - cp lpac-*.deb .. + cmake "$WORKSPACE" -DCPACK_GENERATOR=DEB + make -j package + cp lpac-*.deb "$WORKSPACE" ;; mingw) - cmake .. -GNinja -DCMAKE_TOOLCHAIN_FILE=./cmake/linux-mingw64.cmake - ninja + cmake "$WORKSPACE" -DCMAKE_TOOLCHAIN_FILE=./cmake/linux-mingw64.cmake + make -j CURL="$(download "$MINGW_CURL_WIN64_BLOB")" cp "$CURL"/curl-*-mingw/bin/libcurl-x64.dll output/libcurl.dll zip -r -j "$WORKSPACE/lpac-windows-x86_64-mingw.zip" output/* ;; woa-mingw) TOOLCHAIN="$(download "$MINGW32_TOOLCHAIN_BLOB")" - cmake .. -GNinja -DCMAKE_TOOLCHAIN_FILE=./cmake/linux-mingw64-woa.cmake "-DTOOLCHAIN_BIN_PATH=$TOOLCHAIN/bin" - ninja + cmake "$WORKSPACE" -DCMAKE_TOOLCHAIN_FILE=./cmake/linux-mingw64-woa.cmake "-DTOOLCHAIN_BIN_PATH=$TOOLCHAIN/bin" + make -j CURL="$(download "$MINGW_CURL_WIN64A_BLOB")" cp "$CURL"/curl-*-mingw/bin/libcurl-arm64.dll output/libcurl.dll zip -r -j "$WORKSPACE/lpac-windows-arm64-mingw.zip" output/* ;; woa-zig) - cmake .. -GNinja -DCMAKE_TOOLCHAIN_FILE=./cmake/aarch64-windows-zig.cmake - ninja + cmake "$WORKSPACE" -DCMAKE_TOOLCHAIN_FILE=./cmake/aarch64-windows-zig.cmake + make -j CURL="$(download "$MINGW_CURL_WIN64A_BLOB")" cp "$CURL"/curl-*-mingw/bin/libcurl-arm64.dll output/libcurl.dll zip -r -j "$WORKSPACE/lpac-windows-arm64-zig.zip" output/* ;; -macos) - cmake .. - make "-j$(sysctl -n hw.ncpu)" - chmod +x output/lpac - zip -r -j "$WORKSPACE/lpac-macos-universal.zip" output/* - ;; *) - echo "Usage: $0 {build,debian,mingw,woa-mingw,woa-zig,macos}" + echo "Usage: $0 {make,debian,mingw,woa-mingw,woa-zig}" + exit 1 ;; esac + +rm -rf "$BUILD" diff --git a/scripts/setup-debian.sh b/scripts/setup-debian.sh new file mode 100755 index 0000000..305051a --- /dev/null +++ b/scripts/setup-debian.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -xeuo pipefail +sudo apt-get update +sudo apt-get install -y build-essential libpcsclite-dev libcurl4-openssl-dev gcc-mingw-w64 g++-mingw-w64 diff --git a/scripts/setup-linux.sh b/scripts/setup-linux.sh deleted file mode 100755 index 251d655..0000000 --- a/scripts/setup-linux.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -xeuo pipefail -sudo apt-get update -sudo apt-get install -y libpcsclite-dev libcurl4-openssl-dev gcc make cmake gcc-mingw-w64 g++-mingw-w64 unzip ninja-build -sudo snap install zig --classic --beta