Skip to content

Commit

Permalink
Refactor build scripts and workflow files
Browse files Browse the repository at this point in the history
  • Loading branch information
maroontress-tomohisa committed Sep 3, 2023
1 parent 446e09b commit e96d376
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 55 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
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,22 @@ of Git. Therefore, clone it as follows:
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
```

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 @@ -69,8 +79,9 @@ 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 @@ -104,8 +115,8 @@ Build 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`).
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
51 changes: 33 additions & 18 deletions ios.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/bin/sh

if [ "$#" = "0" ] ; then
echo usage: $0 BUILD_DIR configure
echo usage: $0 BUILD_DIR build
echo usage: $0 BUILD_DIR install INSTALL_DIR
echo usage: $0 BUILD_DIR test ARCH
echo usage: $0 BUILD_DIR build-non-fat SDK ARCH
echo usage: $0 BUILD_DIR configure [CMAKE_OPTIONS...]
echo usage: $0 BUILD_DIR build [CMAKE_OPTIONS...]
echo usage: $0 BUILD_DIR install INSTALL_DIR [CMAKE_OPTIONS...]
echo usage: $0 BUILD_DIR test ARCH [CTEST_OPTOINS...]
echo usage: $0 BUILD_DIR build-non-fat SDK ARCH BUILD_TYPE [CMAKE_OPTIONS...]
exit 1
fi
root_build_dir="$1"
shift

# Usage:
# configure SDK ARCH [CMAKE_OPTIONS]
# configure SDK ARCH [CMAKE_OPTIONS...]
#
# SDK:
# "iphoneos"
Expand All @@ -37,7 +37,6 @@ configure() {
# compile with different configurations for each architecture. Instead, we
# will use lipo to create the fat file with non-fat files later.
cmake -S . -B "$build_dir" -G Xcode \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_SYSTEM_NAME="iOS" \
-DCMAKE_OSX_ARCHITECTURES="$arch" \
-DCMAKE_OSX_DEPLOYMENT_TARGET=13.0 \
Expand All @@ -48,7 +47,8 @@ configure() {
"$@" || exit 1
# WORKAROUND for EFFECTIVE_PLATFORM_NAME
sed -i .bak -e 's/\${EFFECTIVE_PLATFORM_NAME}/-'$sdk'/' \
"$root_build_dir/$sdk-$arch/testsuite/testsuite[1]_include-Release.cmake"
"$root_build_dir/$sdk-$arch/testsuite/testsuite[1]_include-Release.cmake" \
"$root_build_dir/$sdk-$arch/testsuite/testsuite[1]_include-Debug.cmake"
}

# Usage:
Expand All @@ -70,7 +70,7 @@ print_destination() {
}

# Usage:
# build SDK ARCH
# build SDK ARCH [CMAKE_OPTIONS...]
#
# SDK:
# "iphoneos"
Expand All @@ -84,11 +84,12 @@ print_destination() {
build() {
sdk="$1"
arch="$2"
shift 2
build_dir="$root_build_dir/$sdk-$arch"
destination="$(print_destination $sdk)"
# Note that the following command does not work:
# cmake --install $build_dir
cmake --build $build_dir --config Release -v \
cmake --build $build_dir -v "$@" \
-- -sdk $sdk -destination "$destination" || exit 1
}

Expand Down Expand Up @@ -122,7 +123,7 @@ install_include() {
}

# Usage:
# cmake_install SDK ARCH
# cmake_install SDK ARCH [CMAKE_OPTIONS...]
#
# SDK:
# "iphoneos"
Expand All @@ -136,11 +137,12 @@ install_include() {
cmake_install() {
sdk="$1"
arch="$2"
shift 2
build_dir="$root_build_dir/$sdk-$arch"
destination="$(print_destination $sdk)"
# Note that the following command does not work:
# cmake --install $build_dir
cmake --build $build_dir --target install --config Release -v \
cmake --build $build_dir --target install -v "$@" \
-- -sdk $sdk -destination "$destination" || exit 1
}

Expand All @@ -166,6 +168,17 @@ check_arch() {
esac
}

check_build_type() {
type="$1"
case "$type" in
Release|Debug)
;;
*)
echo unknown BUILD_TYPE: $arch
exit 1
esac
}

if [ "$#" = "0" ] ; then
echo COMMAND not specified
exit 1
Expand All @@ -178,18 +191,20 @@ all="iphoneos-arm64 iphonesimulator-arm64 iphonesimulator-x86_64"

case "$command" in
build-non-fat)
if [ "$#" -lt 2 ] ; then
echo SDK and ARCH not specified
if [ "$#" -lt 3 ] ; then
echo SDK, ARCH, and BUILD_TYPE not specified
exit 1
fi
sdk="$1"
arch="$2"
shift 2
build_type="$3"
shift 3
check_sdk $sdk
check_arch $arch
check_build_type $build_type
rm -rf $root_build_dir || exit 1
configure $sdk $arch "$@" || exit 1
build $sdk $arch || exit 1
build $sdk $arch --config "$build_type" || exit 1
;;
configure)
rm -rf $root_build_dir || exit 1
Expand All @@ -216,7 +231,7 @@ install)
for i in $all ; do
sdk=${i%-*}
arch=${i#*-}
cmake_install $sdk $arch || exit 1
cmake_install $sdk $arch "$@" || exit 1
done
mkdir -p $dest_dir \
$dest_dir/iphoneos/include \
Expand Down Expand Up @@ -256,7 +271,7 @@ test)
udid=$(xcrun simctl list devices iPhone available -j \
| jq '.devices['$runtime']|.[].udid' | tail -1)
xcrun simctl bootstatus $(eval echo $udid) -b
ctest --test-dir "$root_build_dir/iphonesimulator-$arch" -C Release
ctest --test-dir "$root_build_dir/iphonesimulator-$arch" "$@"
;;
*)
echo unknown command: $command
Expand Down

0 comments on commit e96d376

Please sign in to comment.