Skip to content

Commit

Permalink
refactor: bash scripts (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
septs authored Jun 24, 2024
1 parent f5956dd commit d508b28
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 107 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
name: Build for ${{ matrix.build.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
fail-fast: false
matrix:
os: [ubuntu-latest]
build:
Expand All @@ -29,7 +29,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup Toolchain
run: ./scripts/setup-debian.sh
run: sudo ./scripts/setup-debian.sh ${{ matrix.build.variant }}
if: runner.os == 'Linux'

- name: Build for ${{ matrix.build.name }}
Expand Down
84 changes: 22 additions & 62 deletions scripts/build-ci.sh
Original file line number Diff line number Diff line change
@@ -1,66 +1,25 @@
#!/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
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

function download {
URL="$1"
SAVED_PATH="$(mktemp)"
SAVED_DIR="$(mktemp -d)"
wget --no-verbose "$URL" -O "$SAVED_PATH"
case "$URL" in
*.zip)
unzip -q -d "$SAVED_DIR" "$SAVED_PATH"
rm "$SAVED_PATH"
echo "$SAVED_DIR"
;;
*.tar.gz)
tar -C "$SAVED_DIR" --gzip --extract --file="$SAVED_PATH"
rm "$SAVED_PATH"
echo "$SAVED_DIR"
;;
*)
echo "$SAVED_PATH"
;;
esac
}
source "$SCRIPT_DIR/functions.sh"

set -x
set -euo pipefail

BUILD="$(mktemp -d)"
cd "$BUILD" || exit 1

ARTIFACT="$WORKSPACE/build"

mkdir "$BUILD/output"
[ -d "$ARTIFACT" ] || mkdir "$ARTIFACT"
cd "$BUILD" || exit 1

cp "$WORKSPACE/src/LICENSE" "$BUILD/output/lpac-LICENSE"
cp "$WORKSPACE/euicc/LICENSE" "$BUILD/output/libeuicc-LICENSE"
cp "$WORKSPACE/cjson/LICENSE" "$BUILD/output/cjson-LICENSE"
cp "$WORKSPACE/dlfcn-win32/LICENSE" "$BUILD/output/dlfcn-win32-LICENSE"
mkdir -p "$BUILD/output"
mkdir -p "$ARTIFACT"

