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