This repository has been archived by the owner on Oct 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-dcc.sh
executable file
·228 lines (189 loc) · 6.11 KB
/
build-dcc.sh
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/usr/bin/env bash
# --- Setup and variables ---
# System flags
set -e
# User / CI input
platforms=$1
# Base paths
BASE_ANDROID="android"
BASE_IOS="ios"
BASE_DCC="delta_chat_core"
# Delta Chat Core
DCC_LIBRARY_NAME="libdeltachat.a"
DCC_ANDROID_ARCHITECTURES=("aarch64-linux-android" "armv7-linux-androideabi" "i686-linux-android" "x86_64-linux-android") # The order of DCC_ANDROID_TARGETS, DCC_ANDROID_BUILD_PARAMETERS and ANDROID_DCC_LIBRARY_SUB_FOLDERS must stay in sync
DCC_ANDROID_BUILD_PARAMETERS=("aarch64-linux-android21-clang" "armv7a-linux-androideabi21-clang" "i686-linux-android21-clang" "x86_64-linux-android21-clang") # The order of DCC_ANDROID_TARGETS, DCC_ANDROID_BUILD_PARAMETERS and ANDROID_DCC_LIBRARY_SUB_FOLDERS must stay in sync
DCC_IOS_ARCHITECTURES=("universal")
# Android
ANDROID_DCC_LIBRARY_FOLDER="android/jni"
ANDROID_DCC_LIBRARY_SUB_FOLDERS=("arm64-v8a" "armeabi-v7a" "x86" "x86_64") # The order of DCC_ANDROID_TARGETS, DCC_ANDROID_BUILD_PARAMETERS and ANDROID_DCC_LIBRARY_SUB_FOLDERS must stay in sync
# ANDROID_RUST_TARGETS is implicitly defined by DCC_ANDROID_ARCHITECTURES, please use DCC_ANDROID_ARCHITECTURES to refer to the Android Rust targets
# iOS
IOS_DCC_LIBRARY_FOLDER="ios/Libraries"
IOS_RUST_TARGETS=("aarch64-apple-ios" "x86_64-apple-ios")
# Functions
function isAndroid {
if [[ ${platforms} == "android" || ${platforms} == "all" ]]; then
true
else
false
fi
}
function isIos {
if [[ ${platforms} == "ios" || ${platforms} == "all" ]]; then
true
else
false
fi
}
function checkTarget {
currentTarget=${1}
echo "Checking rust target $currentTarget..."
isInstalled=$(rustup target list --installed | grep ${currentTarget} -c | cat)
if [[ ${isInstalled} != 1 ]]; then
echo "ERROR - $currentTarget is missing"
if isAndroid; then
platformTargets=${DCC_ANDROID_ARCHITECTURES[@]}
fi
if isIos; then
platformTargets=${IOS_RUST_TARGETS[@]}
fi
echo "Fix via: cd $BASE_DCC && rustup target add $platformTargets && cd .."
exit 5
fi
}
function checkTargets {
if isAndroid; then
for i in "${!DCC_ANDROID_ARCHITECTURES[@]}"; do
currentTarget="${DCC_ANDROID_ARCHITECTURES[$i]}"
checkTarget ${currentTarget}
done
fi
if isIos; then
for i in "${!IOS_RUST_TARGETS[@]}"; do
currentTarget="${IOS_RUST_TARGETS[$i]}"
checkTarget ${currentTarget}
done
fi
}
function testCommand() {
command=${1}
echo "Checking $command..."
if ! [[ -x "$(command -v ${command})" ]]; then
echo "ERROR - $command is missing"
if [[ ${command} == "rustc" || ${command} == "cargo" ]]; then
echo "Fix via: curl https://sh.rustup.rs -sSf | sh"
elif [[ ${command} == "cargo-lipo" ]]; then
echo "Fix via: cargo install cargo-lipo"
elif [[ ${command} == "ndk-build" ]]; then
echo "Fix via: https://developer.android.com/studio/projects/install-ndk.md and add you ndk-bundle folder to your path (located in the Android SDK)"
fi
exit 4
fi
}
function buildAndroid {
export CFLAGS=-D__ANDROID_API__=21
for i in "${!DCC_ANDROID_ARCHITECTURES[@]}"; do
currentTarget="${DCC_ANDROID_ARCHITECTURES[$i]}"
echo "Building $currentTarget"
TARGET_CC="${DCC_ANDROID_BUILD_PARAMETERS[$i]}" \
cargo build --release --target ${currentTarget} -p deltachat_ffi
done
}
function buildIos {
cargo lipo --release --manifest-path 'deltachat-ffi/Cargo.toml' --no-default-features --features nightly
}
function buildPlatforms {
if isAndroid; then
buildAndroid
fi
if isIos; then
buildIos
fi
}
function moveFromTarget {
target=${1}
copyTarget=${2}
targetPath="target/${target}/release/${DCC_LIBRARY_NAME}"
echo "Moving $targetPath to $copyTarget"
mv ${targetPath} ${copyTarget}
}
function moveAndroid {
for i in "${!DCC_ANDROID_ARCHITECTURES[@]}"; do
currentTarget="${DCC_ANDROID_ARCHITECTURES[$i]}"
currentCopyTarget="../${ANDROID_DCC_LIBRARY_FOLDER}/${ANDROID_DCC_LIBRARY_SUB_FOLDERS[$i]}"
rm -rf ${currentCopyTarget}
mkdir -p ${currentCopyTarget}
moveFromTarget ${currentTarget} ${currentCopyTarget}
done
}
function moveIos {
mkdir -p "../${IOS_DCC_LIBRARY_FOLDER}"
for i in "${!DCC_IOS_ARCHITECTURES[@]}"; do
currentTarget="${DCC_IOS_ARCHITECTURES[$i]}"
moveFromTarget ${currentTarget} "../${IOS_DCC_LIBRARY_FOLDER}/"
done
}
function movePlatforms {
if isAndroid; then
moveAndroid
fi
if isIos; then
moveIos
fi
}
function changeDirectory {
echo "Changing directory to $(pwd)"
cd $1 || exit 1
}
function postCompileAndroid {
echo "Resetting Cargo.toml and Cargo.lock changes"
git checkout Cargo.lock
git checkout Cargo.toml
}
# Execution
echo "-- Checking prerequisites --"
if [[ -z "$(ls -A ${BASE_DCC})" ]]; then
echo "ERROR - Delta Chat sub repository not found"
echo "Fix via: git submodule update --init --recursive"
exit 2
fi
if ! isAndroid && ! isIos; then
echo "ERROR - No or wrong platforms selected"
echo "Fix via: ./build-dcc.sh [android OR ios OR all]"
exit 3
fi
testCommand rustc
testCommand cargo
if isAndroid; then
testCommand ndk-build
fi
if isIos; then
testCommand cargo-lipo
fi
changeDirectory ${BASE_DCC}
checkTargets
echo "-- Applying platform specific fixes --"
echo "-- Compiling Rust core --"
buildPlatforms
echo "-- Performing post Rust compile steps --"
if isAndroid; then
postCompileAndroid
fi
echo "-- Moving files --"
movePlatforms
echo "-- Performing additional build steps --"
if isAndroid; then
changeDirectory "../${BASE_ANDROID}"
echo "Building via ndk-build"
ndk-build
fi
if isIos; then
echo "Adjusting symlinks"
changeDirectory "../$IOS_DCC_LIBRARY_FOLDER"
ln -sf "../../$BASE_DCC/deltachat-ffi/deltachat.h" .
fi
echo "-- Finishing + hints --"
if isIos; then
echo "NOTE: Don't forget to run: cd ../ox-coi/ios && rm -f Podfile.lock && pod install"
fi
echo "-- Build succeeded --"