blob: 02f8f11f38f0c6d8924cb731714e5abe915764c5 [file] [log] [blame] [view]
David Benjamin95aaf4a2015-09-03 12:09:36 -04001# Building BoringSSL
2
3## Build Prerequisites
4
Brian Smith953cfc82015-10-06 12:51:38 -10005 * [CMake](http://www.cmake.org/download/) 2.8.8 or later is required.
David Benjamin95aaf4a2015-09-03 12:09:36 -04006
Brian Smith953cfc82015-10-06 12:51:38 -10007 * Perl 5.6.1 or later is required. On Windows,
8 [Strawberry Perl](http://strawberryperl.com/) and MSYS Perl have both been
9 reported to work. If not found by CMake, it may be configured explicitly by
10 setting `PERL_EXECUTABLE`.
David Benjamin95aaf4a2015-09-03 12:09:36 -040011
Brian Smith953cfc82015-10-06 12:51:38 -100012 * On Windows you currently must use [Ninja](https://martine.github.io/ninja/)
13 to build; on other platforms, it is not required, but recommended, because
14 it makes builds faster.
David Benjamin95aaf4a2015-09-03 12:09:36 -040015
16 * If you need to build Ninja from source, then a recent version of
Brian Smith953cfc82015-10-06 12:51:38 -100017 [Python](https://www.python.org/downloads/) is required (Python 2.7.5 works).
David Benjamin95aaf4a2015-09-03 12:09:36 -040018
Brian Smith953cfc82015-10-06 12:51:38 -100019 * On Windows only, [Yasm](http://yasm.tortall.net/) is required. If not found
20 by CMake, it may be configured explicitly by setting
21 `CMAKE_ASM_NASM_COMPILER`.
David Benjamin95aaf4a2015-09-03 12:09:36 -040022
23 * A C compiler is required. On Windows, MSVC 12 (Visual Studio 2013) or later
24 with Platform SDK 8.1 or later are supported. Recent versions of GCC and
25 Clang should work on non-Windows platforms, and maybe on Windows too.
26
Brian Smith953cfc82015-10-06 12:51:38 -100027 * [Go](https://golang.org/dl/) is required. If not found by CMake, the go
28 executable may be configured explicitly by setting `GO_EXECUTABLE`.
29
Adam Langleydff504d2015-10-28 16:35:08 -070030 * If you change crypto/chacha/chacha\_vec.c, you will need the
Brian Smith953cfc82015-10-06 12:51:38 -100031 arm-linux-gnueabihf-gcc compiler:
32
33 ```
Adam Langleydff504d2015-10-28 16:35:08 -070034 wget https://releases.linaro.org/14.11/components/toolchain/binaries/arm-linux-gnueabihf/gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf.tar.xz && \
35 echo bc4ca2ced084d2dc12424815a4442e19cb1422db87068830305d90075feb1a3b gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf.tar.xz | sha256sum -c && \
36 tar xf gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf.tar.xz && \
37 sudo mv gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf /opt/
Brian Smith953cfc82015-10-06 12:51:38 -100038 ```
David Benjamin95aaf4a2015-09-03 12:09:36 -040039
40## Building
41
42Using Ninja (note the 'N' is capitalized in the cmake invocation):
43
44 mkdir build
45 cd build
46 cmake -GNinja ..
47 ninja
48
49Using Make (does not work on Windows):
50
51 mkdir build
52 cd build
53 cmake ..
54 make
55
56You usually don't need to run `cmake` again after changing `CMakeLists.txt`
57files because the build scripts will detect changes to them and rebuild
58themselves automatically.
59
60Note that the default build flags in the top-level `CMakeLists.txt` are for
61debugging—optimisation isn't enabled.
62
63If you want to cross-compile then there is an example toolchain file for 32-bit
64Intel in `util/`. Wipe out the build directory, recreate it and run `cmake` like
65this:
66
67 cmake -DCMAKE_TOOLCHAIN_FILE=../util/32-bit-toolchain.cmake -GNinja ..
68
69If you want to build as a shared library, pass `-DBUILD_SHARED_LIBS=1`. On
70Windows, where functions need to be tagged with `dllimport` when coming from a
71shared library, define `BORINGSSL_SHARED_LIBRARY` in any code which `#include`s
72the BoringSSL headers.
73
Adam Langley2e3c9782015-10-27 08:47:11 -070074In order to serve environments where code-size is important as well as those
75where performance is the overriding concern, `OPENSSL_SMALL` can be defined to
76remove some code that is especially large.
77
David Benjamin95aaf4a2015-09-03 12:09:36 -040078### Building for Android
79
80It's possible to build BoringSSL with the Android NDK using CMake. This has
81been tested with version 10d of the NDK.
82
83Unpack the Android NDK somewhere and export `ANDROID_NDK` to point to the
84directory. Clone https://github.com/taka-no-me/android-cmake into `util/`. Then
85make a build directory as above and run CMake *twice* like this:
86
87 cmake -DANDROID_NATIVE_API_LEVEL=android-9 \
88 -DANDROID_ABI=armeabi-v7a \
89 -DCMAKE_TOOLCHAIN_FILE=../util/android-cmake/android.toolchain.cmake \
90 -DANDROID_NATIVE_API_LEVEL=16 \
91 -GNinja ..
92
93Once you've run that twice, Ninja should produce Android-compatible binaries.
94You can replace `armeabi-v7a` in the above with `arm64-v8a` to build aarch64
95binaries.
96
97## Known Limitations on Windows
98
99 * Versions of CMake since 3.0.2 have a bug in its Ninja generator that causes
100 yasm to output warnings
101
102 yasm: warning: can open only one input file, only the last file will be processed
103
104 These warnings can be safely ignored. The cmake bug is
105 http://www.cmake.org/Bug/view.php?id=15253.
106
107 * CMake can generate Visual Studio projects, but the generated project files
108 don't have steps for assembling the assembly language source files, so they
109 currently cannot be used to build BoringSSL.
110
Adam Langley6a7cfbe2015-10-16 15:46:46 -0700111## Embedded ARM
112
113ARM, unlike Intel, does not have an instruction that allows applications to
114discover the capabilities of the processor. Instead, the capability information
115has to be provided by the operating system somehow.
116
117BoringSSL will try to use `getauxval` to discover the capabilities and, failing
118that, will probe for NEON support by executing a NEON instruction and handling
119any illegal-instruction signal. But some environments don't support that sort
120of thing and, for them, it's possible to configure the CPU capabilities
121at compile time.
122
123If you define `OPENSSL_STATIC_ARMCAP` then you can define any of the following
124to enabling the corresponding ARM feature.
125
126 * `OPENSSL_STATIC_ARMCAP_NEON` or `__ARM_NEON__` (note that the latter is set by compilers when NEON support is enabled).
127 * `OPENSSL_STATIC_ARMCAP_AES`
128 * `OPENSSL_STATIC_ARMCAP_SHA1`
129 * `OPENSSL_STATIC_ARMCAP_SHA256`
130 * `OPENSSL_STATIC_ARMCAP_PMULL`
131
132Note that if a feature is enabled in this way, but not actually supported at
133run-time, BoringSSL will likely crash.
134
Adam Langleydc7e9c42015-09-29 15:21:04 -0700135# Running tests
136
137There are two sets of tests: the C/C++ tests and the blackbox tests. For former
138are built by Ninja and can be run from the top-level directory with `go run
139util/all_tests.go`. The latter have to be run separately by running `go test`
140from within `ssl/test/runner`.
141
David Benjamin301afaf2015-10-14 21:34:40 -0400142Both sets of tests may also be run with `ninja -C build run_tests`, but CMake
1433.2 or later is required to avoid Ninja's output buffering.