blob: ab88e05b996191cd8e107b3e8727f1c58ab18c70 [file] [log] [blame] [view]
zpeng8d6f584a2016-12-16 20:50:281# Adding third_party Libraries
2
3[TOC]
4
5Using third party code can save time and is consistent with our values - no need
6to reinvent the wheel! We put all code that isn't written by Chromium developers
Dirk Pranke568e95c2018-11-01 23:41:507into `//third_party` (even if you end up modifying just a few functions). We do
zpeng8d6f584a2016-12-16 20:50:288this to make it easy to track license compliance, security patches, and supply
9the right credit and attributions. It also makes it a lot easier for other
10projects that embed our code to track what is Chromium licensed and what is
11covered by other licenses.
12
Dirk Pranke568e95c2018-11-01 23:41:5013## Put the code in //third_party
zpeng8d6f584a2016-12-16 20:50:2814
Dirk Pranke568e95c2018-11-01 23:41:5015By default, all code should be checked into [//third_party](../third_party/),
16for the reasons given above. Other locations are only appropriate in a few
17situations and need explicit approval; don't assume that because there's some
18other directory with third_party in the name it's okay to put new things
19there.
zpeng8d6f584a2016-12-16 20:50:2820
Tim van der Lippe5870ac32019-10-18 11:46:5421## Before you start
22
23To make sure the inclusion of a new third_party project makes sense for the
Alex Mineer55764332022-02-25 18:05:1924Chromium project, you should first obtain
Yaron Friedmane34271392022-04-29 16:45:5325[Chrome Eng Review](../ENG_REVIEW_OWNERS) approval. Please include the following information in an
26email to chrome-eng-review@google.com:
27* Motivation of your project
28* Design docs
29* Additional checkout size
30* Build time increase
31* Binary size increase on Android ([official](https://www.chromium.org/developers/gn-build-configuration) builds)
32* Binary size increase on Windows
33
34Googlers can access [go/chrome-eng-review](https://goto.google.com/chrome-eng-review) and review
Alex Mineer55764332022-02-25 18:05:1935existing topics in g/chrome-eng-review, and can also come to office hours to ask
36questions.
37
Scott Violet50a02e42022-11-29 20:02:3438### Rust
39
40Rust is allowed for third-party libraries as long as there is a business need,
41which includes the following:
42
43* The Rust implementation is the best (e.g., speed, memory, lack of bugs) or
44only existing implementation available for the third-party library.
45* The Rust implementation allows the operation to move to a higher privileged
46process, and this benefits the product by improving on guardrail metrics (e.g.
47through avoiding process startup, IPC overheads, or C++ memory-unsafety
48mitigations).
49* The Rust implementation can meaningfully reduce our expected risk of
50(memory/crashes/undefined behavior) bugs, when compared to the existing
51third-party library and related C++ code required to use the library. We realize
52assessing risk is quite complex and very nuanced. If this is the criteria by
53which the third-party library is being added, chrome-eng-review@google.com and
54chrome-rust@google.com may ask for more data.
55
56Support for third-party libraries written in Rust is in active development. If
57the library you wish to add is in Rust, reach out to chrome-rust@google.com
58first.
59
Yaron Friedmane34271392022-04-29 16:45:5360### A note on size constraints
61
62The size of Chromium derived executables can impact overall performance of those binaries as they
63need to run on a wide range of devices including those with extremely limited RAM. Additionally, we
64have experience from Windows of the binary size impacting successful patch rate of updates as well
65as constraints from the Android Ecosystem where APKs included in the system image have hard
66limits on their size due to allocation size of the system partition. For more details and
67guidelines on size increases see
Michael Cui5d517752022-11-01 14:11:3268[//docs/speed/binary_size/binary_size_explainer.md](speed/binary_size/binary_size_explainer.md) and Googlers can
69additionally check [go/chrome-binary-size](https://goto.google.com/chrome-binary-size)
Tim van der Lippe5870ac32019-10-18 11:46:5470
Dirk Pranke568e95c2018-11-01 23:41:5071## Get the code
zpeng8d6f584a2016-12-16 20:50:2872
Dirk Pranke568e95c2018-11-01 23:41:5073There are two common ways to depend on third-party code: you can reference a
Jason D. Clintonb21e99b2021-09-30 19:19:5874Git repo directly (via entries in the DEPS file) or you can check in a
75snapshot. The former is preferable in most cases:
76
771. If you are actively developing in the upstream repo, then having the DEPS
78 file include the upstream (that's been mirrored to GoB, see below) can be a
79 way to include those changes into Chromium at a particular revision. The
80 DEPS file will be updated to a new revision when you are ready to "roll" the
81 new version into Chromium. This also avoids duplicate copies of the code
82 showing up in multiple repos leading to contributor confusion.
831. This interacts favorably with our upstream tracking automation. We
84 automatically consume the upstream Git hashes and match them against a
85 database of known upstreams to tracking drift between Chromium and upstream
86 sources.
871. This makes adding deps that don't need local changes easier. E.g. some of
88 our automation automatically converts non-GN build rules into GN build rules
89 without any additional CLs.
90
91Checking in a snapshot is useful if this is effectively taking on maintenance
92of an unmaintained project (e.g. an ancient library that we're going to GN-ify
93that hasn't been updated in years). And, of course, if the code you need isn't
94in a Git repo, then you have to snapshot.
zpeng8d6f584a2016-12-16 20:50:2895
Tim van der Lippe5870ac32019-10-18 11:46:5496### Node packages
97
98To include a Node package, add the dependency to the
99[Node package.json](../third_party/node/package.json). Make sure to update
100the corresponding [`npm_exclude.txt`](../third_party/node/npm_exclude.txt)
101and [`npm_include.txt`](../third_party/node/npm_include.txt) to make the code
102available during checkout.
103
Dirk Pranke568e95c2018-11-01 23:41:50104### Pulling the code via DEPS
105
106If the code is in a Git repo that you want to mirror, please file an [infra git
107ticket](https://bugs.chromium.org/p/chromium/issues/entry?template=Infra-Git)
108to get the repo mirrored onto chromium.googlesource.com; we don't allow direct
109dependencies on non-Google-hosted repositories, so that we can still build
Jason D. Clintonb21e99b2021-09-30 19:19:58110if an external repository goes down.
Dirk Pranke568e95c2018-11-01 23:41:50111
112Once the mirror is set up, add an entry to [//DEPS](../DEPS) so that gclient
113will pull it in. If the code is only needed on some platforms, add a condition
114to the deps entry so that developers on other platforms don't pull in things
115they don't need.
116
117As for specifying the path where the library is fetched, a path like
118`//third_party/<project_name>/src` is highly recommended so that you can put
119the file like OWNERS or README.chromium at `//third_party/<project_name>`. If
120you have a wrong path in DEPS and want to change the path of the existing
121library in DEPS, please ask the infrastructure team before committing the
122change.
123
David Dorwin7fde299b2020-09-25 02:10:34124Lastly, add the new directory to Chromium's `//third_party/.gitignore`, so that
125it won't show up as untracked files when you run `git status` on the main
126repository.
Dirk Pranke568e95c2018-11-01 23:41:50127
128### Checking in the code directly
129
130If you are checking in a snapshot, please describe the source in the
131README.chromium file, described below. For security reasons, please retrieve
132the code as securely as you can, using HTTPS and GPG signatures if available.
133If retrieving a tarball, please do not check the tarball itself into the tree,
134but do list the source and the SHA-512 hash (for verification) in the
135README.chromium and Change List. The SHA-512 hash can be computed via
136`sha512sum` or `openssl dgst -sha512`. If retrieving from a git
137repository, please list the revision that the code was pulled from.
138
139If you are checking the files in directly, you do not need an entry in DEPS
David Dorwin7fde299b2020-09-25 02:10:34140and do not need to modify `//third_party/.gitignore`.
Dirk Pranke568e95c2018-11-01 23:41:50141
142### Checking in large files
143
144_Accessible to Googlers only. Non-Googlers can email one of the people in
145third_party/OWNERS for help.
146
147See [Moving large files to Google Storage](https://goto.google.com/checking-in-large-files)
148
149## Document the code's context
zpeng8d6f584a2016-12-16 20:50:28150
151### Add OWNERS
152
Forrest Fleming80f70212020-07-01 00:13:50153Your OWNERS file must either list two Chromium developer accounts as the first
154two lines or include a `file:` directive to an OWNERS file within the
155`third_party` directory that itself conforms to this criterion. This will ensure
zpeng8d6f584a2016-12-16 20:50:28156accountability for maintenance of the code over time. While there isn't always
157an ideal or obvious set of people that should go in OWNERS, this is critical for
158first-line triage of any issues that crop up in the code.
159
160As an OWNER, you're expected to:
161
162* Remove the dependency when/if it is no longer needed
163* Update the dependency when a security or stability bug is fixed upstream
164* Help ensure the Chrome feature that uses the dependency continues to use the
165 dependency in the best way, as the feature and the dependency change over
166 time.
167
168### Add a README.chromium
169
170You need a README.chromium file with information about the project from which
171you're re-using code. See
Dirk Pranke568e95c2018-11-01 23:41:50172[//third_party/README.chromium.template](../third_party/README.chromium.template)
zpeng8d6f584a2016-12-16 20:50:28173for a list of fields to include. A presubmit check will check this has the right
174format.
175
Dirk Pranke568e95c2018-11-01 23:41:50176README.chromium files contain a field indicating whether the package is
177security-critical or not. A package is security-critical if it is compiled
178into the product and does any of the following:
179
180* Accepts untrustworthy inputs from the internet
181* Parses or interprets complex input formats
182* Sends data to internet servers
183* Collects new data
184* Influences or sets security-related policy (including the user experience)
185
Adrian Taylor0a06ec32020-03-03 05:00:07186One of the fields is CPEPrefix. This is used by Chromium and Google systems to
187spot known upstream security vulnerabilities, and ensure we merge the fixes
188into our third-party copy. These systems are not foolproof, so as the OWNER,
189it's up to you to keep an eye out rather than solely relying on these
190automated systems. But, adding CPEs decreases the chances of us missing
191vulnerabilities, so they should always be added if possible.
192
193The CPE is a common format shared across the industry; you can look up the CPE
194for your package [here](https://nvd.nist.gov/products/cpe/search). Please use
195CPE format 2.2. When searching for a CPE, you may find that there is not yet
196a CPE for the specific upstream version you're using. This is normal, as CPEs
197are typically allocated only when a vulnerability is found. You should follow
198the version number convention such that, when that does occur in future, we'll
199be notified. If no CPE is available, please specify "unknown".
200
Adrian Taylor8e0d3fd2020-04-17 20:14:25201If you're using a patched or modified version which is halfway between two
202public versions, please "round downwards" to the lower of the public versions
203(it's better for us to be notified of false-positive vulnerabilities than
204false-negatives).
Adrian Taylor0a06ec32020-03-03 05:00:07205
zpeng8d6f584a2016-12-16 20:50:28206### Add a LICENSE file and run related checks
207
208You need a LICENSE file. Example:
Dirk Pranke568e95c2018-11-01 23:41:50209[//third_party/libjpeg/LICENSE](../third_party/libjpeg/LICENSE).
zpeng8d6f584a2016-12-16 20:50:28210
Andrew Mellen2be00b92022-11-11 16:38:42211Run `//tools/licenses/licenses.py scan`; this will complain about incomplete or missing
Dirk Pranke568e95c2018-11-01 23:41:50212data for third_party checkins. We use `licenses.py credits` to generate the
213about:credits page in Google Chrome builds.
zpeng8d6f584a2016-12-16 20:50:28214
215If the library will never be shipped as a part of Chrome (e.g. build-time tools,
216testing tools), make sure to set "License File" as "NOT_SHIPPED" so that the
Dirk Prankebf4136b2018-09-20 22:48:43217license is not included in about:credits page ([more on this below](#credits)).
zpeng8d6f584a2016-12-16 20:50:28218
Dirk Pranke568e95c2018-11-01 23:41:50219## Get a review
zpeng8d6f584a2016-12-16 20:50:28220
Aaron Gablefc8cdad2018-01-16 21:02:40221All third party additions and substantive changes like re-licensing need the
Dirk Pranke568e95c2018-11-01 23:41:50222following sign-offs. Some of these are accessible to Googlers only.
223Non-Googlers can email one of the people in
224[//third_party/OWNERS](../third_party/OWNERS) for help.
zpeng8d6f584a2016-12-16 20:50:28225
Tim van der Lippe8c7498392019-10-28 12:21:04226* Make sure you have the approval from Chrome Eng Review as mentioned
227 [above](#before-you-start).
Alex Rudenkof712a7f2022-02-23 17:55:36228* Get security@chromium.org (or chrome-security@google.com, Google-only)
229 approval. Email the list with relevant details and a link to the CL.
230 Third party code is a hot spot for security vulnerabilities.
Aaron Gablefc8cdad2018-01-16 21:02:40231 When adding a new package that could potentially carry security risk, make
232 sure to highlight risk to security@chromium.org. You may be asked to add
233 a README.security or, in dangerous cases, README.SECURITY.URGENTLY file.
Dirk Pranke6fb90c02018-10-17 02:02:20234* Add chromium-third-party@google.com as a reviewer on your change. This
Adam Langley88658b32018-11-20 22:12:47235 will trigger an automatic round-robin assignment to a reviewer who will check
236 licensing matters. These reviewers may not be able to +1 a change so look for
237 verbal approval in the comments. (This list does not receive or deliver
238 email, so only use it as a reviewer, not for other communication. Internally,
Michael Cui5d517752022-11-01 14:11:32239 see [cl/221704656](http://cl/221704656) for details about how
Dirk Prankef7432812020-06-10 22:38:20240 this is configured.). If you have questions about the third-party process,
241 ask one of the [//third_party/OWNERS](../third_party/OWNERS) instead.
Adam Langley88658b32018-11-20 22:12:47242* Lastly, if all other steps are complete, get a positive code review from a
243 member of [//third_party/OWNERS](../third_party/OWNERS) to land the change.
zpeng8d6f584a2016-12-16 20:50:28244
Kentaro Haracd328342022-02-25 08:25:44245Please send separate emails to the eng review and security@chromium.org.
246You can skip the eng review and security@chromium.org when you are only moving
247existing directories in Chromium to //third_party/.
jochen893d5182017-01-31 22:01:49248
Dirk Pranke568e95c2018-11-01 23:41:50249Subsequent changes don't normally require third-party-owners or security
250approval; you can modify the code as much as you want. When you update code, be
251mindful of security-related mailing lists for the project and relevant CVE to
252update your package.
Dirk Prankebf4136b2018-09-20 22:48:43253
254## How we ensure that the right credits are displayed {#credits}
255
256As we said at the beginning, it is important that Chrome displays the
257right credit and attributions for all of the third_party code we use.
258
259To view this in chrome, you can open chrome://credits.
260
261That page displays a resource embedded in the browser as part of the
262[//components/resources/components_resources.grd](../components/resources/components_resource.grd)
263GRIT file; the actual HTML text is generated in the
264[//components/resources:about_credits](../components/resources/BUILD.gn)
265build target using a template from the output of the
Andrew Mellen2be00b92022-11-11 16:38:42266[//tools/licenses/licenses.py](../tools/licenses/licenses.py) script. Assuming you've followed
Dirk Prankebf4136b2018-09-20 22:48:43267the rules above to ensure that you have the proper LICENSE file and it passes
268the checks, it'll be included automatically.