Skip to content

Commit

Permalink
Add the script for iOS build on macOS (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
maroontress-tomohisa authored Aug 22, 2023
1 parent cca1eb1 commit a889b37
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: iOS

on:
push:
branches: [main]
pull_request:
branches: [main]

env:
BUILD_TYPE: Release

jobs:
build:
runs-on: macos-latest
timeout-minutes: 30

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

- name: Build
run: |
sh build-ios.sh "$HOME/ios"
- name: Archive artifacts
uses: actions/upload-artifact@v3
with:
name: ios
path: ~/ios/
133 changes: 133 additions & 0 deletions build-ios.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/bin/sh

if [ "$#" = "0" ] ; then
echo usage: $0 INSTALL_DIR
exit 1
fi

dest_dir="$1"
root_build_dir="build-ios"
rm -rf $root_build_dir || exit 1

# Usage:
# build SDK ABI
#
# SDK:
# "iphoneos"
# "iphonesimulator"
#
# ABI:
# "arm64"
# "x86_64"
#
# Note that the combination of iphoneos and x86_64 makes no sense so far.
build() {
sdk="$1"
abi="$2"
build_dir="$root_build_dir/$sdk-$abi"

case "$sdk" in
iphoneos)
destination="generic/platform=iOS"
;;
iphonesimulator)
destination="generic/platform=iOS Simulator"
;;
*)
echo unknown SDK: $sdk
exit 1
esac
# Note that although it is possible to specify
# -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
# and create the fat file at once, we will not do so here because we will
# 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="$abi" \
-DCMAKE_OSX_DEPLOYMENT_TARGET=13.0 \
-DCMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=NO \
-DCMAKE_IOS_INSTALL_COMBINED=NO \
-DCMAKE_POSITION_INDEPENDENT_CODE="ON" \
-DCMAKE_INSTALL_PREFIX:PATH="$PWD/$build_dir/exports" \
-DBUILD_TESTSUITE=OFF \
|| exit 1
# Note that the following command does not work:
# cmake --install $build_dir
cmake --build $build_dir --target install --config Release -v \
-- -sdk $sdk -destination "$destination" || exit 1
}

# Usage:
# install_lib LIBRARY
#
# LIBRARY must be either a ".a" or ".dylib" file.
install_lib() {
lib="$1"
install $root_build_dir/iphoneos-arm64/exports/lib/$lib \
$dest_dir/iphoneos/lib/ || exit 1
rm -f $dest_dir/iphonesimulator/lib/$lib
lipo -create \
$root_build_dir/iphonesimulator-arm64/exports/lib/$lib \
$root_build_dir/iphonesimulator-x86_64/exports/lib/$lib \
-output $dest_dir/iphonesimulator/lib/$lib || exit 1
}

# Usage:
# install_include SDK ABI
install_include() {
sdk="$1"
abi="$2"
from="$root_build_dir/$sdk-$abi/exports/include"
to="$dest_dir/$sdk/include"
mkdir -p $to || exit 1
(cd $from && find . -type d -print0) \
| xargs -0 -I "{}" install -m 755 -d "${to}/{}" || exit 1
(cd $from && find . -type f -print0) \
| xargs -0 -I "{}" install -m 644 "$from/{}" "${to}/{}" || exit 1
}

combo_list="iphoneos-arm64 iphonesimulator-arm64 iphonesimulator-x86_64"

for combo in $combo_list ; do
sdk=${combo%-*}
abi=${combo#*-}
build $sdk $abi || exit 1
done

for combo in $combo_list ; do
sdk=${combo%-*}
abi=${combo#*-}
build_dir="$root_build_dir/$sdk-$abi"
lipo -info $build_dir/exports/lib/libmimicssl-aes128-cbc-decrypt.a || exit 1
done

mkdir -p $dest_dir \
$dest_dir/iphoneos/include \
$dest_dir/iphoneos/lib \
$dest_dir/iphonesimulator/include \
$dest_dir/iphonesimulator/lib \
$dest_dir/xcframeworks || exit 1

staticlib=libmimicssl-aes128-cbc-decrypt.a
sharedlib=libmimicssl-aes128-cbc-decrypt.dylib
for lib in $staticlib $sharedlib ; do
install_lib $lib || exit 1
done

sdk_list="iphoneos iphonesimulator"
for sdk in $sdk_list ; do
# Here, we consider header files of the "iphonesimulator" identical
# regardless of the architecture.
install_include $sdk arm64 || exit 1
done

xcframework=mimicssl-aes128-cbc-decrypt.xcframework
rm -rf $dest_dir/xcframeworks/$xcframework
xcodebuild -create-xcframework \
-library $dest_dir/iphoneos/lib/$staticlib \
-headers $dest_dir/iphoneos/include \
-library $dest_dir/iphonesimulator/lib/$staticlib \
-headers $dest_dir/iphonesimulator/include \
-output $dest_dir/xcframeworks/$xcframework || exit 1
10 changes: 10 additions & 0 deletions evp-example-cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ set(CMAKE_CXX_STANDARD 23)

add_executable(evp-example-cli main.cxx)

if("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
set_target_properties(evp-example-cli PROPERTIES
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
XCODE_ATTRIBUTE_ENABLE_BITCODE "NO"
MACOSX_BUNDLE_BUNDLE_NAME evp-example-cli
MACOSX_BUNDLE_BUNDLE_VERSION 1.0
MACOSX_BUNDLE_SHORT_VERSION_STRING 1.0
MACOSX_BUNDLE_LONG_VERSION_STRING 1.0)
endif()

target_include_directories(evp-example-cli PRIVATE
mimicssl-aes128-cbc-decrypt)

Expand Down
14 changes: 14 additions & 0 deletions libmimicssl-aes128-cbc-decrypt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
else()
set(SOURCES src/evp.c src/Aes128Cbc.c)
endif()
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
if("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "arm64")
set(SOURCES src/evp.c src/aarch64_Aes128Cbc.c)
elseif("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "x86_64")
set(OPTIONS -msse3 -maes)
set(SOURCES src/evp.c src/x86_64_Aes128Cbc.c)
endif()
set_target_properties(mimicssl-aes128-cbc-decrypt-shared PROPERTIES
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
XCODE_ATTRIBUTE_ENABLE_BITCODE "NO"
MACOSX_BUNDLE_BUNDLE_NAME mimicssl-aes128-cbc-decrypt
MACOSX_BUNDLE_BUNDLE_VERSION 1.0
MACOSX_BUNDLE_SHORT_VERSION_STRING 1.0
MACOSX_BUNDLE_LONG_VERSION_STRING 1.0)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin"
AND "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64")
set(SOURCES src/evp.c src/aarch64_Aes128Cbc.c)
Expand Down
14 changes: 14 additions & 0 deletions testsuite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
else()
set(SOURCES main.cxx)
endif()
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
if("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "arm64")
set(SOURCES aarch64_main.cxx)
elseif("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "x86_64")
set(OPTIONS -msse3 -maes)
set(SOURCES x86_64_main.cxx)
endif()
set_target_properties(testsuite PROPERTIES
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
XCODE_ATTRIBUTE_ENABLE_BITCODE "NO"
MACOSX_BUNDLE_BUNDLE_NAME mimicssl-aes128-cbc-decrypt-testsuite
MACOSX_BUNDLE_BUNDLE_VERSION 1.0
MACOSX_BUNDLE_SHORT_VERSION_STRING 1.0
MACOSX_BUNDLE_LONG_VERSION_STRING 1.0)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin"
AND "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64")
set(SOURCES aarch64_main.cxx)
Expand Down

0 comments on commit a889b37

Please sign in to comment.