• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
6## Which branch to use
7
8BoringSSL usage typically follows a
9["live at head"](https://abseil.io/about/philosophy#we-recommend-that-you-choose-to-live-at-head)
10model. Projects pin to whatever the current latest of BoringSSL is at the time
11of update, and regularly update it to pick up new changes.
12
13While the BoringSSL repository may contain project-specific branches, e.g.
14`chromium-2214`, those are _not_ supported release branches and must not as
15such. In rare cases, BoringSSL will temporarily maintain a short-lived branch on
16behalf of a project. Most such branches are no longer updated, because the
17corresponding project no longer needs them, and we do not create new ones to
18replace the ones that are no longer updated. E.g., not every Chromium release
19branch has a corresponding BoringSSL `chromium-*` branch. Even while active, the
20branch may not contain all changes relevant to a general BoringSSL consumer.
21
22## Bazel
23
24If you are using [Bazel](https://bazel.build) then you can incorporate
25BoringSSL as an external repository by using a commit from the
26`master-with-bazel` branch. That branch is maintained by a bot from `master`
27and includes the needed generated files and a top-level BUILD file.
28
29For example:
30
31    git_repository(
32        name = "boringssl",
33        commit = "_some commit_",
34        remote = "https://boringssl.googlesource.com/boringssl",
35    )
36
37You would still need to keep the referenced commit up to date if a specific
38commit is referred to.
39
40## Directory layout
41
42Typically projects create a `third_party/boringssl` directory to put
43BoringSSL-specific files into. The source code of BoringSSL itself goes into
44`third_party/boringssl/src`, either by copying or as a
45[submodule](https://git-scm.com/docs/git-submodule).
46
47It's generally a mistake to put BoringSSL's source code into
48`third_party/boringssl` directly because pre-built files and custom build files
49need to go somewhere and merging these with the BoringSSL source code makes
50updating things more complex.
51
52## Build support
53
54BoringSSL is designed to work with many different build systems. Currently,
55different projects use [GYP](https://gyp.gsrc.io/),
56[GN](https://gn.googlesource.com/gn/+/master/docs/quick_start.md),
57[Bazel](https://bazel.build/) and [Make](https://www.gnu.org/software/make/)  to
58build BoringSSL, without too much pain.
59
60The development build system is CMake and the CMake build knows how to
61automatically generate the intermediate files that BoringSSL needs. However,
62outside of the CMake environment, these intermediates are generated once and
63checked into the incorporating project's source repository. This avoids
64incorporating projects needing to support Perl and Go in their build systems.
65
66The script [`util/generate_build_files.py`](/util/generate_build_files.py)
67expects to be run from the `third_party/boringssl` directory and to find the
68BoringSSL source code in `src/`. You should pass it a single argument: the name
69of the build system that you're using. If you don't use any of the supported
70build systems then you should augment `generate_build_files.py` with support
71for it.
72
73The script will pregenerate the intermediate files (see
74[BUILDING.md](/BUILDING.md) for details about which tools will need to be
75installed) and output helper files for that build system. It doesn't generate a
76complete build script, just file and test lists, which change often. For
77example, see the
78[file](https://code.google.com/p/chromium/codesearch#chromium/src/third_party/boringssl/BUILD.generated.gni)
79and
80[test](https://code.google.com/p/chromium/codesearch#chromium/src/third_party/boringssl/BUILD.generated_tests.gni)
81lists generated for GN in Chromium.
82
83Generally one checks in these generated files alongside the hand-written build
84files. Periodically an engineer updates the BoringSSL revision, regenerates
85these files and checks in the updated result. As an example, see how this is
86done [in Chromium](https://code.google.com/p/chromium/codesearch#chromium/src/third_party/boringssl/).
87
88## Defines
89
90BoringSSL does not present a lot of configurability in order to reduce the
91number of configurations that need to be tested. But there are a couple of
92\#defines that you may wish to set:
93
94`OPENSSL_NO_ASM` prevents the use of assembly code (although it's up to you to
95ensure that the build system doesn't link it in if you wish to reduce binary
96size). This will have a significant performance impact but can be useful if you
97wish to use tools like
98[AddressSanitizer](http://clang.llvm.org/docs/AddressSanitizer.html) that
99interact poorly with assembly code.
100
101`OPENSSL_SMALL` removes some code that is especially large at some performance
102cost.
103
104## Symbols
105
106You cannot link multiple versions of BoringSSL or OpenSSL into a single binary
107without dealing with symbol conflicts. If you are statically linking multiple
108versions together, there's not a lot that can be done because C doesn't have a
109module system.
110
111If you are using multiple versions in a single binary, in different shared
112objects, ensure you build BoringSSL with `-fvisibility=hidden` and do not
113export any of BoringSSL's symbols. This will prevent any collisions with other
114verisons that may be included in other shared objects. Note that this requires
115that all callers of BoringSSL APIs live in the same shared object as BoringSSL.
116
117If you require that BoringSSL APIs be used across shared object boundaries,
118continue to build with `-fvisibility=hidden` but define
119`BORINGSSL_SHARED_LIBRARY` in both BoringSSL and consumers. BoringSSL's own
120source files (but *not* consumers' source files) must also build with
121`BORINGSSL_IMPLEMENTATION` defined. This will export BoringSSL's public symbols
122in the resulting shared object while hiding private symbols. However note that,
123as with a static link, this precludes dynamically linking with another version
124of BoringSSL or OpenSSL.
125