Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·198 lines (181 loc) · 7.89 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·198 lines (181 loc) · 7.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/bash -e
# See https://github.com/tdlib/td/blob/master/example/ios/build.sh
__DIR__="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
BUILD_ROOT_DIR="$__DIR__/build"
INSTALL_ROOT_DIR="$__DIR__/install"
ARCHIVES_ROOT_DIR="$__DIR__/archives"
TD_DIR="$__DIR__/td"
# cleanup all
# rm -fr $BUILD_ROOT_DIR
# rm -fr $INSTALL_ROOT_DIR
# rm -fr $ARCHIVES_ROOT_DIR
# rm -fr $TD_DIR
# https://github.com/beeware/Python-Apple-support/releases/download/3.9-b3/Python-3.9-$platform-support.b3.tar.gz will Cause error: ...libOpenSSL.a(bss_mem.o), building for iOS, but linking in object file (.../libOpenSSL.a(bss_mem.o)) built for macOS, for architecture arm64
download_prebuilt_openssl() {
local install_root_dir="$1"
local v_tag=3.1.5004
local f_name=OpenSSL.tar.gz
curl -SL https://github.com/krzyzanowskim/OpenSSL/archive/refs/tags/${v_tag}.tar.gz -o $f_name
tar xzf $f_name
# The output folder name should be OpenSSL-${v_tag}
mkdir -p $install_root_dir
mv OpenSSL-${v_tag} $install_root_dir/openssl
rm $f_name
# standardize the folder name
# mv $install_root_dir/openssl/appletvos $install_root_dir/openssl/tvOS
# mv $install_root_dir/openssl/appletvsimulator $install_root_dir/openssl/tvOS-simulator
mv $install_root_dir/openssl/iphoneos $install_root_dir/openssl/iOS
mv $install_root_dir/openssl/iphonesimulator $install_root_dir/openssl/iOS-simulator
mv $install_root_dir/openssl/macosx $install_root_dir/openssl/macOS
# mv $install_root_dir/openssl/macosx_catalyst $install_root_dir/openssl/macOS_catalyst
# mv $install_root_dir/openssl/visionos $install_root_dir/openssl/visionOS
# mv $install_root_dir/openssl/visionsimulator $install_root_dir/openssl/visionOS-simulator
}
download_td_source() {
cd $__DIR__
git clone https://github.com/tdlib/td.git
cd td
# How to get the hash if there is no version tag:
# - Goto https://github.com/tdlib/td/blame/master/CMakeLists.txt
# - Check the version from the line: `project(TDLib VERSION <version>...`
# - Copy version and paste to following:
# git checkout tags/v1.8.65
# - Click the commit link
# - Copy the commit hash from the browser url link (e.q. https://github.com/tdlib/td/commit/<hash>) and paste to following:
git checkout a8f21f5230172634becc1739050ef23ecd6ea291
cd ..
}
# prepare
if [ ! -d "$TD_DIR" ]; then
download_td_source
fi
if [ ! -d "$INSTALL_ROOT_DIR/openssl" ]; then
download_prebuilt_openssl $INSTALL_ROOT_DIR
fi
# build, see https://github.com/tdlib/td/tree/master/example/ios
if [ -z "$1" ]; then
# platforms="macOS iOS watchOS tvOS visionOS"
platforms="macOS iOS"
# Need to generate some files if we don't build macOS first, see https://github.com/tdlib/td/issues/1077#issuecomment-640056388
# if [ ! -d "$BUILD_ROOT_DIR/prepare_cross_compiling" ]; then
# mkdir -p $BUILD_ROOT_DIR/prepare_cross_compiling
# cd $BUILD_ROOT_DIR/prepare_cross_compiling
# cmake $TD_DIR || exit 1
# cmake --build . --target prepare_cross_compiling || exit 1
# fi
else
platforms="$1"
fi
xcodebuild_more_options=""
xcodebuild_static_more_options=""
for platform in $platforms; do
if [[ $platform = "macOS" ]]; then
simulators="0"
more_options="-DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES='x86_64;arm64'"
else
simulators="0 1"
more_options="-DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_TOOLCHAIN_FILE=${TD_DIR}/CMake/iOS.cmake -DCMAKE_MAKE_PROGRAM=make"
fi
openssl_install_path="$INSTALL_ROOT_DIR/openssl/${platform}"
build_dir="$BUILD_ROOT_DIR/${platform}"
install_dir="$INSTALL_ROOT_DIR/tdjson/${platform}"
for simulator in $simulators; do
if [[ $platform = "macOS" ]]; then
cmake_ios_platform=""
xcode_platform="OS"
else
if [[ $platform = "watchOS" ]]; then
cmake_ios_platform="WATCH"
elif [[ $platform = "tvOS" ]]; then
cmake_ios_platform="TV"
elif [[ $platform = "visionOS" ]]; then
cmake_ios_platform="VISION"
else
cmake_ios_platform=""
fi
xcode_platform=$platform
if [[ $simulator = "0" ]]; then
cmake_ios_platform="${cmake_ios_platform}OS"
else
cmake_ios_platform="${cmake_ios_platform}SIMULATOR"
xcode_platform="${cmake_ios_platform} Simulator"
openssl_install_path="${openssl_install_path}-simulator"
build_dir="${build_dir}-simulator"
install_dir="${install_dir}-simulator"
fi
more_options="$more_options -DIOS_PLATFORM=${cmake_ios_platform}"
fi
openssl_crypto_library="${openssl_install_path}/lib/libcrypto.a"
openssl_ssl_library="${openssl_install_path}/lib/libssl.a"
# rm -rf $build_dir $install_dir
mkdir -p $build_dir $install_dir
cd $build_dir
cmake $TD_DIR $more_options \
-DCMAKE_INSTALL_PREFIX=$install_dir \
-DOPENSSL_FOUND=1 \
-DOPENSSL_CRYPTO_LIBRARY=${openssl_crypto_library} \
-DOPENSSL_SSL_LIBRARY=${openssl_ssl_library} \
-DOPENSSL_INCLUDE_DIR=${openssl_install_path}/include \
-DOPENSSL_LIBRARIES="${openssl_crypto_library};${openssl_ssl_library}" || exit 1
cmake --build . --target tdjson || exit 1
cmake --build . --target tdjson_static || exit 1
cmake --install . || exit 1
# xcodebuild clean archive \
# -scheme "${SCHEME_NAME}" \
# -configuration "${CONFIGURATION}" \
# -sdk iphoneos \
# -archivePath "${IOS_DEVICE_ARCHIVE_PATH}" \
# -destination generic/platform=iOS \
# SKIP_INSTALL=NO \
# BUILD_LIBRARY_FOR_DISTRIBUTION=YES
# https://developer.apple.com/documentation/xcode/creating-a-multi-platform-binary-framework-bundle
# xcodebuild archive \
# -scheme libtdjson \
# -destination "generic/platform=$xcode_platform" \
# -archivePath "$ARCHIVES_ROOT_DIR/libtdjson-${xcode_platform}"
# xcodebuild_more_options="$xcodebuild_more_options -archive $ARCHIVES_ROOT_DIR/libtdjson-${xcode_platform}.xcarchive -framework libtdjson.framework"
# for a in $install_dir/lib/*.a; do
# abs_path="$(grealpath "${a}")"
# file $abs_path
# xcodebuild_more_options="$xcodebuild_more_options -library $abs_path -headers $install_dir/include"
# done
dylib_path="$install_dir/lib/libtdjson.dylib"
abs_path="$(grealpath "$dylib_path")"
if [ -h $dylib_path ]; then
rm -fr $dylib_path
mv $abs_path $dylib_path
install_name_tool -id @rpath/libtdjson.dylib $dylib_path
fi
xcodebuild_more_options="$xcodebuild_more_options -library $dylib_path"
# Merge every static archive tdjson_static depends on (tdcore, tdactor,
# tddb, tdnet, tdutils, tdsqlite, tdapi, tdjson_private, tdclient, ...)
# AND OpenSSL (libssl.a + libcrypto.a) into a single libtdjson.a.
# Without this, libtdjson_static.a alone has unresolved symbols for
# every tdlib subsystem and for OpenSSL. The dylib already bundles all
# of these internally — the merged .a is the static equivalent.
# xcodebuild requires -headers alongside -library for static archives.
combined_dir="$install_dir/combined"
mkdir -p "$combined_dir"
combined_a="$combined_dir/libtdjson.a"
rm -f "$combined_a"
libtool -static -no_warning_for_no_symbols -o "$combined_a" \
"$install_dir"/lib/libtd*.a \
"$openssl_install_path/lib/libcrypto.a" \
"$openssl_install_path/lib/libssl.a" || exit 1
xcodebuild_static_more_options="$xcodebuild_static_more_options -library $combined_a -headers $install_dir/include"
done
done
# What if met the error: Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionSentinelHostApplications for extension Xcode.DebuggerFoundation.AppExtensionHosts.watchOS of plug-in com.apple.dt.IDEWatchSupportCore...
# see:
# - https://apple.stackexchange.com/questions/438785/xcode-error-when-launching-terminal
# - https://stackoverflow.com/questions/71320584/flutter-build-ios-got-error-requested-but-did-not-find-extension-point-with-ide
echo $xcodebuild_more_options
rm -fr "$__DIR__/libtdjson.xcframework"
xcodebuild -create-xcframework \
${xcodebuild_more_options} \
-output "$__DIR__/libtdjson.xcframework"
echo $xcodebuild_static_more_options
rm -fr "$__DIR__/libtdjson-static.xcframework"
xcodebuild -create-xcframework \
${xcodebuild_static_more_options} \
-output "$__DIR__/libtdjson-static.xcframework"