blob: 3a2eae88d60da6d8701097f5b169d9fe27026140 [file] [log] [blame] [view]
David Benjamin95aaf4a2015-09-03 12:09:36 -04001# Building BoringSSL
2
3## Build Prerequisites
4
David Benjamin96628432017-01-19 19:05:47 -05005 * [CMake](https://cmake.org/download/) 2.8.11 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,
nmittler042e8f72016-02-09 11:25:52 -08008 [Active State Perl](http://www.activestate.com/activeperl/) has been
9 reported to work, as has MSYS Perl.
10 [Strawberry Perl](http://strawberryperl.com/) also works but it adds GCC
11 to `PATH`, which can confuse some build tools when identifying the compiler
12 (removing `C:\Strawberry\c\bin` from `PATH` should resolve any problems).
13 If Perl is not found by CMake, it may be configured explicitly by setting
14 `PERL_EXECUTABLE`.
David Benjamin95aaf4a2015-09-03 12:09:36 -040015
David Benjamin2c71ce12016-02-05 22:08:45 -050016 * On Windows you currently must use [Ninja](https://ninja-build.org/)
Brian Smith953cfc82015-10-06 12:51:38 -100017 to build; on other platforms, it is not required, but recommended, because
18 it makes builds faster.
David Benjamin95aaf4a2015-09-03 12:09:36 -040019
20 * If you need to build Ninja from source, then a recent version of
Brian Smith953cfc82015-10-06 12:51:38 -100021 [Python](https://www.python.org/downloads/) is required (Python 2.7.5 works).
David Benjamin95aaf4a2015-09-03 12:09:36 -040022
Brian Smith953cfc82015-10-06 12:51:38 -100023 * On Windows only, [Yasm](http://yasm.tortall.net/) is required. If not found
24 by CMake, it may be configured explicitly by setting
25 `CMAKE_ASM_NASM_COMPILER`.
David Benjamin95aaf4a2015-09-03 12:09:36 -040026
David Benjaminbbe6af02016-04-29 14:15:39 -040027 * A C compiler is required. On Windows, MSVC 14 (Visual Studio 2015) or later
nmittler042e8f72016-02-09 11:25:52 -080028 with Platform SDK 8.1 or later are supported. Recent versions of GCC (4.8+)
29 and Clang should work on non-Windows platforms, and maybe on Windows too.
David Benjaminf6a74c62016-06-10 13:12:20 -040030 To build the tests, you also need a C++ compiler with C++11 support.
David Benjamin95aaf4a2015-09-03 12:09:36 -040031
Brian Smith953cfc82015-10-06 12:51:38 -100032 * [Go](https://golang.org/dl/) is required. If not found by CMake, the go
33 executable may be configured explicitly by setting `GO_EXECUTABLE`.
34
David Benjaminf6a74c62016-06-10 13:12:20 -040035 * To build the x86 and x86\_64 assembly, your assembler must support AVX2
Brian Smitha26d4c32016-03-01 21:17:37 -100036 instructions and MOVBE. If using GNU binutils, you must have 2.22 or later.
David Benjaminf6a74c62016-06-10 13:12:20 -040037
David Benjamin95aaf4a2015-09-03 12:09:36 -040038## Building
39
40Using Ninja (note the 'N' is capitalized in the cmake invocation):
41
42 mkdir build
43 cd build
44 cmake -GNinja ..
45 ninja
46
47Using Make (does not work on Windows):
48
49 mkdir build
50 cd build
51 cmake ..
52 make
53
54You usually don't need to run `cmake` again after changing `CMakeLists.txt`
55files because the build scripts will detect changes to them and rebuild
56themselves automatically.
57
58Note that the default build flags in the top-level `CMakeLists.txt` are for
nmittler042e8f72016-02-09 11:25:52 -080059debugging—optimisation isn't enabled. Pass `-DCMAKE_BUILD_TYPE=Release` to
60`cmake` to configure a release build.
David Benjamin95aaf4a2015-09-03 12:09:36 -040061
62If you want to cross-compile then there is an example toolchain file for 32-bit
63Intel in `util/`. Wipe out the build directory, recreate it and run `cmake` like
64this:
65
66 cmake -DCMAKE_TOOLCHAIN_FILE=../util/32-bit-toolchain.cmake -GNinja ..
67
68If you want to build as a shared library, pass `-DBUILD_SHARED_LIBS=1`. On
69Windows, where functions need to be tagged with `dllimport` when coming from a
70shared library, define `BORINGSSL_SHARED_LIBRARY` in any code which `#include`s
71the BoringSSL headers.
72
Adam Langley2e3c9782015-10-27 08:47:11 -070073In order to serve environments where code-size is important as well as those
74where performance is the overriding concern, `OPENSSL_SMALL` can be defined to
75remove some code that is especially large.
76
nmittler042e8f72016-02-09 11:25:52 -080077See [CMake's documentation](https://cmake.org/cmake/help/v3.4/manual/cmake-variables.7.html)
78for other variables which may be used to configure the build.
79
David Benjamin95aaf4a2015-09-03 12:09:36 -040080### Building for Android
81
82It's possible to build BoringSSL with the Android NDK using CMake. This has
83been tested with version 10d of the NDK.
84
85Unpack the Android NDK somewhere and export `ANDROID_NDK` to point to the
David Benjamin75021b72016-04-28 14:51:36 -040086directory. Then make a build directory as above and run CMake like this:
David Benjamin95aaf4a2015-09-03 12:09:36 -040087
David Benjamin75021b72016-04-28 14:51:36 -040088 cmake -DANDROID_ABI=armeabi-v7a \
89 -DCMAKE_TOOLCHAIN_FILE=../third_party/android-cmake/android.toolchain.cmake \
David Benjamin95aaf4a2015-09-03 12:09:36 -040090 -DANDROID_NATIVE_API_LEVEL=16 \
91 -GNinja ..
92
David Benjamin75021b72016-04-28 14:51:36 -040093Once you've run that, Ninja should produce Android-compatible binaries. You
94can replace `armeabi-v7a` in the above with `arm64-v8a` and use API level 21 or
95higher to build aarch64 binaries.
96
97For other options, see [android-cmake's documentation](./third_party/android-cmake/README.md).
David Benjamin95aaf4a2015-09-03 12:09:36 -040098
David Benjaminaff72a32017-04-06 23:26:04 -040099### Building for iOS
100
101To build for iOS, pass `-DCMAKE_OSX_SYSROOT=iphoneos` and
102`-DCMAKE_OSX_ARCHITECTURES=ARCH` to CMake, where `ARCH` is the desired
103architecture, matching values used in the `-arch` flag in Apple's toolchain.
104
105Passing multiple architectures for a multiple-architecture build is not
106supported.
107
David Benjamin95aaf4a2015-09-03 12:09:36 -0400108## Known Limitations on Windows
109
110 * Versions of CMake since 3.0.2 have a bug in its Ninja generator that causes
111 yasm to output warnings
112
113 yasm: warning: can open only one input file, only the last file will be processed
114
115 These warnings can be safely ignored. The cmake bug is
116 http://www.cmake.org/Bug/view.php?id=15253.
117
118 * CMake can generate Visual Studio projects, but the generated project files
119 don't have steps for assembling the assembly language source files, so they
120 currently cannot be used to build BoringSSL.
121
Adam Langley6a7cfbe2015-10-16 15:46:46 -0700122## Embedded ARM
123
124ARM, unlike Intel, does not have an instruction that allows applications to
125discover the capabilities of the processor. Instead, the capability information
126has to be provided by the operating system somehow.
127
128BoringSSL will try to use `getauxval` to discover the capabilities and, failing
129that, will probe for NEON support by executing a NEON instruction and handling
130any illegal-instruction signal. But some environments don't support that sort
131of thing and, for them, it's possible to configure the CPU capabilities
132at compile time.
133
134If you define `OPENSSL_STATIC_ARMCAP` then you can define any of the following
135to enabling the corresponding ARM feature.
136
137 * `OPENSSL_STATIC_ARMCAP_NEON` or `__ARM_NEON__` (note that the latter is set by compilers when NEON support is enabled).
138 * `OPENSSL_STATIC_ARMCAP_AES`
139 * `OPENSSL_STATIC_ARMCAP_SHA1`
140 * `OPENSSL_STATIC_ARMCAP_SHA256`
141 * `OPENSSL_STATIC_ARMCAP_PMULL`
142
143Note that if a feature is enabled in this way, but not actually supported at
144run-time, BoringSSL will likely crash.
145
Adam Langley008f0812016-08-24 17:34:18 -0700146## Assembling ARMv8 with Clang
147
148In order to support the ARMv8 crypto instructions, Clang requires that the
149architecture be `armv8-a+crypto`. However, setting that as a general build flag
150would allow the compiler to assume that crypto instructions are *always*
151supported, even without testing for them.
152
153It's possible to set the architecture in an assembly file using the `.arch`
154directive, but only very recent versions of Clang support this. If
155`BORINGSSL_CLANG_SUPPORTS_DOT_ARCH` is defined then `.arch` directives will be
156used with Clang, otherwise you may need to craft acceptable assembler flags.
157
Adam Langleydc7e9c42015-09-29 15:21:04 -0700158# Running tests
159
160There are two sets of tests: the C/C++ tests and the blackbox tests. For former
161are built by Ninja and can be run from the top-level directory with `go run
162util/all_tests.go`. The latter have to be run separately by running `go test`
163from within `ssl/test/runner`.
164
David Benjamin301afaf2015-10-14 21:34:40 -0400165Both sets of tests may also be run with `ninja -C build run_tests`, but CMake
1663.2 or later is required to avoid Ninja's output buffering.