Skip to content

Commit

Permalink
improve build.sh (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
septs authored Mar 16, 2024
1 parent 695b72f commit 77ca268
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 71 deletions.
75 changes: 37 additions & 38 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
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-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<<EOF' >> $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: '*'
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
```

</details>
Expand All @@ -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
Expand Down Expand Up @@ -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.

Expand Down
54 changes: 30 additions & 24 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
#!/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"
MINGW_CURL_WIN64_BLOB="https://curl.se/windows/dl-$CURL_VERSION/curl-$CURL_VERSION-win64-mingw.zip"
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)"
Expand All @@ -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"
4 changes: 4 additions & 0 deletions scripts/setup-debian.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 0 additions & 5 deletions scripts/setup-linux.sh

This file was deleted.

0 comments on commit 77ca268

Please sign in to comment.