M1 support (#1620)

* Support Arm64 simulator targets (M1)

* Combine dylibs to xcframework

* Update Python-Apple-support urls

* Update Readme
This commit is contained in:
Sergey 2021-09-03 09:25:14 +03:00 committed by GitHub
parent 7dffe5aabe
commit ab4736df28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 161 additions and 37 deletions

View File

@ -195,15 +195,15 @@ set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS su
if (IOS_PLATFORM STREQUAL "OS")
set (IOS_ARCH "armv7;armv7s;arm64")
elseif (IOS_PLATFORM STREQUAL "SIMULATOR")
set (IOS_ARCH "i386;x86_64")
set (IOS_ARCH "i386;x86_64;arm64")
elseif (IOS_PLATFORM STREQUAL "WATCHOS")
set (IOS_ARCH "armv7k;arm64_32")
elseif (IOS_PLATFORM STREQUAL "WATCHSIMULATOR")
set (IOS_ARCH "i386;x86_64")
set (IOS_ARCH "i386;x86_64;arm64")
elseif (IOS_PLATFORM STREQUAL "TVOS")
set (IOS_ARCH "arm64")
elseif (IOS_PLATFORM STREQUAL "TVSIMULATOR")
set (IOS_ARCH "x86_64")
set (IOS_ARCH "x86_64;arm64")
else()
message (WARNING "Unknown IOS_PLATFORM=<${IOS_PLATFORM}>")
endif()

View File

@ -1,16 +1,86 @@
diff --git a/Makefile b/Makefile
index 695be54..bce31b9 100644
index 695be54..4efe5e5 100644
--- a/Makefile
+++ b/Makefile
@@ -56,9 +56,10 @@ CFLAGS-appletvos.arm64=-fembed-bitcode
@@ -5,10 +5,13 @@
# - iOS - build everything for iOS
# - tvOS - build everything for tvOS
# - watchOS - build everything for watchOS
-# - OpenSSL-macOS - build OpenSSL for macOS
-# - OpenSSL-iOS - build OpenSSL for iOS
-# - OpenSSL-tvOS - build OpenSSL for tvOS
-# - OpenSSL-watchOS - build OpenSSL for watchOS
+# - OpenSSL-macOS - build OpenSSL for macOS
+# - OpenSSL-iOS - build OpenSSL for iOS
+# - OpenSSL-iOS-simulator - build OpenSSL for iOS-simulator
+# - OpenSSL-tvOS - build OpenSSL for tvOS
+# - OpenSSL-tvOS-simulator - build OpenSSL for tvOS-simulator
+# - OpenSSL-watchOS - build OpenSSL for watchOS
+# - OpenSSL-watchOS-simulator - build OpenSSL for watchOS-simulator
# - BZip2-macOS - build BZip2 for macOS
# - BZip2-iOS - build BZip2 for iOS
# - BZip2-tvOS - build BZip2 for tvOS
@@ -36,31 +39,45 @@ OPENSSL_VERSION=$(OPENSSL_VERSION_NUMBER)$(OPENSSL_REVISION)
BZIP2_VERSION=1.0.6
# Supported OS
-OS=macOS iOS tvOS watchOS
+OS=macOS iOS iOS-simulator tvOS tvOS-simulator watchOS watchOS-simulator
# macOS targets
-TARGETS-macOS=macosx.x86_64
+TARGETS-macOS=macosx.arm64 macosx.x86_64
+PYTHON_TARGETS-macOS=macOS
CFLAGS-macOS=-mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET)
# iOS targets
-TARGETS-iOS=iphonesimulator.x86_64 iphonesimulator.i386 iphoneos.armv7 iphoneos.armv7s iphoneos.arm64
+TARGETS-iOS=iphoneos.armv7 iphoneos.armv7s iphoneos.arm64
CFLAGS-iOS=-mios-version-min=7.0
CFLAGS-iphoneos.armv7=-fembed-bitcode
CFLAGS-iphoneos.armv7s=-fembed-bitcode
CFLAGS-iphoneos.arm64=-fembed-bitcode
+# iOS-simulator targets
+TARGETS-iOS-simulator=iphonesimulator.x86_64 iphonesimulator.i386 iphonesimulator.arm64
+CFLAGS-iOS-simulator=-mios-simulator-version-min=7.0
+
# tvOS targets
-TARGETS-tvOS=appletvsimulator.x86_64 appletvos.arm64
+TARGETS-tvOS=appletvos.arm64
CFLAGS-tvOS=-mtvos-version-min=9.0
CFLAGS-appletvos.arm64=-fembed-bitcode
PYTHON_CONFIGURE-tvOS=ac_cv_func_sigaltstack=no
+# tvOS-simulator targets
+TARGETS-tvOS-simulator=appletvsimulator.x86_64 appletvsimulator.arm64
+CFLAGS-tvOS-simulator=-mtvos-simulator-version-min=9.0
+
# watchOS targets
-TARGETS-watchOS=watchsimulator.i386 watchos.armv7k
+TARGETS-watchOS=watchsimulator.i386 watchsimulator.x86_64 watchos.armv7k watchos.arm64_32
+TARGETS-watchOS=watchos.armv7k watchos.arm64_32
CFLAGS-watchOS=-mwatchos-version-min=4.0
CFLAGS-watchos.armv7k=-fembed-bitcode
+CFLAGS-watchos.arm64_32=-fembed-bitcode
PYTHON_CONFIGURE-watchOS=ac_cv_func_sigaltstack=no
+# watchOS-simulator targets
+TARGETS-watchOS-simulator=watchsimulator.i386 watchsimulator.x86_64 watchsimulator.arm64
+CFLAGS-watchOS-simulator=-mwatchos-simulator-version-min=4.0
+
# override machine types for arm64
MACHINE_DETAILED-arm64=aarch64
MACHINE_SIMPLE-arm64=arm
@@ -194,9 +211,11 @@ endif
# Configure the build
ifeq ($2,macOS)
+ # Patch openssl-darwin-arm64
+ cd $$(OPENSSL_DIR-$1) && git apply ../../../../openssl-1.0.2n-darwin-arm64.patch
cd $$(OPENSSL_DIR-$1) && \
CC="$$(CC-$1)" MACOSX_DEPLOYMENT_TARGET=$$(MACOSX_DEPLOYMENT_TARGET) \
- ./Configure darwin64-x86_64-cc --openssldir=$(PROJECT_DIR)/build/$2/openssl
+ ./Configure darwin64-$$(ARCH-$1)-cc --openssldir=$(PROJECT_DIR)/build/$2/openssl
else
cd $$(OPENSSL_DIR-$1) && \
CC="$$(CC-$1)" \

