David Benjamin | 95aaf4a | 2015-09-03 12:09:36 -0400 | [diff] [blame] | 1 | # Building BoringSSL |
| 2 | |
| 3 | ## Build Prerequisites |
| 4 | |
Brian Smith | 953cfc8 | 2015-10-06 12:51:38 -1000 | [diff] [blame] | 5 | * [CMake](http://www.cmake.org/download/) 2.8.8 or later is required. |
David Benjamin | 95aaf4a | 2015-09-03 12:09:36 -0400 | [diff] [blame] | 6 | |
Brian Smith | 953cfc8 | 2015-10-06 12:51:38 -1000 | [diff] [blame] | 7 | * 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 Benjamin | 95aaf4a | 2015-09-03 12:09:36 -0400 | [diff] [blame] | 11 | |
Brian Smith | 953cfc8 | 2015-10-06 12:51:38 -1000 | [diff] [blame] | 12 | * 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 Benjamin | 95aaf4a | 2015-09-03 12:09:36 -0400 | [diff] [blame] | 15 | |
| 16 | * If you need to build Ninja from source, then a recent version of |
Brian Smith | 953cfc8 | 2015-10-06 12:51:38 -1000 | [diff] [blame] | 17 | [Python](https://www.python.org/downloads/) is required (Python 2.7.5 works). |
David Benjamin | 95aaf4a | 2015-09-03 12:09:36 -0400 | [diff] [blame] | 18 | |
Brian Smith | 953cfc8 | 2015-10-06 12:51:38 -1000 | [diff] [blame] | 19 | * 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 Benjamin | 95aaf4a | 2015-09-03 12:09:36 -0400 | [diff] [blame] | 22 | |
| 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 Smith | 953cfc8 | 2015-10-06 12:51:38 -1000 | [diff] [blame] | 27 | * [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 Langley | dff504d | 2015-10-28 16:35:08 -0700 | [diff] [blame] | 30 | * If you change crypto/chacha/chacha\_vec.c, you will need the |
Brian Smith | 953cfc8 | 2015-10-06 12:51:38 -1000 | [diff] [blame] | 31 | arm-linux-gnueabihf-gcc compiler: |
| 32 | |
| 33 | ``` |
Adam Langley | dff504d | 2015-10-28 16:35:08 -0700 | [diff] [blame] | 34 | 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 Smith | 953cfc8 | 2015-10-06 12:51:38 -1000 | [diff] [blame] | 38 | ``` |
David Benjamin | 95aaf4a | 2015-09-03 12:09:36 -0400 | [diff] [blame] | 39 | |
| 40 | ## Building |
| 41 | |
| 42 | Using Ninja (note the 'N' is capitalized in the cmake invocation): |
| 43 | |
| 44 | mkdir build |
| 45 | cd build |
| 46 | cmake -GNinja .. |
| 47 | ninja |
| 48 | |
| 49 | Using Make (does not work on Windows): |
| 50 | |
| 51 | mkdir build |
| 52 | cd build |
| 53 | cmake .. |
| 54 | make |
| 55 | |
| 56 | You usually don't need to run `cmake` again after changing `CMakeLists.txt` |
| 57 | files because the build scripts will detect changes to them and rebuild |
| 58 | themselves automatically. |
| 59 | |
| 60 | Note that the default build flags in the top-level `CMakeLists.txt` are for |
| 61 | debugging—optimisation isn't enabled. |
| 62 | |
| 63 | If you want to cross-compile then there is an example toolchain file for 32-bit |
| 64 | Intel in `util/`. Wipe out the build directory, recreate it and run `cmake` like |
| 65 | this: |
| 66 | |
| 67 | cmake -DCMAKE_TOOLCHAIN_FILE=../util/32-bit-toolchain.cmake -GNinja .. |
| 68 | |
| 69 | If you want to build as a shared library, pass `-DBUILD_SHARED_LIBS=1`. On |
| 70 | Windows, where functions need to be tagged with `dllimport` when coming from a |
| 71 | shared library, define `BORINGSSL_SHARED_LIBRARY` in any code which `#include`s |
| 72 | the BoringSSL headers. |
| 73 | |
Adam Langley | 2e3c978 | 2015-10-27 08:47:11 -0700 | [diff] [blame] | 74 | In order to serve environments where code-size is important as well as those |
| 75 | where performance is the overriding concern, `OPENSSL_SMALL` can be defined to |
| 76 | remove some code that is especially large. |
| 77 | |
David Benjamin | 95aaf4a | 2015-09-03 12:09:36 -0400 | [diff] [blame] | 78 | ### Building for Android |
| 79 | |
| 80 | It's possible to build BoringSSL with the Android NDK using CMake. This has |
| 81 | been tested with version 10d of the NDK. |
| 82 | |
| 83 | Unpack the Android NDK somewhere and export `ANDROID_NDK` to point to the |
| 84 | directory. Clone https://github.com/taka-no-me/android-cmake into `util/`. Then |
| 85 | make 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 | |
| 93 | Once you've run that twice, Ninja should produce Android-compatible binaries. |
| 94 | You can replace `armeabi-v7a` in the above with `arm64-v8a` to build aarch64 |
| 95 | binaries. |
| 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 Langley | 6a7cfbe | 2015-10-16 15:46:46 -0700 | [diff] [blame] | 111 | ## Embedded ARM |
| 112 | |
| 113 | ARM, unlike Intel, does not have an instruction that allows applications to |
| 114 | discover the capabilities of the processor. Instead, the capability information |
| 115 | has to be provided by the operating system somehow. |
| 116 | |
| 117 | BoringSSL will try to use `getauxval` to discover the capabilities and, failing |
| 118 | that, will probe for NEON support by executing a NEON instruction and handling |
| 119 | any illegal-instruction signal. But some environments don't support that sort |
| 120 | of thing and, for them, it's possible to configure the CPU capabilities |
| 121 | at compile time. |
| 122 | |
| 123 | If you define `OPENSSL_STATIC_ARMCAP` then you can define any of the following |
| 124 | to 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 | |
| 132 | Note that if a feature is enabled in this way, but not actually supported at |
| 133 | run-time, BoringSSL will likely crash. |
| 134 | |
Adam Langley | dc7e9c4 | 2015-09-29 15:21:04 -0700 | [diff] [blame] | 135 | # Running tests |
| 136 | |
| 137 | There are two sets of tests: the C/C++ tests and the blackbox tests. For former |
| 138 | are built by Ninja and can be run from the top-level directory with `go run |
| 139 | util/all_tests.go`. The latter have to be run separately by running `go test` |
| 140 | from within `ssl/test/runner`. |
| 141 | |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 142 | Both sets of tests may also be run with `ninja -C build run_tests`, but CMake |
| 143 | 3.2 or later is required to avoid Ninja's output buffering. |