xref: /freebsd/contrib/ldns/README-Travis.md (revision 5afab0e5e56fe90a378fb57249600e7924e1cab2)
1*5afab0e5SDag-Erling Smørgrav# Travis Testing
2*5afab0e5SDag-Erling Smørgrav
3*5afab0e5SDag-Erling SmørgravLDNS 1.7.1 and above leverage Travis CI to increase coverage of compilers and platforms. Compilers include Clang and GCC; while platforms include Android, iOS, Linux, and OS X on AMD64, Aarch64, PowerPC and s390x hardware.
4*5afab0e5SDag-Erling Smørgrav
5*5afab0e5SDag-Erling SmørgravAndroid is tested on armv7a, aarch64, x86 and x86_64. The Android recipes build and install OpenSSL, and then builds LDNS. The testing is tailored for Android NDK-r19 and above, and includes NDK-r20 and NDK-r21. Mips and Mips64 are not tested because they are no longer supported under current NDKs.
6*5afab0e5SDag-Erling Smørgrav
7*5afab0e5SDag-Erling SmørgraviOS is tested for iPhoneOS, WatchOS, AppleTVOS, iPhoneSimulator, AppleTVSimulator and WatchSimulator. The testing uses Xcode 10 on OS X 10.13.
8*5afab0e5SDag-Erling Smørgrav
9*5afab0e5SDag-Erling SmørgravThe LDNS Travis configuration file `.travis.yml` does not use top-level keys like `os:` and `compiler:` so there is no matrix expansion. Instead LDNS specifies the exact job to run under the `jobs:` and `include:` keys.
10*5afab0e5SDag-Erling Smørgrav
11*5afab0e5SDag-Erling Smørgrav## Typical recipe
12*5afab0e5SDag-Erling Smørgrav
13*5afab0e5SDag-Erling SmørgravA typical recipe tests Clang and GCC on various hardware. The hardware includes AMD64, Aarch64, PowerPC and s390x. PowerPC is a little-endian platform, and s390x is a big-endian platform. There are pairs of recipes that are similar to the following.
14*5afab0e5SDag-Erling Smørgrav
15*5afab0e5SDag-Erling Smørgrav```
16*5afab0e5SDag-Erling Smørgrav- os: linux
17*5afab0e5SDag-Erling Smørgrav  name: GCC on Linux, Aarch64
18*5afab0e5SDag-Erling Smørgrav  compiler: gcc
19*5afab0e5SDag-Erling Smørgrav  arch: arm64
20*5afab0e5SDag-Erling Smørgrav  dist: bionic
21*5afab0e5SDag-Erling Smørgrav- os: linux
22*5afab0e5SDag-Erling Smørgrav  name: Clang on Linux, Aarch64
23*5afab0e5SDag-Erling Smørgrav  compiler: clang
24*5afab0e5SDag-Erling Smørgrav  arch: arm64
25*5afab0e5SDag-Erling Smørgrav  dist: bionic
26*5afab0e5SDag-Erling Smørgrav```
27*5afab0e5SDag-Erling Smørgrav
28*5afab0e5SDag-Erling SmørgravOS X provides a single recipe to test Clang. GCC is not tested because GCC is an alias for Clang.
29*5afab0e5SDag-Erling Smørgrav
30*5afab0e5SDag-Erling Smørgrav## Sanitizer builds
31*5afab0e5SDag-Erling Smørgrav
32*5afab0e5SDag-Erling SmørgravTwo sanitizer builds are tested using Clang and GCC, for a total of four builds. The first sanitizer is Undefined Behavior sanitizer (UBsan), and the second is Address sanitizer (Asan). The sanitizers are only run on AMD64 hardware. Note the environment includes `UBSAN=yes` or `ASAN=yes` for the sanitizer builds.
33*5afab0e5SDag-Erling Smørgrav
34*5afab0e5SDag-Erling SmørgravThe recipes are similar to the following.
35*5afab0e5SDag-Erling Smørgrav
36*5afab0e5SDag-Erling Smørgrav```
37*5afab0e5SDag-Erling Smørgrav- os: linux
38*5afab0e5SDag-Erling Smørgrav  name: UBsan, GCC on Linux, Amd64
39*5afab0e5SDag-Erling Smørgrav  compiler: gcc
40*5afab0e5SDag-Erling Smørgrav  arch: amd64
41*5afab0e5SDag-Erling Smørgrav  dist: bionic
42*5afab0e5SDag-Erling Smørgrav  env: UBSAN=yes
43*5afab0e5SDag-Erling Smørgrav- os: linux
44*5afab0e5SDag-Erling Smørgrav  name: UBsan, Clang on Linux, Amd64
45*5afab0e5SDag-Erling Smørgrav  compiler: clang
46*5afab0e5SDag-Erling Smørgrav  arch: amd64
47*5afab0e5SDag-Erling Smørgrav  dist: bionic
48*5afab0e5SDag-Erling Smørgrav  env: UBSAN=yes
49*5afab0e5SDag-Erling Smørgrav```
50*5afab0e5SDag-Erling Smørgrav
51*5afab0e5SDag-Erling SmørgravWhen the Travis script encounters a sanitizer it uses different `CFLAGS` and configuration string.
52*5afab0e5SDag-Erling Smørgrav
53*5afab0e5SDag-Erling Smørgrav```
54*5afab0e5SDag-Erling Smørgravif [ "$UBSAN" = "yes" ]; then
55*5afab0e5SDag-Erling Smørgrav  export CFLAGS="-DNDEBUG -g2 -O3 -fsanitize=undefined -fno-sanitize-recover"
56*5afab0e5SDag-Erling Smørgrav  bash test/test_ci.sh
57*5afab0e5SDag-Erling Smørgravelif [ "$ASAN" = "yes" ]; then
58*5afab0e5SDag-Erling Smørgrav  export CFLAGS="-DNDEBUG -g2 -O3 -fsanitize=address"
59*5afab0e5SDag-Erling Smørgrav  bash test/test_ci.sh
60*5afab0e5SDag-Erling Smørgrav...
61*5afab0e5SDag-Erling Smørgrav```
62*5afab0e5SDag-Erling Smørgrav
63*5afab0e5SDag-Erling Smørgrav## Android builds
64*5afab0e5SDag-Erling Smørgrav
65*5afab0e5SDag-Erling SmørgravTravis tests Android builds for the armv7a, aarch64, x86 and x86_64 architectures. The builds are trickier than other builds for several reasons. The testing requires installation of the Android NDK and SDK, it requires a cross-compile, and requires OpenSSL prerequisites. The Android cross-compiles also require care to set the Autotools triplet, the OpenSSL triplet, the toolchain path, the tool variables, and the sysroot. The discussion below detail the steps of the Android recipes.
66*5afab0e5SDag-Erling Smørgrav
67*5afab0e5SDag-Erling Smørgrav### Android job
68*5afab0e5SDag-Erling Smørgrav
69*5afab0e5SDag-Erling SmørgravThe first step sets environmental variables for the cross-compile using the Travis job. A typical job with variables is shown below.
70*5afab0e5SDag-Erling Smørgrav
71*5afab0e5SDag-Erling Smørgrav```
72*5afab0e5SDag-Erling Smørgrav- os: linux
73*5afab0e5SDag-Erling Smørgrav  name: Android armv7a, Linux, Amd64
74*5afab0e5SDag-Erling Smørgrav  compiler: clang
75*5afab0e5SDag-Erling Smørgrav  arch: amd64
76*5afab0e5SDag-Erling Smørgrav  dist: bionic
77*5afab0e5SDag-Erling Smørgrav  env:
78*5afab0e5SDag-Erling Smørgrav    - ANDROID=yes
79*5afab0e5SDag-Erling Smørgrav    - AUTOTOOLS_HOST=armv7a-linux-androideabi
80*5afab0e5SDag-Erling Smørgrav    - OPENSSL_HOST=android-arm
81*5afab0e5SDag-Erling Smørgrav    - ANDROID_CPU=armv7a
82*5afab0e5SDag-Erling Smørgrav    - ANDROID_API=23
83*5afab0e5SDag-Erling Smørgrav    - ANDROID_PREFIX="$HOME/android$ANDROID_API-$ANDROID_CPU"
84*5afab0e5SDag-Erling Smørgrav    - ANDROID_SDK_ROOT="$HOME/android-sdk"
85*5afab0e5SDag-Erling Smørgrav    - ANDROID_NDK_ROOT="$HOME/android-ndk"
86*5afab0e5SDag-Erling Smørgrav```
87*5afab0e5SDag-Erling Smørgrav
88*5afab0e5SDag-Erling Smørgrav### ANDROID_NDK_ROOT
89*5afab0e5SDag-Erling Smørgrav
90*5afab0e5SDag-Erling SmørgravThe second step for Android is to set the environmental variables `ANDROID_NDK_ROOT` and `ANDROID_SDK_ROOT`. This is an important step because the NDK and SDK use the variables internally to locate their own tools. Also see [Recommended NDK Directory?](https://groups.google.com/forum/#!topic/android-ndk/qZjhOaynHXc) on the android-ndk mailing list. (Many folks miss this step, or use incorrect variables like `ANDROID_NDK_HOME` or `ANDROID_SDK_HOME`).
91*5afab0e5SDag-Erling Smørgrav
92*5afab0e5SDag-Erling SmørgravIf you are working from a developer machine you probably already have the necessary tools installed. You should ensure `ANDROID_NDK_ROOT` and `ANDROID_SDK_ROOT` are set properly.
93*5afab0e5SDag-Erling Smørgrav
94*5afab0e5SDag-Erling Smørgrav### Tool installation
95*5afab0e5SDag-Erling Smørgrav
96*5afab0e5SDag-Erling SmørgravThe second step installs tools needed for OpenSSL, Expat and LDNS. This step is handled in by the script `contrib/android/install_tools.sh`. The tools include curl, tar, zip, unzip and java.
97*5afab0e5SDag-Erling Smørgrav
98*5afab0e5SDag-Erling Smørgrav```
99*5afab0e5SDag-Erling Smørgravbefore_script:
100*5afab0e5SDag-Erling Smørgrav  - |
101*5afab0e5SDag-Erling Smørgrav    if [ "$ANDROID" = "yes" ]; then
102*5afab0e5SDag-Erling Smørgrav      ./contrib/android/install_tools.sh
103*5afab0e5SDag-Erling Smørgrav    elif [ "$IOS" = "yes" ]; then
104*5afab0e5SDag-Erling Smørgrav      ./contrib/ios/install_tools.sh
105*5afab0e5SDag-Erling Smørgrav    fi
106*5afab0e5SDag-Erling Smørgrav```
107*5afab0e5SDag-Erling Smørgrav
108*5afab0e5SDag-Erling Smørgrav### NDK installation
109*5afab0e5SDag-Erling Smørgrav
110*5afab0e5SDag-Erling SmørgravThe third step installs the NDK and SDK. This step is handled in by the script `contrib/android/install_ndk.sh`. The script uses `ANDROID_NDK_ROOT` and `ANDROID_SDK_ROOT` to place the NDK and SDK in the `$HOME` directory.
111*5afab0e5SDag-Erling Smørgrav
112*5afab0e5SDag-Erling SmørgravIf you are working from a developer machine you probably already have a NDK and SDK installed.
113*5afab0e5SDag-Erling Smørgrav
114*5afab0e5SDag-Erling Smørgrav### Android environment
115*5afab0e5SDag-Erling Smørgrav
116*5afab0e5SDag-Erling SmørgravThe fourth step sets the Android cross-compile environment using the script `contrib/android/setenv_android.sh`. The script is `sourced` so the variables in the script are available to the calling shell. The script sets variables like `CC`, `CXX`, `AS` and `AR`; sets `CFLAGS` and `CXXFLAGS`; sets a `sysroot` so Android headers and libraries are found; and adds the path to the toolchain to `PATH`.
117*5afab0e5SDag-Erling Smørgrav
118*5afab0e5SDag-Erling Smørgrav`contrib/android/setenv_android.sh` knows which toolchain and architecture to select by inspecting environmental variables set by Travis for the job. In particular, the variables `ANDROID_CPU` and `ANDROID_API` tell `contrib/android/setenv_android.sh` which tools and libraries to select.
119*5afab0e5SDag-Erling Smørgrav
120*5afab0e5SDag-Erling SmørgravThe `contrib/android/setenv_android.sh` script specifies the tools in a `case` statement like the following. There is a case for each of the architectures armv7a, aarch64, x86 and x86_64.
121*5afab0e5SDag-Erling Smørgrav
122*5afab0e5SDag-Erling Smørgrav```
123*5afab0e5SDag-Erling Smørgravarmv8a|aarch64|arm64|arm64-v8a)
124*5afab0e5SDag-Erling Smørgrav  CC="aarch64-linux-android$ANDROID_API-clang"
125*5afab0e5SDag-Erling Smørgrav  CXX="aarch64-linux-android$ANDROID_API-clang++"
126*5afab0e5SDag-Erling Smørgrav  LD="aarch64-linux-android-ld"
127*5afab0e5SDag-Erling Smørgrav  AS="aarch64-linux-android-as"
128*5afab0e5SDag-Erling Smørgrav  AR="aarch64-linux-android-ar"
129*5afab0e5SDag-Erling Smørgrav  RANLIB="aarch64-linux-android-ranlib"
130*5afab0e5SDag-Erling Smørgrav  STRIP="aarch64-linux-android-strip"
131*5afab0e5SDag-Erling Smørgrav
132*5afab0e5SDag-Erling Smørgrav  CFLAGS="-funwind-tables -fexceptions"
133*5afab0e5SDag-Erling Smørgrav  CXXFLAGS="-funwind-tables -fexceptions -frtti"
134*5afab0e5SDag-Erling Smørgrav```
135*5afab0e5SDag-Erling Smørgrav
136*5afab0e5SDag-Erling Smørgrav### OpenSSL
137*5afab0e5SDag-Erling Smørgrav
138*5afab0e5SDag-Erling SmørgravThe fifth step builds OpenSSL. OpenSSL is built for iOS using the scripts `contrib/android/install_openssl.sh`. The script downloads, configures and installs the latest release version of the OpenSSL libraries. OpenSSL is configured with `--prefix="$ANDROID_PREFIX"` so the headers are placed in `$ANDROID_PREFIX/include` directory, and the libraries are placed in the `$ANDROID_PREFIX/lib` directory.
139*5afab0e5SDag-Erling Smørgrav
140*5afab0e5SDag-Erling Smørgrav`ANDROID_PREFIX` is the value `$HOME/android$ANDROID_API-$ANDROID_CPU`. The libraries will be installed in `$HOME/android23-armv7a`, `$HOME/android23-aarch64`, etc. For Autotools projects, the appropriate `PKG_CONFIG_PATH` is exported.
141*5afab0e5SDag-Erling Smørgrav
142*5afab0e5SDag-Erling Smørgrav`PKG_CONFIG_PATH` is an important variable. It is the userland equivalent to sysroot, and allows Autotools to find non-system headers and libraries for an architecture. Typical `PKG_CONFIG_PATH` are `$HOME/android23-armv7a/lib/pkgconfig` and `$HOME/android23-aarch64/lib/pkgconfig`.
143*5afab0e5SDag-Erling Smørgrav
144*5afab0e5SDag-Erling SmørgravOpenSSL also uses a custom configuration file called `15-android.conf`. It is a copy of the OpenSSL's project file and located at `contrib/android/15-android.conf`. The LDNS version is copied to the OpenSSL source files after unpacking the OpenSSL distribution. The LDNS version has legacy NDK support removed and some other fixes, like `ANDROID_NDK_ROOT` awareness. The changes mean LDNS's `15-android.conf` will only work with LDNS, with NDK-r19 and above, and a properly set environment.
145*5afab0e5SDag-Erling Smørgrav
146*5afab0e5SDag-Erling SmørgravOpenSSL is configured with `no-engine`. If you want to include OpenSSL engines then edit `contrib/android/install_openssl.sh` and remove the config option.
147*5afab0e5SDag-Erling Smørgrav
148*5afab0e5SDag-Erling Smørgrav### Android build
149*5afab0e5SDag-Erling Smørgrav
150*5afab0e5SDag-Erling SmørgravFinally, once OpenSSL are built, then the Travis script configures and builds LDNS. The recipe looks as follows.
151*5afab0e5SDag-Erling Smørgrav
152*5afab0e5SDag-Erling Smørgrav```
153*5afab0e5SDag-Erling Smørgravelif [ "$ANDROID" = "yes" ]; then
154*5afab0e5SDag-Erling Smørgrav  export AUTOTOOLS_BUILD="$(./config.guess)"
155*5afab0e5SDag-Erling Smørgrav  export PKG_CONFIG_PATH="$ANDROID_PREFIX/lib/pkgconfig"
156*5afab0e5SDag-Erling Smørgrav  ./contrib/android/install_ndk.sh
157*5afab0e5SDag-Erling Smørgrav  source ./contrib/android/setenv_android.sh
158*5afab0e5SDag-Erling Smørgrav  ./contrib/android/install_openssl.sh
159*5afab0e5SDag-Erling Smørgrav  ./contrib/android/bootstrap_ldns.sh
160*5afab0e5SDag-Erling Smørgrav  ./configure \
161*5afab0e5SDag-Erling Smørgrav    --build="$AUTOTOOLS_BUILD" \
162*5afab0e5SDag-Erling Smørgrav    --host="$AUTOTOOLS_HOST" \
163*5afab0e5SDag-Erling Smørgrav    --prefix="$ANDROID_PREFIX" \
164*5afab0e5SDag-Erling Smørgrav    --with-ssl="$ANDROID_PREFIX" \
165*5afab0e5SDag-Erling Smørgrav    --disable-gost \
166*5afab0e5SDag-Erling Smørgrav    --with-drill --with-examples
167*5afab0e5SDag-Erling Smørgrav  make -j 2
168*5afab0e5SDag-Erling Smørgrav  make install
169*5afab0e5SDag-Erling Smørgrav```
170*5afab0e5SDag-Erling Smørgrav
171*5afab0e5SDag-Erling SmørgravTravis only smoke tests an Android build using a compile, link and install. The self tests are not run. TODO: figure out how to fire up an emulator, push the tests to the device and run them.
172*5afab0e5SDag-Erling Smørgrav
173*5afab0e5SDag-Erling Smørgrav### Android flags
174*5afab0e5SDag-Erling Smørgrav
175*5afab0e5SDag-Erling Smørgrav`contrib/android/setenv_android.sh` uses specific flags for `CFLAGS` and `CXXFLAGS`. They are taken from `ndk-build`, so we consider them the official flag set. It is important to use the same flags across projects to avoid subtle problems due to mixing and matching different flags.
176*5afab0e5SDag-Erling Smørgrav
177*5afab0e5SDag-Erling Smørgrav`CXXFLAGS` includes `-fexceptions` and `-frtti` because exceptions and runtime type info are disabled by default. `CFLAGS` include `-funwind-tables` and `-fexceptions` to ensure C++ exceptions pass through C code, if needed. Also see `docs/CPLUSPLUS-SUPPORT.html` in the NDK docs.
178*5afab0e5SDag-Erling Smørgrav
179*5afab0e5SDag-Erling SmørgravTo inspect the flags used by `ndk-build` for a platform clone ASOP's [ndk-samples](https://github.com/android/ndk-samples/tree/master/hello-jni) and build the `hello-jni` project. Use the `V=1` flag to see the full compiler output from `ndk-build`.
180*5afab0e5SDag-Erling Smørgrav
181*5afab0e5SDag-Erling Smørgrav## iOS builds
182*5afab0e5SDag-Erling Smørgrav
183*5afab0e5SDag-Erling SmørgravTravis tests iOS builds for the armv7a, armv7s and aarch64 architectures for iPhoneOS, AppleTVOS and WatchOS. iPhoneOS is tested using both 32-bit builds (iPhones) and 64-bit builds (iPads). Travis also tests compiles against the simulators. The builds are trickier than other builds for several reasons. The testing requires a cross-compile, and requires OpenSSL prerequisites. The iOS cross-compiles also require care to set the Autotools triplet, the OpenSSL triplet, the toolchain path, the tool variables, and the sysroot. The discussion below detail the steps of the iOS recipes.
184*5afab0e5SDag-Erling Smørgrav
185*5afab0e5SDag-Erling Smørgrav### iOS job
186*5afab0e5SDag-Erling Smørgrav
187*5afab0e5SDag-Erling SmørgravThe first step sets environmental variables for the cross-compile using the Travis job. A typical job with variables is shown below.
188*5afab0e5SDag-Erling Smørgrav
189*5afab0e5SDag-Erling Smørgrav```
190*5afab0e5SDag-Erling Smørgrav- os: osx
191*5afab0e5SDag-Erling Smørgrav  osx_image: xcode10
192*5afab0e5SDag-Erling Smørgrav  name: Apple iPhone on iOS, armv7
193*5afab0e5SDag-Erling Smørgrav  compiler: clang
194*5afab0e5SDag-Erling Smørgrav  env:
195*5afab0e5SDag-Erling Smørgrav    - IOS=yes
196*5afab0e5SDag-Erling Smørgrav    - AUTOTOOLS_HOST=armv7-apple-ios
197*5afab0e5SDag-Erling Smørgrav    - OPENSSL_HOST=ios-cross
198*5afab0e5SDag-Erling Smørgrav    - IOS_SDK=iPhoneOS
199*5afab0e5SDag-Erling Smørgrav    - IOS_CPU=armv7s
200*5afab0e5SDag-Erling Smørgrav    - IOS_PREFIX="$HOME/$IOS_SDK-$IOS_CPU"
201*5afab0e5SDag-Erling Smørgrav```
202*5afab0e5SDag-Erling Smørgrav
203*5afab0e5SDag-Erling Smørgrav### Tool installation
204*5afab0e5SDag-Erling Smørgrav
205*5afab0e5SDag-Erling SmørgravThe second step installs tools needed for OpenSSL, Expat and LDNS. This step is handled in by the script `contrib/ios/install_tools.sh`. The tools include autotools, curl and perl. The installation happens at the `before_script:` stage of Travis.
206*5afab0e5SDag-Erling Smørgrav
207*5afab0e5SDag-Erling Smørgrav```
208*5afab0e5SDag-Erling Smørgravbefore_script:
209*5afab0e5SDag-Erling Smørgrav  - |
210*5afab0e5SDag-Erling Smørgrav    if [ "$ANDROID" = "yes" ]; then
211*5afab0e5SDag-Erling Smørgrav      ./contrib/android/install_tools.sh
212*5afab0e5SDag-Erling Smørgrav    elif [ "$IOS" = "yes" ]; then
213*5afab0e5SDag-Erling Smørgrav      ./contrib/ios/install_tools.sh
214*5afab0e5SDag-Erling Smørgrav    fi
215*5afab0e5SDag-Erling Smørgrav```
216*5afab0e5SDag-Erling Smørgrav
217*5afab0e5SDag-Erling Smørgrav### iOS environment
218*5afab0e5SDag-Erling Smørgrav
219*5afab0e5SDag-Erling SmørgravThe third step sets the iOS cross-compile environment using the script `contrib/ios/setenv_ios.sh`. The script is `sourced` so the variables in the script are available to the calling shell. The script sets variables like `CC`, `CXX`, `AS` and `AR`; sets `CFLAGS` and `CXXFLAGS`; sets a `sysroot` so iOS headers and libraries are found; and adds the path to the toolchain to `PATH`.
220*5afab0e5SDag-Erling Smørgrav
221*5afab0e5SDag-Erling Smørgrav`contrib/ios/setenv_ios.sh` knows which toolchain and architecture to select by inspecting environmental variables set by Travis for the job. In particular, the variables `IOS_SDK` and `IOS_CPU` tell `contrib/ios/setenv_ios.sh` which tools and libraries to select.
222*5afab0e5SDag-Erling Smørgrav
223*5afab0e5SDag-Erling SmørgravThe `contrib/ios/setenv_ios.sh` script specifies the tools to use during the cross-compile. For Apple SDKs, the tool names are the same as a desktop. There are no special prefixes for the mobile tools.
224*5afab0e5SDag-Erling Smørgrav
225*5afab0e5SDag-Erling Smørgrav```
226*5afab0e5SDag-Erling SmørgravCPP=cpp
227*5afab0e5SDag-Erling SmørgravCC=clang
228*5afab0e5SDag-Erling SmørgravCXX=clang++
229*5afab0e5SDag-Erling SmørgravLD=ld
230*5afab0e5SDag-Erling SmørgravAS=as
231*5afab0e5SDag-Erling SmørgravAR=ar
232*5afab0e5SDag-Erling SmørgravRANLIB=ranlib
233*5afab0e5SDag-Erling SmørgravSTRIP=strip
234*5afab0e5SDag-Erling Smørgrav```
235*5afab0e5SDag-Erling Smørgrav
236*5afab0e5SDag-Erling SmørgravIf you are working from a developer machine you probably already have the necessary tools installed.
237*5afab0e5SDag-Erling Smørgrav
238*5afab0e5SDag-Erling Smørgrav### OpenSSL
239*5afab0e5SDag-Erling Smørgrav
240*5afab0e5SDag-Erling SmørgravThe fourth step builds OpenSSL. OpenSSL is built for iOS using the scripts `contrib/ios/install_openssl.sh`. The script downloads, configures and installs the latest release version of the OpenSSL libraries. OpenSSL is configured with `--prefix="$IOS_PREFIX"` so the headers are placed in `$IOS_PREFIX/include` directory, and the libraries are placed in the `$IOS_PREFIX/lib` directory.
241*5afab0e5SDag-Erling Smørgrav
242*5afab0e5SDag-Erling Smørgrav`IOS_PREFIX` is the value `$HOME/$IOS_SDK-$IOS_CPU`. The scheme handles both iOS SDKs and cpu architectures so the pair receives a unique installation directory. The libraries will be installed in `$HOME/iPhoneOS-armv7s`, `$HOME/iPhoneOS-arm64`, `$HOME/iPhoneSimulator-i386`, etc. For Autotools projects, the appropriate `PKG_CONFIG_PATH` is exported.
243*5afab0e5SDag-Erling Smørgrav
244*5afab0e5SDag-Erling Smørgrav`PKG_CONFIG_PATH` is an important variable. It is the userland equivalent to sysroot, and allows Autotools to find non-system headers and libraries for an architecture. Typical `PKG_CONFIG_PATH` are `$HOME/iPhoneOS-armv7s/lib/pkgconfig` and `$HOME/iPhoneOS-arm64/lib/pkgconfig`.
245*5afab0e5SDag-Erling Smørgrav
246*5afab0e5SDag-Erling SmørgravOpenSSL also uses a custom configuration file called `15-ios.conf`. It is a copy of the OpenSSL's project file and located at `contrib/ios/15-ios.conf`. The LDNS version is copied to the OpenSSL source files after unpacking the OpenSSL distribution. The changes mean LDNS's `15-ios.conf` will only work with LDNS and a properly set environment.
247*5afab0e5SDag-Erling Smørgrav
248*5afab0e5SDag-Erling SmørgravOpenSSL is configured with `no-engine`. Engines require dynamic loading so engines are disabled permanently in `15-ios.conf`.
249*5afab0e5SDag-Erling Smørgrav
250*5afab0e5SDag-Erling Smørgrav### iOS build
251*5afab0e5SDag-Erling Smørgrav
252*5afab0e5SDag-Erling SmørgravFinally, once OpenSSL are built, then the Travis script configures and builds LDNS. The full recipe looks as follows.
253*5afab0e5SDag-Erling Smørgrav
254*5afab0e5SDag-Erling Smørgrav```
255*5afab0e5SDag-Erling Smørgravelif [ "$IOS" = "yes" ]; then
256*5afab0e5SDag-Erling Smørgrav  export AUTOTOOLS_BUILD="$(./config.guess)"
257*5afab0e5SDag-Erling Smørgrav  export PKG_CONFIG_PATH="$IOS_PREFIX/lib/pkgconfig"
258*5afab0e5SDag-Erling Smørgrav  source ./contrib/ios/setenv_ios.sh
259*5afab0e5SDag-Erling Smørgrav  ./contrib/ios/install_openssl.sh
260*5afab0e5SDag-Erling Smørgrav  ./contrib/ios/bootstrap_ldns.sh
261*5afab0e5SDag-Erling Smørgrav  ./configure \
262*5afab0e5SDag-Erling Smørgrav    --build="$AUTOTOOLS_BUILD" --host="$AUTOTOOLS_HOST" \
263*5afab0e5SDag-Erling Smørgrav    --prefix="$IOS_PREFIX" \
264*5afab0e5SDag-Erling Smørgrav    --with-ssl="$IOS_PREFIX" --disable-gost \
265*5afab0e5SDag-Erling Smørgrav    --with-drill --with-examples
266*5afab0e5SDag-Erling Smørgrav  make -j 2
267*5afab0e5SDag-Erling Smørgrav  make install
268*5afab0e5SDag-Erling Smørgrav```
269*5afab0e5SDag-Erling Smørgrav
270*5afab0e5SDag-Erling SmørgravTravis only smoke tests an iOS build using a compile, link and install. The self tests are not run. TODO: figure out how to fire up an simulator, push the tests to the device and run them.
271*5afab0e5SDag-Erling Smørgrav
272*5afab0e5SDag-Erling Smørgrav### iOS flags
273*5afab0e5SDag-Erling Smørgrav
274*5afab0e5SDag-Erling Smørgrav`contrib/ios/setenv_ios.sh` uses specific flags for `CFLAGS` and `CXXFLAGS`. They are taken from Xcode, so we consider them the official flag set. It is important to use the same flags across projects to avoid subtle problems due to mixing and matching different flags.
275