case "${1:-}" in
make)
cmake "$WORKSPACE"
make -j
zip -r -j "$ARTIFACT/lpac-$KERNEL-$MATCHINE.zip" output/*
copy-license "$BUILD/output"
copy-usage "$BUILD/output"
create-bundle "$ARTIFACT/lpac-$KERNEL-$MATCHINE.zip" "$BUILD/output"
;;
debian)
cmake "$WORKSPACE" -DCPACK_GENERATOR=DEB
Expand All @@ -70,27 +29,28 @@ debian)
mingw)
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
cp "$CURL"/curl-*-mingw/COPYING.txt output/libcurl-LICENSE
zip -r -j "$ARTIFACT/lpac-windows-x86_64-mingw.zip" output/*
copy-license "$BUILD/output"
copy-curl-win "$BUILD/output"
copy-usage "$BUILD/output"
create-bundle "$ARTIFACT/lpac-windows-x86_64-mingw.zip" "$BUILD/output"
;;
woa-mingw)
TOOLCHAIN="$(download "$MINGW32_TOOLCHAIN_BLOB")"
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
cp "$CURL"/curl-*-mingw/COPYING.txt output/libcurl-LICENSE
zip -r -j "$ARTIFACT/lpac-windows-arm64-mingw.zip" output/*
rm -rf "$TOOLCHAIN"
copy-license "$BUILD/output"
copy-curl-woa "$BUILD/output"
copy-usage "$BUILD/output"
create-bundle "$ARTIFACT/lpac-windows-arm64-mingw.zip" "$BUILD/output"
;;
woa-zig)
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
cp "$CURL"/curl-*-mingw/COPYING.txt output/libcurl-LICENSE
zip -r -j "$ARTIFACT/lpac-windows-arm64-zig.zip" output/*
copy-license "$BUILD/output"
copy-curl-woa "$BUILD/output"
copy-usage "$BUILD/output"
create-bundle "$ARTIFACT/lpac-windows-arm64-zig.zip" "$BUILD/output"
;;
*)
echo "Usage: $0 {make,debian,mingw,woa-mingw,woa-zig}"
Expand Down
49 changes: 9 additions & 40 deletions scripts/build-woa.sh
Original file line number Diff line number Diff line change
@@ -1,59 +1,28 @@
#!/bin/bash
set -euo pipefail
WORKSPACE="$(pwd)"
CURL_VERSION="8.6.0_1"
WOA_TOOLCHAIN_VERSION="2024-02-08"
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"
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

function download {
URL="$1"
SAVED_PATH="$(mktemp)"
SAVED_DIR="$(mktemp -d)"
wget --no-verbose "$URL" -O "$SAVED_PATH"
case "$URL" in
*.zip)
unzip -q -d "$SAVED_DIR" "$SAVED_PATH"
rm "$SAVED_PATH"
echo "$SAVED_DIR"
;;
*.tar.gz)
tar -C "$SAVED_DIR" --gzip --extract --file="$SAVED_PATH"
rm "$SAVED_PATH"
echo "$SAVED_DIR"
;;
*)
echo "$SAVED_PATH"
;;
esac
}
source "$SCRIPT_DIR/functions.sh"

set -x
set -euo pipefail

BUILD="$(mktemp -d)"
cd "$BUILD" || exit 1

mkdir "$BUILD/output"
cp "$WORKSPACE/src/LICENSE" output/lpac-LICENSE
cp "$WORKSPACE/euicc/LICENSE" output/libeuicc-LICENSE
cp "$WORKSPACE/cjson/LICENSE" output/cjson-LICENSE
cp "$WORKSPACE/dlfcn-win32/LICENSE" output/dlfcn-win32-LICENSE

case "${1:-}" in
mingw)
TOOLCHAIN="$(download "$MINGW32_TOOLCHAIN_BLOB")"
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
cp "$CURL"/curl-*-mingw/COPYING.txt output/libcurl-LICENSE
copy-license "$BUILD/output"
copy-curl-woa "$BUILD/output"
copy-usage "$BUILD/output"
;;
zig)
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
cp "$CURL"/curl-*-mingw/COPYING.txt output/libcurl-LICENSE
copy-license "$BUILD/output"
copy-curl-woa "$BUILD/output"
copy-usage "$BUILD/output"
;;
*)
echo "Usage: $0 {mingw,zig}"
Expand Down
84 changes: 84 additions & 0 deletions scripts/functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash
export KERNEL="$(uname -s)"
export MATCHINE="$(uname -m)"

export WORKSPACE="${GITHUB_WORKSPACE:-$(pwd)}"
export CURL_VERSION="8.6.0_1"
export WOA_TOOLCHAIN_VERSION="2024-02-08"
export MINGW_CURL_WIN64_BLOB="https://curl.se/windows/dl-$CURL_VERSION/curl-$CURL_VERSION-win64-mingw.zip"
export MINGW_CURL_WIN64A_BLOB="https://curl.se/windows/dl-$CURL_VERSION/curl-$CURL_VERSION-win64a-mingw.zip"
export 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 {
local URL="$1"
local SAVED_PATH="$(mktemp)"
local SAVED_DIR="$(mktemp -d)"
wget --no-verbose "$URL" -O "$SAVED_PATH"
case "$URL" in
*.zip)
unzip -q -d "$SAVED_DIR" "$SAVED_PATH"
rm "$SAVED_PATH"
echo "$SAVED_DIR"
;;
*.tar.gz)
tar -C "$SAVED_DIR" --gzip --extract --file="$SAVED_PATH"
rm "$SAVED_PATH"
echo "$SAVED_DIR"
;;
*)
echo "$SAVED_PATH"
;;
esac
}

function copy-license {
local OUTPUT="$1"

cp "$WORKSPACE/src/LICENSE" "$OUTPUT/LICENSE-lpac"
cp "$WORKSPACE/euicc/LICENSE" "$OUTPUT/LICENSE-libeuicc"
cp "$WORKSPACE/cjson/LICENSE" "$OUTPUT/LICENSE-cjson"
cp "$WORKSPACE/dlfcn-win32/LICENSE" "$OUTPUT/LICENSE-dlfcn-win32"
}

function copy-curl-woa {
local OUTPUT="$1"

CURL="$(download "$MINGW_CURL_WIN64A_BLOB")"
cp "$CURL"/curl-*-mingw/bin/libcurl-arm64.dll "$OUTPUT/libcurl.dll"
cp "$CURL"/curl-*-mingw/COPYING.txt "$OUTPUT/LICENSE-libcurl"
rm -rf "$CURL"
}

function copy-curl-win {
local OUTPUT="$1"

CURL="$(download "$MINGW_CURL_WIN64_BLOB")"
cp "$CURL"/curl-*-mingw/bin/libcurl-x64.dll "$OUTPUT/libcurl.dll"
cp "$CURL"/curl-*-mingw/COPYING.txt "$OUTPUT/LICENSE-libcurl"
rm -rf "$CURL"
}

function copy-usage {
local OUTPUT="$1"

cp "$WORKSPACE/docs/USAGE.md" "$OUTPUT/README.md"
}

function create-bundle {
local BUNDLE_FILE="$1"
local INPUT_DIR="$2"

pushd "$INPUT_DIR"
zip -r "$BUNDLE_FILE" *
popd
}
15 changes: 12 additions & 3 deletions scripts/setup-debian.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
#!/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 zip
set -euo pipefail
export DEBIAN_FRONTEND=noninteractive
export DEBIAN_PRIORITY=critical

apt-get -qq -o=Dpkg::Use-Pty=0 update
apt-get -qq -o=Dpkg::Use-Pty=0 install -y build-essential libpcsclite-dev libcurl4-openssl-dev zip

case "${1:-}" in
mingw)
apt-get -qq -o=Dpkg::Use-Pty=0 install gcc-mingw-w64 g++-mingw-w64
;;
esac

0 comments on commit d508b28

Please sign in to comment.