blob: ba265a41b87f565d205bcf0573b58ab732334eee [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
Lei Zhangf1c73922024-05-13 19:17:4415By default, all third party code should be checked into
16[//third_party](../third_party/),
Dirk Pranke568e95c2018-11-01 23:41:5017for the reasons given above. Other locations are only appropriate in a few
18situations and need explicit approval; don't assume that because there's some
19other directory with third_party in the name it's okay to put new things
20there.
zpeng8d6f584a2016-12-16 20:50:2821
Tim van der Lippe5870ac32019-10-18 11:46:5422## Before you start
23
24To make sure the inclusion of a new third_party project makes sense for the
Alex Mineer55764332022-02-25 18:05:1925Chromium project, you should first obtain
John Abd-El-Malek704bca02022-12-14 18:47:5926[Chrome ATL](../ATL_OWNERS) approval. Please include the following information in an
John Abd-El-Malekf44dc07b2023-02-07 02:39:1127email to chrome-atls-discuss@google.com:
Yaron Friedmane34271392022-04-29 16:45:5328* Motivation of your project
29* Design docs
30* Additional checkout size
John Abd-El-Malekdde7f232022-12-14 23:41:5031 * If the increase is significant (e.g., 20+ MB), can we consider limiting the
32 files to be checked in?
Yaron Friedmane34271392022-04-29 16:45:5333* Build time increase
Erik Staab6e341e82024-08-26 15:13:3534 * This refers to building `chrome` or test targets in the critical
35 development path.
John Abd-El-Malekdde7f232022-12-14 23:41:5036 * If the increase is significant (e.g., 30+ seconds), can we consider making
37 this an optional build target?
38* Binary size increase on Android ([official](https://www.chromium.org/developers/gn-build-configuration) builds)
Lei Zhangf1c73922024-05-13 19:17:4439 * Any increase of 16 KB or more on Android is flagged on the build bots and
John Abd-El-Malekdde7f232022-12-14 23:41:5040 justification is needed.
Yaron Friedmane34271392022-04-29 16:45:5341* Binary size increase on Windows
John Abd-El-Malekdde7f232022-12-14 23:41:5042* Is this library maintained on all platforms that we will use it on?
43 * If not, will the Chrome org be expected to maintain this for some or all
44 platforms?
45* Does it have any performance / memory implications (esp. on Android)? Was the
46library designed with intended use on Android?
47* Do we really need the library? Is there any alternative such as an existing
48library already in Chromium? If introducing a library with similar functionality
49as existing, will it be easy for another developer to understand which should be
50used where? Will you commit to consolidating uses in Chromium and remove the
51alternative libraries?
52* For desktop (Win/Mac/Linux/ChromeOS), does the dependency introduce closed
53source components (e.g., binaries, WASM binaries, obfuscated code)? If yes,
54please reach out to Chrome ATLs.
55
Yaron Friedmane34271392022-04-29 16:45:5356
John Abd-El-Malek704bca02022-12-14 18:47:5957Googlers can access [go/chrome-atls](https://goto.google.com/chrome-atls) and review
58existing topics in g/chrome-atls, and can also come to office hours to ask
Alex Mineer55764332022-02-25 18:05:1959questions.
60
Scott Violet50a02e42022-11-29 20:02:3461### Rust
62
63Rust is allowed for third-party libraries as long as there is a business need,
64which includes the following:
65
66* The Rust implementation is the best (e.g., speed, memory, lack of bugs) or
67only existing implementation available for the third-party library.
68* The Rust implementation allows the operation to move to a higher privileged
69process, and this benefits the product by improving on guardrail metrics (e.g.
70through avoiding process startup, IPC overheads, or C++ memory-unsafety
71mitigations).
72* The Rust implementation can meaningfully reduce our expected risk of
73(memory/crashes/undefined behavior) bugs, when compared to the existing
74third-party library and related C++ code required to use the library. We realize
75assessing risk is quite complex and very nuanced. If this is the criteria by
John Abd-El-Malekf44dc07b2023-02-07 02:39:1176which the third-party library is being added, chrome-atls-discuss@google.com and
Scott Violet50a02e42022-11-29 20:02:3477chrome-rust@google.com may ask for more data.
78
79Support for third-party libraries written in Rust is in active development. If
80the library you wish to add is in Rust, reach out to chrome-rust@google.com
81first.
82
Yaron Friedmane34271392022-04-29 16:45:5383### A note on size constraints
84
85The size of Chromium derived executables can impact overall performance of those binaries as they
86need to run on a wide range of devices including those with extremely limited RAM. Additionally, we
87have experience from Windows of the binary size impacting successful patch rate of updates as well
88as constraints from the Android Ecosystem where APKs included in the system image have hard
89limits on their size due to allocation size of the system partition. For more details and
90guidelines on size increases see
Michael Cui5d517752022-11-01 14:11:3291[//docs/speed/binary_size/binary_size_explainer.md](speed/binary_size/binary_size_explainer.md) and Googlers can
92additionally check [go/chrome-binary-size](https://goto.google.com/chrome-binary-size)
Tim van der Lippe5870ac32019-10-18 11:46:5493
Rachael Newitt15546992023-09-17 22:13:0994### Binaries, obfuscated or minified code
95
96The addition of third-party dependencies that contain binaries, obfuscated
97code, or minified code is strongly discouraged. Code review is an important
98part of reducing risk to Chromium and a reviewer asked to approve a change
99that contains any of these has no way to determine the legitimacy of what
100they are approving. Minification for performance optimization is
101[usually not necessary](speed/binary_size/optimization_advice.md), and the
102trade-off in terms of understandability and security is rarely worth
103it.
104
105Where your dependency will form part of a release binary where size is a concern,
106there are existing tools which handle [compression for distribution](speed/binary_size/optimization_advice.md).
107
108You should not check in any pre-built binaries where there is an alternate,
109supported solution for getting them. If you need to compile from source,
110consider using [CIPD](cipd_and_3pp.md) instead.
111
Dirk Pranke4038090a2024-05-09 01:51:37112This is accessible to Googlers only. Non-Googlers can email one of the people
113in third_party/OWNERS for help.
Rachael Newitt15546992023-09-17 22:13:09114
115See [Chrome Code Policy](https://goto.google.com/chrome-code-policy)
116
117
Dirk Pranke568e95c2018-11-01 23:41:50118## Get the code
zpeng8d6f584a2016-12-16 20:50:28119
Dirk Pranke568e95c2018-11-01 23:41:50120There are two common ways to depend on third-party code: you can reference a
Jason D. Clintonb21e99b2021-09-30 19:19:58121Git repo directly (via entries in the DEPS file) or you can check in a
122snapshot. The former is preferable in most cases:
123
1241. If you are actively developing in the upstream repo, then having the DEPS
125 file include the upstream (that's been mirrored to GoB, see below) can be a
126 way to include those changes into Chromium at a particular revision. The
127 DEPS file will be updated to a new revision when you are ready to "roll" the
128 new version into Chromium. This also avoids duplicate copies of the code
129 showing up in multiple repos leading to contributor confusion.
1301. This interacts favorably with our upstream tracking automation. We
131 automatically consume the upstream Git hashes and match them against a
132 database of known upstreams to tracking drift between Chromium and upstream
133 sources.
1341. This makes adding deps that don't need local changes easier. E.g. some of
135 our automation automatically converts non-GN build rules into GN build rules
136 without any additional CLs.
137
138Checking in a snapshot is useful if this is effectively taking on maintenance
139of an unmaintained project (e.g. an ancient library that we're going to GN-ify
140that hasn't been updated in years). And, of course, if the code you need isn't
141in a Git repo, then you have to snapshot.
zpeng8d6f584a2016-12-16 20:50:28142
Tim van der Lippe5870ac32019-10-18 11:46:54143### Node packages
144
145To include a Node package, add the dependency to the
146[Node package.json](../third_party/node/package.json). Make sure to update
147the corresponding [`npm_exclude.txt`](../third_party/node/npm_exclude.txt)
148and [`npm_include.txt`](../third_party/node/npm_include.txt) to make the code
149available during checkout.
150
Dirk Pranke568e95c2018-11-01 23:41:50151### Pulling the code via DEPS
152
153If the code is in a Git repo that you want to mirror, please file an [infra git
154ticket](https://bugs.chromium.org/p/chromium/issues/entry?template=Infra-Git)
155to get the repo mirrored onto chromium.googlesource.com; we don't allow direct
156dependencies on non-Google-hosted repositories, so that we can still build
Jason D. Clintonb21e99b2021-09-30 19:19:58157if an external repository goes down.
Dirk Pranke568e95c2018-11-01 23:41:50158
159Once the mirror is set up, add an entry to [//DEPS](../DEPS) so that gclient
160will pull it in. If the code is only needed on some platforms, add a condition
161to the deps entry so that developers on other platforms don't pull in things
162they don't need.
163
164As for specifying the path where the library is fetched, a path like
165`//third_party/<project_name>/src` is highly recommended so that you can put
166the file like OWNERS or README.chromium at `//third_party/<project_name>`. If
167you have a wrong path in DEPS and want to change the path of the existing
168library in DEPS, please ask the infrastructure team before committing the
169change.
170
David Dorwin7fde299b2020-09-25 02:10:34171Lastly, add the new directory to Chromium's `//third_party/.gitignore`, so that
172it won't show up as untracked files when you run `git status` on the main
173repository.
Dirk Pranke568e95c2018-11-01 23:41:50174
175### Checking in the code directly
176
177If you are checking in a snapshot, please describe the source in the
178README.chromium file, described below. For security reasons, please retrieve
179the code as securely as you can, using HTTPS and GPG signatures if available.
180If retrieving a tarball, please do not check the tarball itself into the tree,
181but do list the source and the SHA-512 hash (for verification) in the
182README.chromium and Change List. The SHA-512 hash can be computed via
183`sha512sum` or `openssl dgst -sha512`. If retrieving from a git
184repository, please list the revision that the code was pulled from.
185
186If you are checking the files in directly, you do not need an entry in DEPS
David Dorwin7fde299b2020-09-25 02:10:34187and do not need to modify `//third_party/.gitignore`.
Dirk Pranke568e95c2018-11-01 23:41:50188
189### Checking in large files
190
Dirk Pranke4038090a2024-05-09 01:51:37191This is accessible to Googlers only. Non-Googlers can email one of the people
192in third_party/OWNERS for help.
Dirk Pranke568e95c2018-11-01 23:41:50193
194See [Moving large files to Google Storage](https://goto.google.com/checking-in-large-files)
195
196## Document the code's context
zpeng8d6f584a2016-12-16 20:50:28197
198### Add OWNERS
199
Dirk Pranke6d3bb8e2024-05-09 00:54:33200Your OWNERS file must either list the email addresses of two Chromium
201committers on the first two lines or include a `file:` directive to an OWNERS
202file within the `third_party` directory that itself conforms to this criterion.
203This will ensure accountability for maintenance of the code over time. While
204there isn't always an ideal or obvious set of people that should go in OWNERS,
205this is critical for first-line triage of any issues that crop up in the code.
zpeng8d6f584a2016-12-16 20:50:28206
207As an OWNER, you're expected to:
208
209* Remove the dependency when/if it is no longer needed
210* Update the dependency when a security or stability bug is fixed upstream
211* Help ensure the Chrome feature that uses the dependency continues to use the
212 dependency in the best way, as the feature and the dependency change over
213 time.
214
215### Add a README.chromium
216
217You need a README.chromium file with information about the project from which
218you're re-using code. See
Dirk Pranke568e95c2018-11-01 23:41:50219[//third_party/README.chromium.template](../third_party/README.chromium.template)
zpeng8d6f584a2016-12-16 20:50:28220for a list of fields to include. A presubmit check will check this has the right
221format.
222
Dirk Pranke568e95c2018-11-01 23:41:50223README.chromium files contain a field indicating whether the package is
224security-critical or not. A package is security-critical if it is compiled
225into the product and does any of the following:
226
227* Accepts untrustworthy inputs from the internet
228* Parses or interprets complex input formats
229* Sends data to internet servers
230* Collects new data
231* Influences or sets security-related policy (including the user experience)
232
Rachael Newittfc2e3342023-07-04 23:07:31233**CPE Prefix**
Adrian Taylor0a06ec32020-03-03 05:00:07234One of the fields is CPEPrefix. This is used by Chromium and Google systems to
235spot known upstream security vulnerabilities, and ensure we merge the fixes
236into our third-party copy. These systems are not foolproof, so as the OWNER,
237it's up to you to keep an eye out rather than solely relying on these
238automated systems. But, adding CPEs decreases the chances of us missing
239vulnerabilities, so they should always be added if possible.
240
241The CPE is a common format shared across the industry; you can look up the CPE
Anne Redulla04f91972023-08-31 04:09:19242for your package [here](https://nvd.nist.gov/products/cpe/search).
243* Use CPE format 2.3 (preferred) or CPE format 2.2 (supported).
244* If the CPE uses the 2.3 URI binding or 2.2 format (i.e. starts with "cpe:/"),
245and no version is explicitly specified within the `CPEPrefix`, the `Version`
246in the `README.chromium` file will be appended to the `CPEPrefix`, if available.
247 * Note: if the `Version` field is set to a git hash value, version matching
248 for vulnerabilities will fail.
249
250When searching for a CPE, you may find that there is not yet a CPE for the
251specific upstream version you're using. This is normal, as CPEs are typically
252allocated only when a vulnerability is found. You should follow the version
253number convention such that, when that does occur in future, we'll be notified.
254If no CPE is available, please specify "unknown".
Adrian Taylor0a06ec32020-03-03 05:00:07255
Adrian Taylor8e0d3fd2020-04-17 20:14:25256If you're using a patched or modified version which is halfway between two
257public versions, please "round downwards" to the lower of the public versions
258(it's better for us to be notified of false-positive vulnerabilities than
259false-negatives).
Adrian Taylor0a06ec32020-03-03 05:00:07260
Rachael Newittfc2e3342023-07-04 23:07:31261
262**Shipped**
263Your README.chromium should also specify whether your third party dependency
264will be shipped as part of a final binary. The "Shipped" field replaces the now
265deprecated special value of "NOT_SHIPPED" which was previously allowed in the
266"License File" field. This use is no longer supported and if your third party
267dependency includes a license you should also use the "Licence File" field to
268reference it, regardless of whether it is shipped or not.
269
270
Anne Redullab75419e2023-09-12 03:34:01271**Multiple packages**
272Each package should have its own README.chromium. However, if this is not
273possible and the information for multiple packages must be placed in a single
274README.chromium, use the below line to separate the data for each package:
275```
276-------------------- DEPENDENCY DIVIDER --------------------
277```
278
279
zpeng8d6f584a2016-12-16 20:50:28280### Add a LICENSE file and run related checks
281
282You need a LICENSE file. Example:
Dirk Pranke568e95c2018-11-01 23:41:50283[//third_party/libjpeg/LICENSE](../third_party/libjpeg/LICENSE).
zpeng8d6f584a2016-12-16 20:50:28284
Andrew Mellen2be00b92022-11-11 16:38:42285Run `//tools/licenses/licenses.py scan`; this will complain about incomplete or missing
Dirk Pranke568e95c2018-11-01 23:41:50286data for third_party checkins. We use `licenses.py credits` to generate the
287about:credits page in Google Chrome builds.
zpeng8d6f584a2016-12-16 20:50:28288
289If the library will never be shipped as a part of Chrome (e.g. build-time tools,
Rachael Newittfc2e3342023-07-04 23:07:31290testing tools), make sure to set the "Shipped" field to "no" so that the license
Rachael Newitt15546992023-09-17 22:13:09291is not included in about:credits page ([more on this below](#credits)).
zpeng8d6f584a2016-12-16 20:50:28292
Dirk Pranke568e95c2018-11-01 23:41:50293## Get a review
zpeng8d6f584a2016-12-16 20:50:28294
Aaron Gablefc8cdad2018-01-16 21:02:40295All third party additions and substantive changes like re-licensing need the
Dirk Pranke568e95c2018-11-01 23:41:50296following sign-offs. Some of these are accessible to Googlers only.
297Non-Googlers can email one of the people in
298[//third_party/OWNERS](../third_party/OWNERS) for help.
zpeng8d6f584a2016-12-16 20:50:28299
John Abd-El-Malek704bca02022-12-14 18:47:59300* Make sure you have the approval from Chrome ATLs as mentioned
Tim van der Lippe8c7498392019-10-28 12:21:04301 [above](#before-you-start).
Alex Rudenkof712a7f2022-02-23 17:55:36302* Get security@chromium.org (or chrome-security@google.com, Google-only)
303 approval. Email the list with relevant details and a link to the CL.
304 Third party code is a hot spot for security vulnerabilities.
Aaron Gablefc8cdad2018-01-16 21:02:40305 When adding a new package that could potentially carry security risk, make
306 sure to highlight risk to security@chromium.org. You may be asked to add
307 a README.security or, in dangerous cases, README.SECURITY.URGENTLY file.
Dirk Pranke6fb90c02018-10-17 02:02:20308* Add chromium-third-party@google.com as a reviewer on your change. This
Adam Langley88658b32018-11-20 22:12:47309 will trigger an automatic round-robin assignment to a reviewer who will check
310 licensing matters. These reviewers may not be able to +1 a change so look for
311 verbal approval in the comments. (This list does not receive or deliver
312 email, so only use it as a reviewer, not for other communication. Internally,
Michael Cui5d517752022-11-01 14:11:32313 see [cl/221704656](http://cl/221704656) for details about how
Dirk Prankef7432812020-06-10 22:38:20314 this is configured.). If you have questions about the third-party process,
315 ask one of the [//third_party/OWNERS](../third_party/OWNERS) instead.
Adam Langley88658b32018-11-20 22:12:47316* Lastly, if all other steps are complete, get a positive code review from a
317 member of [//third_party/OWNERS](../third_party/OWNERS) to land the change.
zpeng8d6f584a2016-12-16 20:50:28318
John Abd-El-Malek704bca02022-12-14 18:47:59319Please send separate emails to the ATLs and security@chromium.org.
320You can skip the ATL review and security@chromium.org when you are only moving
Kentaro Haracd328342022-02-25 08:25:44321existing directories in Chromium to //third_party/.
jochen893d5182017-01-31 22:01:49322
Dirk Pranke568e95c2018-11-01 23:41:50323Subsequent changes don't normally require third-party-owners or security
324approval; you can modify the code as much as you want. When you update code, be
325mindful of security-related mailing lists for the project and relevant CVE to
326update your package.
Dirk Prankebf4136b2018-09-20 22:48:43327
328## How we ensure that the right credits are displayed {#credits}
329
330As we said at the beginning, it is important that Chrome displays the
331right credit and attributions for all of the third_party code we use.
332
333To view this in chrome, you can open chrome://credits.
334
335That page displays a resource embedded in the browser as part of the
336[//components/resources/components_resources.grd](../components/resources/components_resource.grd)
337GRIT file; the actual HTML text is generated in the
338[//components/resources:about_credits](../components/resources/BUILD.gn)
339build target using a template from the output of the
Rachael Newittfc2e3342023-07-04 23:07:31340[//tools/licenses/licenses.py](../tools/licenses/licenses.py) script. Assuming
341you‘ve followed the rules above to ensure that you have the proper path to the
342LICENSE file and set the Shipped value, if it passes the checks, it’ll be
343included automatically.