Skip to content

Commit

Permalink
Add the script for iOS build on macOS (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
maroontress-tomohisa authored Aug 20, 2023
1 parent f003b62 commit 36c3a36
Show file tree
Hide file tree
Showing 5 changed files with 191 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-md5.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-md5.a
sharedlib=libmimicssl-md5.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-md5.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
9 changes: 9 additions & 0 deletions libmimicssl-md5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ target_include_directories(mimicssl-md5 PUBLIC
${PROJECT_BINARY_DIR})

add_library(mimicssl-md5-shared SHARED)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
set_target_properties(mimicssl-md5-shared PROPERTIES
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
XCODE_ATTRIBUTE_ENABLE_BITCODE "NO"
MACOSX_BUNDLE_BUNDLE_NAME mimicssl-md5
MACOSX_BUNDLE_BUNDLE_VERSION 1.0
MACOSX_BUNDLE_SHORT_VERSION_STRING 1.0
MACOSX_BUNDLE_LONG_VERSION_STRING 1.0)
endif()
target_sources(mimicssl-md5-shared PRIVATE
src/md5.c)
target_include_directories(mimicssl-md5-shared PUBLIC
Expand Down
10 changes: 10 additions & 0 deletions mimicssl-md5-cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ set(CMAKE_C_STANDARD 23)

add_executable(mimicssl-md5-cli main.c)

if("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
set_target_properties(mimicssl-md5-cli PROPERTIES
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
XCODE_ATTRIBUTE_ENABLE_BITCODE "NO"
MACOSX_BUNDLE_BUNDLE_NAME mimicssl-md5-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(mimicssl-md5-cli PRIVATE mimicssl-md5)

target_link_libraries(mimicssl-md5-cli mimicssl-md5)
10 changes: 10 additions & 0 deletions testsuite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ enable_testing()
add_executable(testsuite
main.cxx expect.hxx expect_fallback.hxx)

if("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
set_target_properties(testsuite PROPERTIES
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
XCODE_ATTRIBUTE_ENABLE_BITCODE "NO"
MACOSX_BUNDLE_BUNDLE_NAME mimicssl-md5-testsuite
MACOSX_BUNDLE_BUNDLE_VERSION 1.0
MACOSX_BUNDLE_SHORT_VERSION_STRING 1.0
MACOSX_BUNDLE_LONG_VERSION_STRING 1.0)
endif()

target_include_directories(testsuite PRIVATE
mimicssl-md5 ${CMAKE_SOURCE_DIR}/lighter/include)

Expand Down

0 comments on commit 36c3a36

Please sign in to comment.