initial
This commit is contained in:
118
td/example/ios/Python-Apple-support.patch
Normal file
118
td/example/ios/Python-Apple-support.patch
Normal file
@@ -0,0 +1,118 @@
|
||||
diff --git a/Makefile b/Makefile
|
||||
index a1d13e9..8efcf20 100644
|
||||
--- a/Makefile
|
||||
+++ b/Makefile
|
||||
@@ -18,8 +18,13 @@
|
||||
# - OpenSSL - build OpenSSL for all platforms
|
||||
# - 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
|
||||
+# - OpenSSL-visionOS - build OpenSSL for visionOS
|
||||
+# - OpenSSL-visionOS-simulator - build OpenSSL for visionOS-simulator
|
||||
# - libFFI - build libFFI for all platforms (except macOS)
|
||||
# - libFFI-iOS - build libFFI for iOS
|
||||
# - libFFI-tvOS - build libFFI for tvOS
|
||||
@@ -50,7 +55,7 @@ XZ_VERSION=5.4.2
|
||||
# Preference is to use OpenSSL 3; however, Cryptography 3.4.8 (and
|
||||
# probably some other packages as well) only works with 1.1.1, so
|
||||
# we need to preserve the ability to build the older OpenSSL (for now...)
|
||||
-OPENSSL_VERSION=3.1.0
|
||||
+OPENSSL_VERSION=3.1.5
|
||||
# OPENSSL_VERSION_NUMBER=1.1.1
|
||||
# OPENSSL_REVISION=q
|
||||
# OPENSSL_VERSION=$(OPENSSL_VERSION_NUMBER)$(OPENSSL_REVISION)
|
||||
@@ -59,7 +64,7 @@ LIBFFI_VERSION=3.4.2
|
||||
|
||||
# Supported OS and dependencies
|
||||
DEPENDENCIES=BZip2 XZ OpenSSL libFFI
|
||||
-OS_LIST=macOS iOS tvOS watchOS
|
||||
+OS_LIST=macOS iOS iOS-simulator tvOS tvOS-simulator watchOS watchOS-simulator visionOS visionOS-simulator
|
||||
|
||||
CURL_FLAGS=--disable --fail --location --create-dirs --progress-bar
|
||||
|
||||
@@ -69,22 +74,41 @@ VERSION_MIN-macOS=10.15
|
||||
CFLAGS-macOS=-mmacosx-version-min=$(VERSION_MIN-macOS)
|
||||
|
||||
# iOS targets
|
||||
-TARGETS-iOS=iphonesimulator.x86_64 iphonesimulator.arm64 iphoneos.arm64
|
||||
+TARGETS-iOS=iphoneos.arm64
|
||||
VERSION_MIN-iOS=12.0
|
||||
CFLAGS-iOS=-mios-version-min=$(VERSION_MIN-iOS)
|
||||
|
||||
+# iOS-simulator targets
|
||||
+TARGETS-iOS-simulator=iphonesimulator.x86_64 iphonesimulator.arm64
|
||||
+CFLAGS-iOS-simulator=-mios-simulator-version-min=$(VERSION_MIN-iOS)
|
||||
+
|
||||
# tvOS targets
|
||||
-TARGETS-tvOS=appletvsimulator.x86_64 appletvsimulator.arm64 appletvos.arm64
|
||||
+TARGETS-tvOS=appletvos.arm64
|
||||
VERSION_MIN-tvOS=9.0
|
||||
CFLAGS-tvOS=-mtvos-version-min=$(VERSION_MIN-tvOS)
|
||||
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=$(VERSION_MIN-tvOS)
|
||||
+
|
||||
# watchOS targets
|
||||
-TARGETS-watchOS=watchsimulator.x86_64 watchsimulator.arm64 watchos.arm64_32
|
||||
+TARGETS-watchOS=watchos.armv7k watchos.arm64_32 watchos.arm64
|
||||
VERSION_MIN-watchOS=4.0
|
||||
CFLAGS-watchOS=-mwatchos-version-min=$(VERSION_MIN-watchOS)
|
||||
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=$(VERSION_MIN-watchOS)
|
||||
+
|
||||
+# visionOS targets
|
||||
+TARGETS-visionOS=xros.arm64
|
||||
+PYTHON_CONFIGURE-visionOS=ac_cv_func_sigaltstack=no
|
||||
+
|
||||
+# visionOS-simulator targets
|
||||
+TARGETS-visionOS-simulator=xrsimulator.x86_64 xrsimulator.arm64
|
||||
+
|
||||
# The architecture of the machine doing the build
|
||||
HOST_ARCH=$(shell uname -m)
|
||||
HOST_PYTHON=install/macOS/macosx/python-$(PYTHON_VERSION)
|
||||
@@ -212,6 +236,10 @@ ARCH-$(target)=$$(subst .,,$$(suffix $(target)))
|
||||
|
||||
ifeq ($(os),macOS)
|
||||
TARGET_TRIPLE-$(target)=$$(ARCH-$(target))-apple-darwin
|
||||
+else ifeq ($(os),visionOS)
|
||||
+TARGET_TRIPLE-$(target)=$$(ARCH-$(target))-apple-xros
|
||||
+else ifeq ($(os),visionOS-simulator)
|
||||
+TARGET_TRIPLE-$(target)=$$(ARCH-$(target))-apple-xros-simulator
|
||||
else
|
||||
ifeq ($$(findstring simulator,$$(SDK-$(target))),)
|
||||
TARGET_TRIPLE-$(target)=$$(ARCH-$(target))-apple-$$(OS_LOWER-$(target))
|
||||
@@ -662,7 +690,7 @@ BZIP2_FATLIB-$(sdk)=$$(BZIP2_MERGE-$(sdk))/lib/libbz2.a
|
||||
XZ_MERGE-$(sdk)=$(PROJECT_DIR)/merge/$(os)/$(sdk)/xz-$(XZ_VERSION)
|
||||
XZ_FATLIB-$(sdk)=$$(XZ_MERGE-$(sdk))/lib/liblzma.a
|
||||
|
||||
-OPENSSL_MERGE-$(sdk)=$(PROJECT_DIR)/merge/$(os)/$(sdk)/openssl-$(OPENSSL_VERSION)
|
||||
+OPENSSL_MERGE-$(sdk)=$(PROJECT_DIR)/merge/$(os)/openssl
|
||||
OPENSSL_FATINCLUDE-$(sdk)=$$(OPENSSL_MERGE-$(sdk))/include
|
||||
OPENSSL_SSL_FATLIB-$(sdk)=$$(OPENSSL_MERGE-$(sdk))/lib/libssl.a
|
||||
OPENSSL_CRYPTO_FATLIB-$(sdk)=$$(OPENSSL_MERGE-$(sdk))/lib/libcrypto.a
|
||||
@@ -716,14 +744,14 @@ $$(OPENSSL_SSL_FATLIB-$(sdk)): $$(foreach target,$$(SDK_TARGETS-$(sdk)),$$(OPENS
|
||||
mkdir -p $$(OPENSSL_MERGE-$(sdk))/lib
|
||||
lipo -create -output $$@ \
|
||||
$$(foreach target,$$(SDK_TARGETS-$(sdk)),$$(OPENSSL_SSL_LIB-$$(target))) \
|
||||
- 2>&1 | tee -a merge/$(os)/$(sdk)/openssl-$(OPENSSL_VERSION).ssl.lipo.log
|
||||
+ 2>&1 | tee -a merge/$(os)/openssl-$(OPENSSL_VERSION).ssl.lipo.log
|
||||
|
||||
$$(OPENSSL_CRYPTO_FATLIB-$(sdk)): $$(foreach target,$$(SDK_TARGETS-$(sdk)),$$(OPENSSL_CRYPTO_LIB-$$(target)))
|
||||
@echo ">>> Build OpenSSL crypto fat library for $(sdk)"
|
||||
mkdir -p $$(OPENSSL_MERGE-$(sdk))/lib
|
||||
lipo -create -output $$@ \
|
||||
$$(foreach target,$$(SDK_TARGETS-$(sdk)),$$(OPENSSL_CRYPTO_LIB-$$(target))) \
|
||||
- 2>&1 | tee -a merge/$(os)/$(sdk)/openssl-$(OPENSSL_VERSION).crypto.lipo.log
|
||||
+ 2>&1 | tee -a merge/$(os)/openssl-$(OPENSSL_VERSION).crypto.lipo.log
|
||||
|
||||
###########################################################################
|
||||
# SDK: libFFI
|
||||
46
td/example/ios/README.md
Normal file
46
td/example/ios/README.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# Universal XCFramework build example
|
||||
|
||||
Below are instructions for building TDLib for iOS, watchOS, tvOS, visionOS, and also macOS.
|
||||
|
||||
If you need only a macOS build for the current architecture, take a look at [TDLib build instructions generator](https://tdlib.github.io/td/build.html).
|
||||
|
||||
For example of usage take a look at our [Swift example](https://github.com/tdlib/td/tree/master/example/swift).
|
||||
|
||||
To compile `TDLib` you will need to:
|
||||
* Install the latest Xcode via `xcode-select --install` or downloading it from [Xcode website](https://developer.apple.com/xcode/).
|
||||
It is not enough to install only command line developer tools to build `TDLib` for iOS. Xcode >= 14.0 is required to build TDLib for watchOS.
|
||||
* Install other build dependencies using [Homebrew](https://brew.sh):
|
||||
```
|
||||
brew install gperf cmake coreutils
|
||||
```
|
||||
* If you don't want to build `TDLib` for macOS first, you **must** pregenerate required source code files in the following way:
|
||||
```
|
||||
cd <path to TDLib sources>
|
||||
mkdir native-build
|
||||
cd native-build
|
||||
cmake -DTD_GENERATE_SOURCE_FILES=ON ..
|
||||
cmake --build .
|
||||
```
|
||||
* Build OpenSSL for iOS, watchOS, tvOS, visionOS, and macOS:
|
||||
```
|
||||
cd <path to TDLib sources>/example/ios
|
||||
./build-openssl.sh
|
||||
```
|
||||
Here we use scripts from [Python Apple support](https://github.com/beeware/Python-Apple-support), but any other OpenSSL build 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 are no spaces in the path.
|
||||
Built OpenSSL libraries should be stored in the directory `third_party/openssl/<platform>`, because the next script will rely on this location.
|
||||
* Build TDLib for iOS, watchOS, tvOS, visionOS, and macOS:
|
||||
```
|
||||
cd <path to TDLib sources>/example/ios
|
||||
./build.sh
|
||||
```
|
||||
This may take a while, because TDLib will be built about 16 times.
|
||||
Resulting XCFramework will work on any architecture and even on a simulator.
|
||||
We use [CMake/iOS.cmake](https://github.com/tdlib/td/blob/master/CMake/iOS.cmake) toolchain, other toolchains may work too.
|
||||
|
||||
Built libraries and XCFramework will be stored in `tdjson` directory.
|
||||
|
||||
Documentation for all available classes and methods can be found at https://core.telegram.org/tdlib/docs.
|
||||
|
||||
If you receive an "error: SDK "appletvsimulator" cannot be located", you need to run the command "sudo xcode-select -s /Applications/Xcode.app/Contents/Developer" before running ./build.sh.
|
||||
37
td/example/ios/build-openssl.sh
Executable file
37
td/example/ios/build-openssl.sh
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/bin/sh
|
||||
cd $(dirname $0)
|
||||
|
||||
git clone https://github.com/beeware/Python-Apple-support
|
||||
cd Python-Apple-support
|
||||
git checkout 6f43aba0ddd5a9f52f39775d0141bd4363614020 || exit 1
|
||||
git reset --hard || exit 1
|
||||
git apply ../Python-Apple-support.patch || exit 1
|
||||
cd ..
|
||||
|
||||
platforms="macOS iOS watchOS tvOS visionOS"
|
||||
|
||||
for platform in $platforms;
|
||||
do
|
||||
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 || exit 1
|
||||
cd ..
|
||||
rm -rf third_party/openssl/$platform || exit 1
|
||||
mkdir -p third_party/openssl/$platform/lib || exit 1
|
||||
cp ./Python-Apple-support/merge/$platform/openssl/lib/libcrypto.a third_party/openssl/$platform/lib/ || exit 1
|
||||
cp ./Python-Apple-support/merge/$platform/openssl/lib/libssl.a third_party/openssl/$platform/lib/ || exit 1
|
||||
cp -r ./Python-Apple-support/merge/$platform/openssl/include/ third_party/openssl/$platform/include || exit 1
|
||||
done
|
||||
done
|
||||
92
td/example/ios/build.sh
Executable file
92
td/example/ios/build.sh
Executable file
@@ -0,0 +1,92 @@
|
||||
#!/bin/sh
|
||||
cd $(dirname $0)
|
||||
td_path=$(grealpath ../..)
|
||||
|
||||
rm -rf build
|
||||
mkdir -p build
|
||||
cd build
|
||||
|
||||
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 visionOS"
|
||||
#platforms="watchOS"
|
||||
for platform in $platforms;
|
||||
do
|
||||
echo "Platform = ${platform}"
|
||||
if [[ $platform = "macOS" ]]; then
|
||||
simulators="0"
|
||||
else
|
||||
simulators="0 1"
|
||||
fi
|
||||
|
||||
for simulator in $simulators;
|
||||
do
|
||||
if [[ $platform = "macOS" ]]; then
|
||||
other_options="-DCMAKE_OSX_ARCHITECTURES='x86_64;arm64'"
|
||||
else
|
||||
if [[ $platform = "watchOS" ]]; then
|
||||
ios_platform="WATCH"
|
||||
elif [[ $platform = "tvOS" ]]; then
|
||||
ios_platform="TV"
|
||||
elif [[ $platform = "visionOS" ]]; then
|
||||
ios_platform="VISION"
|
||||
else
|
||||
ios_platform=""
|
||||
fi
|
||||
|
||||
if [[ $simulator = "1" ]]; then
|
||||
platform="${platform}-simulator"
|
||||
ios_platform="${ios_platform}SIMULATOR"
|
||||
else
|
||||
ios_platform="${ios_platform}OS"
|
||||
fi
|
||||
|
||||
echo "iOS platform = ${ios_platform}"
|
||||
other_options="-DIOS_PLATFORM=${ios_platform} -DCMAKE_TOOLCHAIN_FILE=${td_path}/CMake/iOS.cmake"
|
||||
fi
|
||||
|
||||
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 $other_options -DCMAKE_INSTALL_PREFIX=../${install}
|
||||
make -j3 install || exit
|
||||
cd ..
|
||||
install_name_tool -id @rpath/libtdjson.dylib ${install}/lib/libtdjson.dylib
|
||||
mkdir -p ../tdjson/${platform}/include
|
||||
rsync --recursive ${install}/include/ ../tdjson/${platform}/include/
|
||||
mkdir -p ../tdjson/${platform}/lib
|
||||
cp ${install}/lib/libtdjson.dylib ../tdjson/${platform}/lib/
|
||||
done
|
||||
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/
|
||||
Reference in New Issue
Block a user