1# Incorporating BoringSSL into a project 2 3**Note**: if your target project is not a Google project then first read the 4[main README](./README.md) about the purpose of BoringSSL. 5 6If you are porting BoringSSL to a new platform see 7["go/boringssl-on-new-platform"](https://goto.corp.google.com/boringssl-on-new-platform) (Google 8Internal) for information about porting BoringSSL to a new platform for a Google 9project. 10 11## Which branch to use 12 13BoringSSL usage typically follows a 14["live at head"](https://abseil.io/about/philosophy#we-recommend-that-you-choose-to-live-at-head) 15model. Projects pin to whatever the current latest of BoringSSL is at the time 16of update, and regularly update it to pick up new changes. 17 18Some systems cannot consume git revisions and expect git tags. BoringSSL tags 19periodic snapshots as "releases", to meet the needs of those systems. These 20versions do not represent any kind of stability or development milestone. 21BoringSSL does not branch at these releases and will not cherry-pick bugfixes to 22them. Unless there is a technical constraint to use one of these revisions, 23projects should simply use the latest untagged revision when updating. 24 25While the BoringSSL repository may contain project-specific branches, e.g. 26`chromium-2214`, those are _not_ supported release branches and must not as 27such. In rare cases, BoringSSL will temporarily maintain a short-lived branch on 28behalf of a project. Most such branches are no longer updated, because the 29corresponding project no longer needs them, and we do not create new ones to 30replace the ones that are no longer updated. E.g., not every Chromium release 31branch has a corresponding BoringSSL `chromium-*` branch. Even while active, the 32branch may not contain all changes relevant to a general BoringSSL consumer. 33 34## Bazel 35 36If you are using [Bazel](https://bazel.build) then you can use the [boringssl 37module](https://registry.bazel.build/modules/boringssl) in the Bazel Central 38Registry with bzlmod. Look up the latest version and add the following to your 39`MODULE.bazel` file: 40 41 bazel_dep(name = "boringssl", version = "INSERT_VERSION_HERE") 42 43Substitute the latest version in for `INSERT_VERSION_HERE`. 44 45BoringSSL will periodically ship snapshots to Bazel Central Registry. As with 46other dependencies, periodically keep the referenced version up-to-date. 47 48## Directory layout 49 50Typically projects create a `third_party/boringssl` directory to put 51BoringSSL-specific files into. The source code of BoringSSL itself goes into 52`third_party/boringssl/src`, either by copying or as a 53[submodule](https://git-scm.com/docs/git-submodule). 54 55It's generally a mistake to put BoringSSL's source code into 56`third_party/boringssl` directly because custom build files need to go somewhere 57and merging these with the BoringSSL source code makes updating things more 58complex. 59 60## Build support 61 62BoringSSL is designed to work with many different build systems. The project 63currently has [CMake](https://cmake.org/) and [Bazel](https://bazel.build/) 64builds checked in. Other build systems, and embedders with custom build needs, 65are supported by separating the source list, maintained by BoringSSL, and the 66top-level build logic, maintained by the embedder. 67 68Source lists for various build systems are pre-generated and live in the `gen` 69directory. For example, source lists for 70[GN](https://gn.googlesource.com/gn/+/master/docs/quick_start.md) live in 71[gen/sources.gni](./gen/sources.gni). There is also a generic 72[gen/sources.json](./gen/sources.json) file for projects to consume if needed. 73[util/build/build.go](./util/build/build.go) describes what the various source 74lists mean. Most projects should concatenate the `bcm` and `crypto` targets. 75 76If you don't use any of the supported build systems, you should augment the 77[util/pregenerate](./util/pregenerate) tool to support it, or 78consume [gen/sources.json](./gen/sources.json). 79 80Historically, source lists were generated at update time with the 81[`util/generate_build_files.py`](./util/generate_build_files.py) script. We are 82in the process of transitioning builds to the pre-generated files, so that 83embedders do not need to run a custom script when updating BoringSSL. 84 85## Defines 86 87BoringSSL does not present a lot of configurability in order to reduce the 88number of configurations that need to be tested. But there are a couple of 89\#defines that you may wish to set: 90 91`OPENSSL_NO_ASM` prevents the use of assembly code (although it's up to you to 92ensure that the build system doesn't link it in if you wish to reduce binary 93size). This will have a significant performance impact but can be useful if you 94wish to use tools like 95[AddressSanitizer](http://clang.llvm.org/docs/AddressSanitizer.html) that 96interact poorly with assembly code. 97 98`OPENSSL_SMALL` removes some code that is especially large at some performance 99cost. 100 101## Symbols 102 103You cannot link multiple versions of BoringSSL or OpenSSL into a single binary 104without dealing with symbol conflicts. If you are statically linking multiple 105versions together, there's not a lot that can be done because C doesn't have a 106module system. 107 108If you are using multiple versions in a single binary, in different shared 109objects, ensure you build BoringSSL with `-fvisibility=hidden` and do not 110export any of BoringSSL's symbols. This will prevent any collisions with other 111verisons that may be included in other shared objects. Note that this requires 112that all callers of BoringSSL APIs live in the same shared object as BoringSSL. 113 114If you require that BoringSSL APIs be used across shared object boundaries, 115continue to build with `-fvisibility=hidden` but define 116`BORINGSSL_SHARED_LIBRARY` in both BoringSSL and consumers. BoringSSL's own 117source files (but *not* consumers' source files) must also build with 118`BORINGSSL_IMPLEMENTATION` defined. This will export BoringSSL's public symbols 119in the resulting shared object while hiding private symbols. However note that, 120as with a static link, this precludes dynamically linking with another version 121of BoringSSL or OpenSSL. 122