From a53d4f06c5377383fb9a7c85fb2ff7b603852d1d Mon Sep 17 00:00:00 2001 From: "Tomohisa Tanaka (Maroontress)" Date: Mon, 4 Sep 2023 04:04:37 +0900 Subject: [PATCH] Refactor build scripts and workflow files (#7) --- .github/workflows/android.yml | 24 +++++++---------- .github/workflows/cmake.yml | 35 ++++++++++++++++++++---- .github/workflows/ios.yml | 15 +++++------ README.md | 29 +++++++++++++------- android.sh | 11 +++++--- ios.sh | 51 ++++++++++++++++++++++------------- 6 files changed, 105 insertions(+), 60 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index d477a42..adfc851 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -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 @@ -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}} @@ -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 diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 5b47093..5c254cf 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -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 diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index 8d794fb..bb917da 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -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: @@ -56,8 +55,7 @@ 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 @@ -65,8 +63,7 @@ jobs: 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: @@ -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: @@ -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 diff --git a/README.md b/README.md index d23fe01..06ba5e7 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ``` @@ -99,13 +110,13 @@ 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`). @@ -113,7 +124,7 @@ sh ios.sh $build_dir install /path/to/dir 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 diff --git a/android.sh b/android.sh index 1f54302..df88240 100644 --- a/android.sh +++ b/android.sh @@ -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" @@ -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 @@ -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" \ @@ -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" ;; *) diff --git a/ios.sh b/ios.sh index efc26bf..d993fe6 100644 --- a/ios.sh +++ b/ios.sh @@ -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" @@ -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 \ @@ -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: @@ -70,7 +70,7 @@ print_destination() { } # Usage: -# build SDK ARCH +# build SDK ARCH [CMAKE_OPTIONS...] # # SDK: # "iphoneos" @@ -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 } @@ -122,7 +123,7 @@ install_include() { } # Usage: -# cmake_install SDK ARCH +# cmake_install SDK ARCH [CMAKE_OPTIONS...] # # SDK: # "iphoneos" @@ -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 } @@ -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 @@ -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 @@ -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 \ @@ -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