Skip to content

Commit

Permalink
Refactor build scripts and workflow files (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
maroontress-tomohisa authored Sep 3, 2023
1 parent 446e09b commit a53d4f0
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 60 deletions.
24 changes: 9 additions & 15 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@ jobs:
- name: Set up on Windows
if: runner.os == 'Windows'
shell: bash
run: |
echo NINJA_ZIP="ninja-win.zip" >> "$GITHUB_ENV"
echo ANDROID_NDK="$(cygpath -u $ANDROID_NDK)" >> "$GITHUB_ENV"
- name: Set up on Linux
if: runner.os == 'Linux'
run: echo NINJA_ZIP="ninja-linux.zip" >> "$GITHUB_ENV"
- name: Set up on macOS
if: runner.os == 'macOS'
run: echo NINJA_ZIP="ninja-mac.zip" >> "$GITHUB_ENV"
run: echo ANDROID_NDK="$(cygpath -u $ANDROID_NDK)" >> "$GITHUB_ENV"
- name: Install ninja
shell: bash
run: |
map_Windows="win" ; map_Linux="linux" ; map_macOS="mac"
suffix="$(eval echo '$'map_$RUNNER_OS)"
mkdir -p "$HOME/bin"
curl -L -o ninja.zip "https://github.com/ninja-build/ninja/releases/download/v1.11.1/$NINJA_ZIP"
curl -L -o ninja.zip \
"https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-$suffix.zip"
unzip ninja.zip -d "$HOME/bin"
- uses: actions/checkout@v3
Expand All @@ -46,10 +41,11 @@ jobs:
run: |
sh android.sh build configure ${{matrix.abi}} \
-G Ninja -DCMAKE_MAKE_PROGRAM="$HOME/bin/ninja" \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_INSTALL_PREFIX:PATH="$HOME/android/${{matrix.abi}}"
- name: Build ${{matrix.abi}}
shell: bash
run: cmake --build build/${{matrix.abi}} --config Release -v
run: cmake --build build/${{matrix.abi}} -v
- name: Install ${{matrix.abi}}
shell: bash
run: cmake --install build/${{matrix.abi}}
Expand All @@ -72,11 +68,9 @@ jobs:
with:
submodules: true
- name: Configure ${{matrix.abi}}
run: |
sh android.sh build configure ${{matrix.abi}}
run: sh android.sh build configure ${{matrix.abi}} -DCMAKE_BUILD_TYPE=$BUILD_TYPE
- name: Build ${{matrix.abi}}
run: |
cmake --build build/${{matrix.abi}} --config Release -v
run: cmake --build build/${{matrix.abi}} -v
- name: AVD cache
uses: actions/cache@v3
id: avd-cache
Expand Down
35 changes: 30 additions & 5 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,50 @@ env:
BUILD_TYPE: Release

jobs:
build:
single_config:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest, macos-latest]
runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v3
with:
submodules: true

lfs: true
- name: Configure CMake
shell: bash
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=$BUILD_TYPE
- name: Build
shell: bash
run: cmake --build build
- name: Test
shell: bash
run: ctest --test-dir build -V
- name: Install
shell: bash
run: cmake --install build --prefix=$HOME/mimicssl

multi_config:
strategy:
matrix:
os: [windows-latest]
runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v3
with:
submodules: true
lfs: true
- name: Configure CMake
shell: bash
run: cmake -S . -B build
- name: Build
shell: bash
run: cmake --build build --config $BUILD_TYPE

- name: Test
shell: bash
run: ctest --test-dir build -C $BUILD_TYPE -V
run: ctest --test-dir build -V -C $BUILD_TYPE
- name: Install
shell: bash
run: cmake --install build --config $BUILD_TYPE --prefix=$HOME/mimicssl
15 changes: 6 additions & 9 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ jobs:
submodules: true
lfs: true
- name: Build ${{matrix.abi}}
run: |
sh ios.sh build build-non-fat ${{matrix.sdk}} ${{matrix.abi}}
run: sh ios.sh build build-non-fat ${{matrix.sdk}} ${{matrix.abi}} $BUILD_TYPE
- name: Archive artifacts
uses: actions/upload-artifact@v3
with:
Expand All @@ -56,17 +55,15 @@ jobs:
udid=$(xcrun simctl list devices iPhone available -j | jq '.devices['$runtime']|.[].udid' | tail -1)
xcrun simctl bootstatus $(eval echo $udid) -b
- name: Test
run: |
ctest --test-dir build/iphonesimulator-x86_64 -C Release
run: ctest --test-dir build/iphonesimulator-x86_64 -C $BUILD_TYPE
- name: Archive artifacts (testsuite)
if: ${{failure()}}
uses: actions/upload-artifact@v3
with:
name: testsuite
path: ${{github.workspace}}/build/iphonesimulator-x86_64/
- name: Install fat files and XCFrameworks
run: |
sh ios.sh build install "$HOME/ios"
run: sh ios.sh build install "$HOME/ios" --config $BUILD_TYPE
- name: Archive artifacts (xcframework)
uses: actions/upload-artifact@v3
with:
Expand All @@ -85,9 +82,9 @@ jobs:
- name: Configure
run: sh ios.sh build configure
- name: Build
run: sh ios.sh build build
run: sh ios.sh build build --config $BUILD_TYPE
- name: Install
run: sh ios.sh build install $HOME/ios
run: sh ios.sh build install $HOME/ios --config $BUILD_TYPE
- name: Archive artifacts
uses: actions/upload-artifact@v3
with:
Expand All @@ -100,4 +97,4 @@ jobs:
xcrun simctl bootstatus $(eval echo $udid) -b
- name: Test
run: |
ctest --test-dir build/iphonesimulator-x86_64 -C Release
ctest --test-dir build/iphonesimulator-x86_64 -C $BUILD_TYPE
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,29 @@ MD5_Final(md, &ctx);
## Build
This repository uses [lighter][maroontress::lighter] for testing as a sub-module
of Git. Therefore, clone it as follows:
This repository uses [lighter][maroontress::lighter] for testing as a submodule
of Git. So clone it as follows:
```plaintext
git clone --recursive URL
```

