2015-09-03 17:09:36 +01:00
|
|
|
# Building BoringSSL
|
|
|
|
|
|
|
|
## Build Prerequisites
|
|
|
|
|
Do a cursory conversion of a few tests to GTest.
For now, this is the laziest conversion possible. The intent is to just
get the build setup ready so that we can get everything working in our
consumers. The intended end state is:
- The standalone build produces three test targets, one per library:
{crypto,ssl,decrepit}_tests.
- Each FOO_test is made up of:
FOO/**/*_test.cc
crypto/test/gtest_main.cc
test_support
- generate_build_files.py emits variables crypto_test_sources and
ssl_test_sources. These variables are populated with FindCFiles,
looking for *_test.cc.
- The consuming file assembles those variables into the two test targets
(plus decrepit) from there. This avoids having generate_build_files.py
emit actual build rules.
- Our standalone builders, Chromium, and Android just run the top-level
test targets using whatever GTest-based reporting story they have.
In transition, we start by converting one of two tests in each library
to populate the three test targets. Those are added to all_tests.json
and all_tests.go hacked to handle them transparently. This keeps our
standalone builder working.
generate_build_files.py, to start with, populates the new source lists
manually and subtracts them out of the old machinery. We emit both for
the time being. When this change rolls in, we'll write all the build
glue needed to build the GTest-based tests and add it to consumers'
continuous builders.
Next, we'll subsume a file-based test and get the consumers working with
that. (I.e. make sure the GTest targets can depend on a data file.)
Once that's all done, we'll be sure all this will work. At that point,
we start subsuming the remaining tests into the GTest targets and,
asynchronously, rewriting tests to use GTest properly rather than
cursory conversion here.
When all non-GTest tests are gone, the old generate_build_files.py hooks
will be removed, consumers updated to not depend on them, and standalone
builders converted to not rely on all_tests.go, which can then be
removed. (Unless bits end up being needed as a malloc test driver. I'm
thinking we'll want to do something with --gtest_filter.)
As part of this CL, I've bumped the CMake requirements (for
target_include_directories) and added a few suppressions for warnings
that GTest doesn't pass.
BUG=129
Change-Id: I881b26b07a8739cc0b52dbb51a30956908e1b71a
Reviewed-on: https://boringssl-review.googlesource.com/13232
Reviewed-by: Adam Langley <agl@google.com>
2017-01-20 00:05:47 +00:00
|
|
|
* [CMake](https://cmake.org/download/) 2.8.11 or later is required.
|
2015-09-03 17:09:36 +01:00
|
|
|
|
2015-10-06 23:51:38 +01:00
|
|
|
* Perl 5.6.1 or later is required. On Windows,
|
2016-02-09 19:25:52 +00:00
|
|
|
[Active State Perl](http://www.activestate.com/activeperl/) has been
|
|
|
|
reported to work, as has MSYS Perl.
|
|
|
|
[Strawberry Perl](http://strawberryperl.com/) also works but it adds GCC
|
|
|
|
to `PATH`, which can confuse some build tools when identifying the compiler
|
|
|
|
(removing `C:\Strawberry\c\bin` from `PATH` should resolve any problems).
|
|
|
|
If Perl is not found by CMake, it may be configured explicitly by setting
|
|
|
|
`PERL_EXECUTABLE`.
|
2015-09-03 17:09:36 +01:00
|
|
|
|
2016-02-06 03:08:45 +00:00
|
|
|
* On Windows you currently must use [Ninja](https://ninja-build.org/)
|
2015-10-06 23:51:38 +01:00
|
|
|
to build; on other platforms, it is not required, but recommended, because
|
|
|
|
it makes builds faster.
|
2015-09-03 17:09:36 +01:00
|
|
|
|
|
|
|
* If you need to build Ninja from source, then a recent version of
|
2015-10-06 23:51:38 +01:00
|
|
|
[Python](https://www.python.org/downloads/) is required (Python 2.7.5 works).
|
2015-09-03 17:09:36 +01:00
|
|
|
|
2015-10-06 23:51:38 +01:00
|
|
|
* On Windows only, [Yasm](http://yasm.tortall.net/) is required. If not found
|
|
|
|
by CMake, it may be configured explicitly by setting
|
|
|
|
`CMAKE_ASM_NASM_COMPILER`.
|
2015-09-03 17:09:36 +01:00
|
|
|
|
2016-04-29 19:15:39 +01:00
|
|
|
* A C compiler is required. On Windows, MSVC 14 (Visual Studio 2015) or later
|
2016-02-09 19:25:52 +00:00
|
|
|
with Platform SDK 8.1 or later are supported. Recent versions of GCC (4.8+)
|
|
|
|
and Clang should work on non-Windows platforms, and maybe on Windows too.
|
2016-06-10 18:12:20 +01:00
|
|
|
To build the tests, you also need a C++ compiler with C++11 support.
|
2015-09-03 17:09:36 +01:00
|
|
|
|
2015-10-06 23:51:38 +01:00
|
|
|
* [Go](https://golang.org/dl/) is required. If not found by CMake, the go
|
|
|
|
executable may be configured explicitly by setting `GO_EXECUTABLE`.
|
|
|
|
|
2016-06-10 18:12:20 +01:00
|
|
|
* To build the x86 and x86\_64 assembly, your assembler must support AVX2
|
2016-03-02 07:17:37 +00:00
|
|
|
instructions and MOVBE. If using GNU binutils, you must have 2.22 or later.
|
2016-06-10 18:12:20 +01:00
|
|
|
|
2015-09-03 17:09:36 +01:00
|
|
|
## Building
|
|
|
|
|
|
|
|
Using Ninja (note the 'N' is capitalized in the cmake invocation):
|
|
|
|
|
|
|
|
mkdir build
|
|
|
|
cd build
|
|
|
|
cmake -GNinja ..
|
|
|
|
ninja
|
|
|
|
|
|
|
|
Using Make (does not work on Windows):
|
|
|
|
|
|
|
|
mkdir build
|
|
|
|
cd build
|
|
|
|
cmake ..
|
|
|
|
make
|
|
|
|
|
|
|
|
You usually don't need to run `cmake` again after changing `CMakeLists.txt`
|
|
|
|
files because the build scripts will detect changes to them and rebuild
|
|
|
|
themselves automatically.
|
|
|
|
|
|
|
|
Note that the default build flags in the top-level `CMakeLists.txt` are for
|
2016-02-09 19:25:52 +00:00
|
|
|
debugging—optimisation isn't enabled. Pass `-DCMAKE_BUILD_TYPE=Release` to
|
|
|
|
`cmake` to configure a release build.
|
2015-09-03 17:09:36 +01:00
|
|
|
|
|
|
|
If you want to cross-compile then there is an example toolchain file for 32-bit
|
|
|
|
Intel in `util/`. Wipe out the build directory, recreate it and run `cmake` like
|
|
|
|
this:
|
|
|
|
|
|
|
|
cmake -DCMAKE_TOOLCHAIN_FILE=../util/32-bit-toolchain.cmake -GNinja ..
|
|
|
|
|
|
|
|
If you want to build as a shared library, pass `-DBUILD_SHARED_LIBS=1`. On
|
|
|
|
Windows, where functions need to be tagged with `dllimport` when coming from a
|
|
|
|
shared library, define `BORINGSSL_SHARED_LIBRARY` in any code which `#include`s
|
|
|
|
the BoringSSL headers.
|
|
|
|
|
2015-10-27 15:47:11 +00:00
|
|
|
In order to serve environments where code-size is important as well as those
|
|
|
|
where performance is the overriding concern, `OPENSSL_SMALL` can be defined to
|
|
|
|
remove some code that is especially large.
|
|
|
|
|
2016-02-09 19:25:52 +00:00
|
|
|
See [CMake's documentation](https://cmake.org/cmake/help/v3.4/manual/cmake-variables.7.html)
|
|
|
|
for other variables which may be used to configure the build.
|
|
|
|
|
2015-09-03 17:09:36 +01:00
|
|
|
### Building for Android
|
|
|
|
|
|
|
|
It's possible to build BoringSSL with the Android NDK using CMake. This has
|
|
|
|
been tested with version 10d of the NDK.
|
|
|
|
|
|
|
|
Unpack the Android NDK somewhere and export `ANDROID_NDK` to point to the
|
2016-04-28 19:51:36 +01:00
|
|
|
directory. Then make a build directory as above and run CMake like this:
|
2015-09-03 17:09:36 +01:00
|
|
|
|
2016-04-28 19:51:36 +01:00
|
|
|
cmake -DANDROID_ABI=armeabi-v7a \
|
|
|
|
-DCMAKE_TOOLCHAIN_FILE=../third_party/android-cmake/android.toolchain.cmake \
|
2015-09-03 17:09:36 +01:00
|
|
|
-DANDROID_NATIVE_API_LEVEL=16 \
|
|
|
|
-GNinja ..
|
|
|
|
|
2016-04-28 19:51:36 +01:00
|
|
|
Once you've run that, Ninja should produce Android-compatible binaries. You
|
|
|
|
can replace `armeabi-v7a` in the above with `arm64-v8a` and use API level 21 or
|
|
|
|
higher to build aarch64 binaries.
|
|
|
|
|
|
|
|
For other options, see [android-cmake's documentation](./third_party/android-cmake/README.md).
|
2015-09-03 17:09:36 +01:00
|
|
|
|
2017-04-07 04:26:04 +01:00
|
|
|
### Building for iOS
|
|
|
|
|
|
|
|
To build for iOS, pass `-DCMAKE_OSX_SYSROOT=iphoneos` and
|
|
|
|
`-DCMAKE_OSX_ARCHITECTURES=ARCH` to CMake, where `ARCH` is the desired
|
|
|
|
architecture, matching values used in the `-arch` flag in Apple's toolchain.
|
|
|
|
|
|
|
|
Passing multiple architectures for a multiple-architecture build is not
|
|
|
|
supported.
|
|
|
|
|
2015-09-03 17:09:36 +01:00
|
|
|
## Known Limitations on Windows
|
|
|
|
|
|
|
|
* Versions of CMake since 3.0.2 have a bug in its Ninja generator that causes
|
|
|
|
yasm to output warnings
|
|
|
|
|
|
|
|
yasm: warning: can open only one input file, only the last file will be processed
|
|
|
|
|
|
|
|
These warnings can be safely ignored. The cmake bug is
|
|
|
|
http://www.cmake.org/Bug/view.php?id=15253.
|
|
|
|
|
|
|
|
* CMake can generate Visual Studio projects, but the generated project files
|
|
|
|
don't have steps for assembling the assembly language source files, so they
|
|
|
|
currently cannot be used to build BoringSSL.
|
|
|
|
|
2015-10-16 23:46:46 +01:00
|
|
|
## Embedded ARM
|
|
|
|
|
|
|
|
ARM, unlike Intel, does not have an instruction that allows applications to
|
|
|
|
discover the capabilities of the processor. Instead, the capability information
|
|
|
|
has to be provided by the operating system somehow.
|
|
|
|
|
2017-06-08 21:53:28 +01:00
|
|
|
By default, on Linux-based systems, BoringSSL will try to use `getauxval` and
|
|
|
|
`/proc` to discover the capabilities. But some environments don't support that
|
|
|
|
sort of thing and, for them, it's possible to configure the CPU capabilities at
|
|
|
|
compile time.
|
|
|
|
|
|
|
|
On iOS or builds which define `OPENSSL_STATIC_ARMCAP`, features will be
|
|
|
|
determined based on the `__ARM_NEON__` and `__ARM_FEATURE_CRYPTO` preprocessor
|
|
|
|
symbols reported by the compiler. These values are usually controlled by the
|
|
|
|
`-march` flag. You can also define any of the following to enable the
|
|
|
|
corresponding ARM feature.
|
|
|
|
|
|
|
|
* `OPENSSL_STATIC_ARMCAP_NEON`
|
2015-10-16 23:46:46 +01:00
|
|
|
* `OPENSSL_STATIC_ARMCAP_AES`
|
|
|
|
* `OPENSSL_STATIC_ARMCAP_SHA1`
|
|
|
|
* `OPENSSL_STATIC_ARMCAP_SHA256`
|
|
|
|
* `OPENSSL_STATIC_ARMCAP_PMULL`
|
|
|
|
|
|
|
|
Note that if a feature is enabled in this way, but not actually supported at
|
|
|
|
run-time, BoringSSL will likely crash.
|
|
|
|
|
2016-08-25 01:34:18 +01:00
|
|
|
## Assembling ARMv8 with Clang
|
|
|
|
|
|
|
|
In order to support the ARMv8 crypto instructions, Clang requires that the
|
|
|
|
architecture be `armv8-a+crypto`. However, setting that as a general build flag
|
|
|
|
would allow the compiler to assume that crypto instructions are *always*
|
|
|
|
supported, even without testing for them.
|
|
|
|
|
|
|
|
It's possible to set the architecture in an assembly file using the `.arch`
|
|
|
|
directive, but only very recent versions of Clang support this. If
|
|
|
|
`BORINGSSL_CLANG_SUPPORTS_DOT_ARCH` is defined then `.arch` directives will be
|
|
|
|
used with Clang, otherwise you may need to craft acceptable assembler flags.
|
|
|
|
|
2015-09-29 23:21:04 +01:00
|
|
|
# Running tests
|
|
|
|
|
|
|
|
There are two sets of tests: the C/C++ tests and the blackbox tests. For former
|
|
|
|
are built by Ninja and can be run from the top-level directory with `go run
|
|
|
|
util/all_tests.go`. The latter have to be run separately by running `go test`
|
|
|
|
from within `ssl/test/runner`.
|
|
|
|
|
Add a run_tests target to run all tests.
It's very annoying having to remember the right incant every time I want
to switch around between my build, build-release, build-asan, etc.,
output directories.
Unfortunately, this target is pretty unfriendly without CMake 3.2+ (and
Ninja 1.5+). This combination gives a USES_TERMINAL flag to
add_custom_target which uses Ninja's "console" pool, otherwise the
output buffering gets in the way. Ubuntu LTS is still on an older CMake,
so do a version check in the meantime.
CMake also has its own test mechanism (CTest), but this doesn't use it.
It seems to prefer knowing what all the tests are and then tries to do
its own output management and parallelizing and such. We already have
our own runners. all_tests.go could actually be converted tidily, but
generate_build_files.py also needs to read it, and runner.go has very
specific needs.
Naming the target ninja -C build test would be nice, but CTest squats
that name and CMake grumps when you use a reserved name, so I've gone
with run_tests.
Change-Id: Ibd20ebd50febe1b4e91bb19921f3bbbd9fbcf66c
Reviewed-on: https://boringssl-review.googlesource.com/6270
Reviewed-by: Adam Langley <alangley@gmail.com>
2015-10-15 02:34:40 +01:00
|
|
|
Both sets of tests may also be run with `ninja -C build run_tests`, but CMake
|
|
|
|
3.2 or later is required to avoid Ninja's output buffering.
|