View File

@ -26,8 +26,8 @@ cmake --build . --target prepare_cross_compiling
cd <path to TDLib sources>/example/ios
./build-openssl.sh
```
Here we use scripts from [Python Apple support](https://github.com/pybee/Python-Apple-support), but any other OpenSSL builds should work too.
[Python Apple support](https://github.com/pybee/Python-Apple-support) has known problems with spaces in the path to the current directory, so
Here we use scripts from [Python Apple support](https://github.com/beeware/Python-Apple-support), but any other OpenSSL builds should work too.
[Python Apple support](https://github.com/beeware/Python-Apple-support) has known problems with spaces in the path to the current directory, so
you need to ensure that there is no spaces in the path.
Built libraries should be stored in `third_party/openssl/<platform>`, because the next script will rely on this location.
* Build TDLib for iOS, watchOS, tvOS and macOS:
@ -36,7 +36,7 @@ cd <path to TDLib sources>/example/ios
./build.sh
```
This may take a while, because TDLib will be built about 10 times.
Resulting library for iOS will work on any architecture (armv7, armv7s, arm64) and even on a simulator.
Resulting library for iOS will work on any architecture (armv7, armv7s, arm64) and even on a simulator (Intel, Apple Silicon).
We use [CMake/iOS.cmake](https://github.com/tdlib/td/blob/master/CMake/iOS.cmake) toolchain, other toolchains may work too.
Built libraries will be stored in `tdjson` directory.

View File

@ -1,6 +1,6 @@
#!/bin/sh
git clone https://github.com/pybee/Python-Apple-support
git clone https://github.com/beeware/Python-Apple-support
cd Python-Apple-support
git checkout 60b990128d5f1f04c336ff66594574515ab56604
git apply ../Python-Apple-support.patch
@ -8,17 +8,29 @@ cd ..
#TODO: change openssl version
platforms="macOS iOS watchOS tvOS"
#platforms="watchOS"
for platform in $platforms;
do
echo $platform
cd Python-Apple-support
#NB: -j will fail
make OpenSSL-$platform
cd ..
rm -rf third_party/openssl/$platform
mkdir -p third_party/openssl/$platform/lib
cp ./Python-Apple-support/build/$platform/libcrypto.a third_party/openssl/$platform/lib/
cp ./Python-Apple-support/build/$platform/libssl.a third_party/openssl/$platform/lib/
cp -r ./Python-Apple-support/build/$platform/Support/OpenSSL/Headers/ third_party/openssl/$platform/include
if [[ $platform = "macOS" ]]; then
simulators="0"
else
simulators="0 1"
fi
for simulator in $simulators;
do
if [[ $simulator = "1" ]]; then
platform="${platform}-simulator"
fi
echo $platform
cd Python-Apple-support
#NB: -j will fail
make OpenSSL-$platform
cd ..
rm -rf third_party/openssl/$platform
mkdir -p third_party/openssl/$platform/lib
cp ./Python-Apple-support/build/$platform/libcrypto.a third_party/openssl/$platform/lib/
cp ./Python-Apple-support/build/$platform/libssl.a third_party/openssl/$platform/lib/
cp -r ./Python-Apple-support/build/$platform/Support/OpenSSL/Headers/ third_party/openssl/$platform/include
done
done

View File

@ -5,34 +5,45 @@ rm -rf build
mkdir -p build
cd build
platforms="macOS iOS watchOS tvOS"
#platforms="watchOS"
for platform in $platforms;
do
echo "Platform = ${platform} Simulator = ${simulator}"
openssl_path=$(grealpath ../third_party/openssl/${platform})
set_cmake_options () {
# Set CMAKE options depending on platform passed $1
openssl_path=$(grealpath ../third_party/openssl/$1)
echo "OpenSSL path = ${openssl_path}"
openssl_crypto_library="${openssl_path}/lib/libcrypto.a"
openssl_ssl_library="${openssl_path}/lib/libssl.a"
options=""
options="$options -DOPENSSL_FOUND=1"
options="$options -DOPENSSL_CRYPTO_LIBRARY=${openssl_crypto_library}"
options="$options -DOPENSSL_SSL_LIBRARY=${openssl_ssl_library}"
options="$options -DOPENSSL_INCLUDE_DIR=${openssl_path}/include"
options="$options -DOPENSSL_LIBRARIES=${openssl_crypto_library};${openssl_ssl_library}"
options="$options -DCMAKE_BUILD_TYPE=Release"
}
platforms="macOS iOS watchOS tvOS"
#platforms="watchOS"
for platform in $platforms;
do
echo "Platform = ${platform}"
if [[ $platform = "macOS" ]]; then
set_cmake_options $platform
build="build-${platform}"
install="install-${platform}"
rm -rf $build
mkdir -p $build
mkdir -p $install
cd $build
cmake $td_path $options -DCMAKE_INSTALL_PREFIX=../${install}
cmake $td_path $options -DCMAKE_INSTALL_PREFIX=../${install} -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"
make -j3 install || exit
cd ..
mkdir -p $platform
cp $build/libtdjson.dylib $platform/libtdjson.dylib
install_name_tool -id @rpath/libtdjson.dylib $platform/libtdjson.dylib
mkdir -p ../tdjson/${platform}/include
rsync --recursive ${install}/include/ ../tdjson/${platform}/include/
mkdir -p ../tdjson/${platform}/lib
cp ${platform}/libtdjson.dylib ../tdjson/${platform}/lib/
else
simulators="0 1"
for simulator in $simulators;
@ -42,9 +53,15 @@ do
if [[ $simulator = "1" ]]; then
build="${build}-simulator"
install="${install}-simulator"
platform_path="${platform}-simulator"
ios_platform="SIMULATOR"
lib="${install}/lib/libtdjson.dylib"
set_cmake_options ${platform_path}
else
platform_path=${platform}
ios_platform="OS"
lib="${install}/lib/libtdjson.dylib"
set_cmake_options ${platform_path}
fi
watchos=""
if [[ $platform = "watchOS" ]]; then
@ -62,16 +79,29 @@ do
cmake $td_path $options $watchos -DIOS_PLATFORM=${ios_platform} -DCMAKE_TOOLCHAIN_FILE=${td_path}/CMake/iOS.cmake -DCMAKE_INSTALL_PREFIX=../${install}
make -j3 install || exit
cd ..
install_name_tool -id @rpath/libtdjson.dylib $lib
mkdir -p ../tdjson/${platform_path}/include
rsync --recursive ${install}/include/ ../tdjson/${platform_path}/include/
mkdir -p ../tdjson/${platform_path}/lib
cp ${lib} ../tdjson/${platform_path}/lib/
done
lib="install-${platform}/lib/libtdjson.dylib"
lib_simulator="install-${platform}-simulator/lib/libtdjson.dylib"
mkdir -p $platform
lipo -create $lib $lib_simulator -o $platform/libtdjson.dylib
install_name_tool -id @rpath/libtdjson.dylib $platform/libtdjson.dylib
fi
mkdir -p ../tdjson/$platform/include
rsync --recursive ${install}/include/ ../tdjson/${platform}/include/
mkdir -p ../tdjson/$platform/lib
cp $platform/libtdjson.dylib ../tdjson/$platform/lib/
done
produced_dylibs=(install-*/lib/libtdjson.dylib)
xcodebuild_frameworks=()
for dylib in "${produced_dylibs[@]}";
do
xcodebuild_frameworks+=(-library $(grealpath "${dylib}"))
done
# Make xcframework
xcodebuild -create-xcframework \
"${xcodebuild_frameworks[@]}" \
-output "libtdjson.xcframework"
rsync --recursive libtdjson.xcframework ../tdjson/

View File

@ -0,0 +1,12 @@
--- Configure 2019-12-20 14:02:41.000000000 +0100
+++ Configure 2020-11-22 16:23:13.000000000 +0100
@@ -650,7 +650,9 @@
"darwin-i386-cc","cc:-arch i386 -O3 -fomit-frame-pointer -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:".eval{my $asm=$x86_asm;$asm=~s/cast\-586\.o//;$asm}.":macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
"debug-darwin-i386-cc","cc:-arch i386 -g3 -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:${x86_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
"darwin64-x86_64-cc","cc:-arch x86_64 -O3 -DL_ENDIAN -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:".eval{my $asm=$x86_64_asm;$asm=~s/rc4\-[^:]+//;$asm}.":macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch x86_64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+"darwin64-arm64-cc","cc:-arch arm64 -O3 -DL_ENDIAN -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-arch arm64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
"debug-darwin64-x86_64-cc","cc:-arch x86_64 -ggdb -g2 -O0 -DL_ENDIAN -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:".eval{my $asm=$x86_64_asm;$asm=~s/rc4\-[^:]+//;$asm}.":macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch x86_64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+"debug-darwin64-arm64-cc","cc:-arch arm64 -ggdb -g2 -O0 -DL_ENDIAN -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-arch arm64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
"debug-darwin-ppc-cc","cc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DB_ENDIAN -g -Wall -O::-D_REENTRANT:MACOSX::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc32_asm}:osx32:dlfcn:darwin-shared:-fPIC:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
# iPhoneOS/iOS
"iphoneos-cross","llvm-gcc:-O3 -isysroot \$(CROSS_TOP)/SDKs/\$(CROSS_SDK) -fomit-frame-pointer -fno-common::-D_REENTRANT:macOS:-Wl,-search_paths_first%:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",