Then build the library as follows:
Then build the library on macOS or Linux as follows:

```textplain
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
ctest --test-dir build
cmake --install build --prefix=/path/to/dir
```

Or on Windows as follows:

```textplain
cmake -S . -B build
cmake --build build --config Release
ctest --test-dir build -C Release
cmake --install build --config Release --prefix=/path/to/dir
```

## Build for Android
Expand All @@ -62,15 +72,16 @@ but a typical configuration would be as follows:
- Linux: `/home/USERNAME/Android/Sdk`
- macOS: `/Users/USERNAME/Library/Android/sdk`

Then build as follows:
Then build the library as follows:

```sh
abi=ABI
build_dir=BUILD_DIR
sh android.sh $build_dir configure $abi -G Ninja \
-DCMAKE_MAKE_PROGRAM="/path/to/ninja" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX:PATH="/path/to/dir"
cmake --build $build_dir/$abi --config Release -v
cmake --build $build_dir/$abi -v
cmake --install $build_dir/$abi
```

Expand Down Expand Up @@ -99,21 +110,21 @@ sh android.sh $build_dir test $abi

## Build for iOS

Build on macOS as follows:
Build the library on macOS as follows:

```sh
build_dir=BUILD_DIR
sh ios.sh $build_dir configure
sh ios.sh $build_dir build
sh ios.sh $build_dir install /path/to/dir
sh ios.sh $build_dir build --config Release
sh ios.sh $build_dir install /path/to/dir --config Release
```

`BUILD_DIR` should be replaced by the build directory (e.g., `build-ios`).

You can run `testsuite` with the iPhone simulator as follows:

```sh
sh ios.sh $build_dir test ARCH
sh ios.sh $build_dir test ARCH -C Release
```

`ARCH` should be replaced by `arm64` or `x86_64`. Note that `jq` is required to
Expand Down
11 changes: 7 additions & 4 deletions android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

if [ "$#" = 0 ] ; then
echo usage: $0 BUILD_DIR configure ABI [CMAKE_OPTIONS...]
echo usage: $0 BUILD_DIR test ABI
echo usage: $0 BUILD_DIR test ABI [CTEST_OPTIONS...]
exit 1
fi
root_build_dir="$1"
Expand All @@ -18,9 +18,12 @@ shift
# "arm64-v8a"
# "armeabi-v7a"

# Options:
# CMAKE_OPTIONS:
# -DCMAKE_BUILD_TYPE=Release
# -DCMAKE_INSTALL_PREFIX:PATH="$HOME/android/$ABI"

# CTEST_OPTIONS:

check_abi() {
abi=$1
case "$abi" in
Expand Down Expand Up @@ -53,7 +56,7 @@ configure)
if [ "$abi" = "armeabi-v7a" ] ; then
EXTRA_ARGS='-DCMAKE_ANDROID_ARM_NEON=ON'
fi
cmake -S . -B "$build_dir" -DCMAKE_BUILD_TYPE=Release \
cmake -S . -B "$build_dir" \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_CROSSCOMPILING_EMULATOR="$PWD/emulator-android.sh" \
-DCMAKE_SYSTEM_VERSION="21" \
Expand All @@ -71,7 +74,7 @@ test)
check_abi $abi
build_dir="$root_build_dir/$abi"
sh emulator-android.sh --adb-push "$build_dir/testsuite"
ctest --test-dir "$build_dir" -C Release -V || exit 1
ctest --test-dir "$build_dir" -V "$@" || exit 1
sh emulator-android.sh --adb-pull "$build_dir/testsuite"
;;
*)
Expand Down
Loading

0 comments on commit a53d4f0

Please sign in to comment.