zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 1 | # Adding third_party Libraries |
| 2 | |
| 3 | [TOC] |
| 4 | |
| 5 | Using third party code can save time and is consistent with our values - no need |
| 6 | to reinvent the wheel! We put all code that isn't written by Chromium developers |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 7 | into `//third_party` (even if you end up modifying just a few functions). We do |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 8 | this to make it easy to track license compliance, security patches, and supply |
| 9 | the right credit and attributions. It also makes it a lot easier for other |
| 10 | projects that embed our code to track what is Chromium licensed and what is |
| 11 | covered by other licenses. |
| 12 | |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 13 | ## Put the code in //third_party |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 14 | |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 15 | By default, all code should be checked into [//third_party](../third_party/), |
| 16 | for the reasons given above. Other locations are only appropriate in a few |
| 17 | situations and need explicit approval; don't assume that because there's some |
| 18 | other directory with third_party in the name it's okay to put new things |
| 19 | there. |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 20 | |
Tim van der Lippe | 5870ac3 | 2019-10-18 11:46:54 | [diff] [blame] | 21 | ## Before you start |
| 22 | |
| 23 | To make sure the inclusion of a new third_party project makes sense for the |
Alex Mineer | 5576433 | 2022-02-25 18:05:19 | [diff] [blame] | 24 | Chromium project, you should first obtain |
John Abd-El-Malek | 704bca0 | 2022-12-14 18:47:59 | [diff] [blame] | 25 | [Chrome ATL](../ATL_OWNERS) approval. Please include the following information in an |
John Abd-El-Malek | f44dc07b | 2023-02-07 02:39:11 | [diff] [blame] | 26 | email to chrome-atls-discuss@google.com: |
Yaron Friedman | e3427139 | 2022-04-29 16:45:53 | [diff] [blame] | 27 | * Motivation of your project |
| 28 | * Design docs |
| 29 | * Additional checkout size |
John Abd-El-Malek | dde7f23 | 2022-12-14 23:41:50 | [diff] [blame] | 30 | * If the increase is significant (e.g., 20+ MB), can we consider limiting the |
| 31 | files to be checked in? |
Yaron Friedman | e3427139 | 2022-04-29 16:45:53 | [diff] [blame] | 32 | * Build time increase |
John Abd-El-Malek | dde7f23 | 2022-12-14 23:41:50 | [diff] [blame] | 33 | * If the increase is significant (e.g., 30+ seconds), can we consider making |
| 34 | this an optional build target? |
| 35 | * Binary size increase on Android ([official](https://www.chromium.org/developers/gn-build-configuration) builds) |
| 36 | * Any 16 KB increase on Android is flagged on the build bots and |
| 37 | justification is needed. |
Yaron Friedman | e3427139 | 2022-04-29 16:45:53 | [diff] [blame] | 38 | * Binary size increase on Windows |
John Abd-El-Malek | dde7f23 | 2022-12-14 23:41:50 | [diff] [blame] | 39 | * Is this library maintained on all platforms that we will use it on? |
| 40 | * If not, will the Chrome org be expected to maintain this for some or all |
| 41 | platforms? |
| 42 | * Does it have any performance / memory implications (esp. on Android)? Was the |
| 43 | library designed with intended use on Android? |
| 44 | * Do we really need the library? Is there any alternative such as an existing |
| 45 | library already in Chromium? If introducing a library with similar functionality |
| 46 | as existing, will it be easy for another developer to understand which should be |
| 47 | used where? Will you commit to consolidating uses in Chromium and remove the |
| 48 | alternative libraries? |
| 49 | * For desktop (Win/Mac/Linux/ChromeOS), does the dependency introduce closed |
| 50 | source components (e.g., binaries, WASM binaries, obfuscated code)? If yes, |
| 51 | please reach out to Chrome ATLs. |
| 52 | |
Yaron Friedman | e3427139 | 2022-04-29 16:45:53 | [diff] [blame] | 53 | |
John Abd-El-Malek | 704bca0 | 2022-12-14 18:47:59 | [diff] [blame] | 54 | Googlers can access [go/chrome-atls](https://goto.google.com/chrome-atls) and review |
| 55 | existing topics in g/chrome-atls, and can also come to office hours to ask |
Alex Mineer | 5576433 | 2022-02-25 18:05:19 | [diff] [blame] | 56 | questions. |
| 57 | |
Scott Violet | 50a02e4 | 2022-11-29 20:02:34 | [diff] [blame] | 58 | ### Rust |
| 59 | |
| 60 | Rust is allowed for third-party libraries as long as there is a business need, |
| 61 | which includes the following: |
| 62 | |
| 63 | * The Rust implementation is the best (e.g., speed, memory, lack of bugs) or |
| 64 | only existing implementation available for the third-party library. |
| 65 | * The Rust implementation allows the operation to move to a higher privileged |
| 66 | process, and this benefits the product by improving on guardrail metrics (e.g. |
| 67 | through avoiding process startup, IPC overheads, or C++ memory-unsafety |
| 68 | mitigations). |
| 69 | * The Rust implementation can meaningfully reduce our expected risk of |
| 70 | (memory/crashes/undefined behavior) bugs, when compared to the existing |
| 71 | third-party library and related C++ code required to use the library. We realize |
| 72 | assessing risk is quite complex and very nuanced. If this is the criteria by |
John Abd-El-Malek | f44dc07b | 2023-02-07 02:39:11 | [diff] [blame] | 73 | which the third-party library is being added, chrome-atls-discuss@google.com and |
Scott Violet | 50a02e4 | 2022-11-29 20:02:34 | [diff] [blame] | 74 | chrome-rust@google.com may ask for more data. |
| 75 | |
| 76 | Support for third-party libraries written in Rust is in active development. If |
| 77 | the library you wish to add is in Rust, reach out to chrome-rust@google.com |
| 78 | first. |
| 79 | |
Yaron Friedman | e3427139 | 2022-04-29 16:45:53 | [diff] [blame] | 80 | ### A note on size constraints |
| 81 | |
| 82 | The size of Chromium derived executables can impact overall performance of those binaries as they |
| 83 | need to run on a wide range of devices including those with extremely limited RAM. Additionally, we |
| 84 | have experience from Windows of the binary size impacting successful patch rate of updates as well |
| 85 | as constraints from the Android Ecosystem where APKs included in the system image have hard |
| 86 | limits on their size due to allocation size of the system partition. For more details and |
| 87 | guidelines on size increases see |
Michael Cui | 5d51775 | 2022-11-01 14:11:32 | [diff] [blame] | 88 | [//docs/speed/binary_size/binary_size_explainer.md](speed/binary_size/binary_size_explainer.md) and Googlers can |
| 89 | additionally check [go/chrome-binary-size](https://goto.google.com/chrome-binary-size) |
Tim van der Lippe | 5870ac3 | 2019-10-18 11:46:54 | [diff] [blame] | 90 | |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 91 | ## Get the code |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 92 | |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 93 | There are two common ways to depend on third-party code: you can reference a |
Jason D. Clinton | b21e99b | 2021-09-30 19:19:58 | [diff] [blame] | 94 | Git repo directly (via entries in the DEPS file) or you can check in a |
| 95 | snapshot. The former is preferable in most cases: |
| 96 | |
| 97 | 1. If you are actively developing in the upstream repo, then having the DEPS |
| 98 | file include the upstream (that's been mirrored to GoB, see below) can be a |
| 99 | way to include those changes into Chromium at a particular revision. The |
| 100 | DEPS file will be updated to a new revision when you are ready to "roll" the |
| 101 | new version into Chromium. This also avoids duplicate copies of the code |
| 102 | showing up in multiple repos leading to contributor confusion. |
| 103 | 1. This interacts favorably with our upstream tracking automation. We |
| 104 | automatically consume the upstream Git hashes and match them against a |
| 105 | database of known upstreams to tracking drift between Chromium and upstream |
| 106 | sources. |
| 107 | 1. This makes adding deps that don't need local changes easier. E.g. some of |
| 108 | our automation automatically converts non-GN build rules into GN build rules |
| 109 | without any additional CLs. |
| 110 | |
| 111 | Checking in a snapshot is useful if this is effectively taking on maintenance |
| 112 | of an unmaintained project (e.g. an ancient library that we're going to GN-ify |
| 113 | that hasn't been updated in years). And, of course, if the code you need isn't |
| 114 | in a Git repo, then you have to snapshot. |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 115 | |
Tim van der Lippe | 5870ac3 | 2019-10-18 11:46:54 | [diff] [blame] | 116 | ### Node packages |
| 117 | |
| 118 | To include a Node package, add the dependency to the |
| 119 | [Node package.json](../third_party/node/package.json). Make sure to update |
| 120 | the corresponding [`npm_exclude.txt`](../third_party/node/npm_exclude.txt) |
| 121 | and [`npm_include.txt`](../third_party/node/npm_include.txt) to make the code |
| 122 | available during checkout. |
| 123 | |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 124 | ### Pulling the code via DEPS |
| 125 | |
| 126 | If the code is in a Git repo that you want to mirror, please file an [infra git |
| 127 | ticket](https://bugs.chromium.org/p/chromium/issues/entry?template=Infra-Git) |
| 128 | to get the repo mirrored onto chromium.googlesource.com; we don't allow direct |
| 129 | dependencies on non-Google-hosted repositories, so that we can still build |
Jason D. Clinton | b21e99b | 2021-09-30 19:19:58 | [diff] [blame] | 130 | if an external repository goes down. |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 131 | |
| 132 | Once the mirror is set up, add an entry to [//DEPS](../DEPS) so that gclient |
| 133 | will pull it in. If the code is only needed on some platforms, add a condition |
| 134 | to the deps entry so that developers on other platforms don't pull in things |
| 135 | they don't need. |
| 136 | |
| 137 | As for specifying the path where the library is fetched, a path like |
| 138 | `//third_party/<project_name>/src` is highly recommended so that you can put |
| 139 | the file like OWNERS or README.chromium at `//third_party/<project_name>`. If |
| 140 | you have a wrong path in DEPS and want to change the path of the existing |
| 141 | library in DEPS, please ask the infrastructure team before committing the |
| 142 | change. |
| 143 | |
David Dorwin | 7fde299b | 2020-09-25 02:10:34 | [diff] [blame] | 144 | Lastly, add the new directory to Chromium's `//third_party/.gitignore`, so that |
| 145 | it won't show up as untracked files when you run `git status` on the main |
| 146 | repository. |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 147 | |
| 148 | ### Checking in the code directly |
| 149 | |
| 150 | If you are checking in a snapshot, please describe the source in the |
| 151 | README.chromium file, described below. For security reasons, please retrieve |
| 152 | the code as securely as you can, using HTTPS and GPG signatures if available. |
| 153 | If retrieving a tarball, please do not check the tarball itself into the tree, |
| 154 | but do list the source and the SHA-512 hash (for verification) in the |
| 155 | README.chromium and Change List. The SHA-512 hash can be computed via |
| 156 | `sha512sum` or `openssl dgst -sha512`. If retrieving from a git |
| 157 | repository, please list the revision that the code was pulled from. |
| 158 | |
| 159 | If you are checking the files in directly, you do not need an entry in DEPS |
David Dorwin | 7fde299b | 2020-09-25 02:10:34 | [diff] [blame] | 160 | and do not need to modify `//third_party/.gitignore`. |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 161 | |
| 162 | ### Checking in large files |
| 163 | |
| 164 | _Accessible to Googlers only. Non-Googlers can email one of the people in |
| 165 | third_party/OWNERS for help. |
| 166 | |
| 167 | See [Moving large files to Google Storage](https://goto.google.com/checking-in-large-files) |
| 168 | |
| 169 | ## Document the code's context |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 170 | |
| 171 | ### Add OWNERS |
| 172 | |
Forrest Fleming | 80f7021 | 2020-07-01 00:13:50 | [diff] [blame] | 173 | Your OWNERS file must either list two Chromium developer accounts as the first |
| 174 | two lines or include a `file:` directive to an OWNERS file within the |
| 175 | `third_party` directory that itself conforms to this criterion. This will ensure |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 176 | accountability for maintenance of the code over time. While there isn't always |
| 177 | an ideal or obvious set of people that should go in OWNERS, this is critical for |
| 178 | first-line triage of any issues that crop up in the code. |
| 179 | |
| 180 | As an OWNER, you're expected to: |
| 181 | |
| 182 | * Remove the dependency when/if it is no longer needed |
| 183 | * Update the dependency when a security or stability bug is fixed upstream |
| 184 | * Help ensure the Chrome feature that uses the dependency continues to use the |
| 185 | dependency in the best way, as the feature and the dependency change over |
| 186 | time. |
| 187 | |
| 188 | ### Add a README.chromium |
| 189 | |
| 190 | You need a README.chromium file with information about the project from which |
| 191 | you're re-using code. See |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 192 | [//third_party/README.chromium.template](../third_party/README.chromium.template) |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 193 | for a list of fields to include. A presubmit check will check this has the right |
| 194 | format. |
| 195 | |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 196 | README.chromium files contain a field indicating whether the package is |
| 197 | security-critical or not. A package is security-critical if it is compiled |
| 198 | into the product and does any of the following: |
| 199 | |
| 200 | * Accepts untrustworthy inputs from the internet |
| 201 | * Parses or interprets complex input formats |
| 202 | * Sends data to internet servers |
| 203 | * Collects new data |
| 204 | * Influences or sets security-related policy (including the user experience) |
| 205 | |
Rachael Newitt | fc2e334 | 2023-07-04 23:07:31 | [diff] [blame^] | 206 | **CPE Prefix** |
Adrian Taylor | 0a06ec3 | 2020-03-03 05:00:07 | [diff] [blame] | 207 | One of the fields is CPEPrefix. This is used by Chromium and Google systems to |
| 208 | spot known upstream security vulnerabilities, and ensure we merge the fixes |
| 209 | into our third-party copy. These systems are not foolproof, so as the OWNER, |
| 210 | it's up to you to keep an eye out rather than solely relying on these |
| 211 | automated systems. But, adding CPEs decreases the chances of us missing |
| 212 | vulnerabilities, so they should always be added if possible. |
| 213 | |
| 214 | The CPE is a common format shared across the industry; you can look up the CPE |
| 215 | for your package [here](https://nvd.nist.gov/products/cpe/search). Please use |
| 216 | CPE format 2.2. When searching for a CPE, you may find that there is not yet |
| 217 | a CPE for the specific upstream version you're using. This is normal, as CPEs |
| 218 | are typically allocated only when a vulnerability is found. You should follow |
| 219 | the version number convention such that, when that does occur in future, we'll |
| 220 | be notified. If no CPE is available, please specify "unknown". |
| 221 | |
Adrian Taylor | 8e0d3fd | 2020-04-17 20:14:25 | [diff] [blame] | 222 | If you're using a patched or modified version which is halfway between two |
| 223 | public versions, please "round downwards" to the lower of the public versions |
| 224 | (it's better for us to be notified of false-positive vulnerabilities than |
| 225 | false-negatives). |
Adrian Taylor | 0a06ec3 | 2020-03-03 05:00:07 | [diff] [blame] | 226 | |
Rachael Newitt | fc2e334 | 2023-07-04 23:07:31 | [diff] [blame^] | 227 | |
| 228 | **Shipped** |
| 229 | Your README.chromium should also specify whether your third party dependency |
| 230 | will be shipped as part of a final binary. The "Shipped" field replaces the now |
| 231 | deprecated special value of "NOT_SHIPPED" which was previously allowed in the |
| 232 | "License File" field. This use is no longer supported and if your third party |
| 233 | dependency includes a license you should also use the "Licence File" field to |
| 234 | reference it, regardless of whether it is shipped or not. |
| 235 | |
| 236 | |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 237 | ### Add a LICENSE file and run related checks |
| 238 | |
| 239 | You need a LICENSE file. Example: |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 240 | [//third_party/libjpeg/LICENSE](../third_party/libjpeg/LICENSE). |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 241 | |
Andrew Mellen | 2be00b9 | 2022-11-11 16:38:42 | [diff] [blame] | 242 | Run `//tools/licenses/licenses.py scan`; this will complain about incomplete or missing |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 243 | data for third_party checkins. We use `licenses.py credits` to generate the |
| 244 | about:credits page in Google Chrome builds. |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 245 | |
| 246 | If the library will never be shipped as a part of Chrome (e.g. build-time tools, |
Rachael Newitt | fc2e334 | 2023-07-04 23:07:31 | [diff] [blame^] | 247 | testing tools), make sure to set the "Shipped" field to "no" so that the license |
| 248 | is not included in about:credits page ([more on this below](#credits)). |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 249 | |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 250 | ## Get a review |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 251 | |
Aaron Gable | fc8cdad | 2018-01-16 21:02:40 | [diff] [blame] | 252 | All third party additions and substantive changes like re-licensing need the |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 253 | following sign-offs. Some of these are accessible to Googlers only. |
| 254 | Non-Googlers can email one of the people in |
| 255 | [//third_party/OWNERS](../third_party/OWNERS) for help. |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 256 | |
John Abd-El-Malek | 704bca0 | 2022-12-14 18:47:59 | [diff] [blame] | 257 | * Make sure you have the approval from Chrome ATLs as mentioned |
Tim van der Lippe | 8c749839 | 2019-10-28 12:21:04 | [diff] [blame] | 258 | [above](#before-you-start). |
Alex Rudenko | f712a7f | 2022-02-23 17:55:36 | [diff] [blame] | 259 | * Get security@chromium.org (or chrome-security@google.com, Google-only) |
| 260 | approval. Email the list with relevant details and a link to the CL. |
| 261 | Third party code is a hot spot for security vulnerabilities. |
Aaron Gable | fc8cdad | 2018-01-16 21:02:40 | [diff] [blame] | 262 | When adding a new package that could potentially carry security risk, make |
| 263 | sure to highlight risk to security@chromium.org. You may be asked to add |
| 264 | a README.security or, in dangerous cases, README.SECURITY.URGENTLY file. |
Dirk Pranke | 6fb90c0 | 2018-10-17 02:02:20 | [diff] [blame] | 265 | * Add chromium-third-party@google.com as a reviewer on your change. This |
Adam Langley | 88658b3 | 2018-11-20 22:12:47 | [diff] [blame] | 266 | will trigger an automatic round-robin assignment to a reviewer who will check |
| 267 | licensing matters. These reviewers may not be able to +1 a change so look for |
| 268 | verbal approval in the comments. (This list does not receive or deliver |
| 269 | email, so only use it as a reviewer, not for other communication. Internally, |
Michael Cui | 5d51775 | 2022-11-01 14:11:32 | [diff] [blame] | 270 | see [cl/221704656](http://cl/221704656) for details about how |
Dirk Pranke | f743281 | 2020-06-10 22:38:20 | [diff] [blame] | 271 | this is configured.). If you have questions about the third-party process, |
| 272 | ask one of the [//third_party/OWNERS](../third_party/OWNERS) instead. |
Adam Langley | 88658b3 | 2018-11-20 22:12:47 | [diff] [blame] | 273 | * Lastly, if all other steps are complete, get a positive code review from a |
| 274 | member of [//third_party/OWNERS](../third_party/OWNERS) to land the change. |
zpeng | 8d6f584a | 2016-12-16 20:50:28 | [diff] [blame] | 275 | |
John Abd-El-Malek | 704bca0 | 2022-12-14 18:47:59 | [diff] [blame] | 276 | Please send separate emails to the ATLs and security@chromium.org. |
| 277 | You can skip the ATL review and security@chromium.org when you are only moving |
Kentaro Hara | cd32834 | 2022-02-25 08:25:44 | [diff] [blame] | 278 | existing directories in Chromium to //third_party/. |
jochen | 893d518 | 2017-01-31 22:01:49 | [diff] [blame] | 279 | |
Dirk Pranke | 568e95c | 2018-11-01 23:41:50 | [diff] [blame] | 280 | Subsequent changes don't normally require third-party-owners or security |
| 281 | approval; you can modify the code as much as you want. When you update code, be |
| 282 | mindful of security-related mailing lists for the project and relevant CVE to |
| 283 | update your package. |
Dirk Pranke | bf4136b | 2018-09-20 22:48:43 | [diff] [blame] | 284 | |
| 285 | ## How we ensure that the right credits are displayed {#credits} |
| 286 | |
| 287 | As we said at the beginning, it is important that Chrome displays the |
| 288 | right credit and attributions for all of the third_party code we use. |
| 289 | |
| 290 | To view this in chrome, you can open chrome://credits. |
| 291 | |
| 292 | That page displays a resource embedded in the browser as part of the |
| 293 | [//components/resources/components_resources.grd](../components/resources/components_resource.grd) |
| 294 | GRIT file; the actual HTML text is generated in the |
| 295 | [//components/resources:about_credits](../components/resources/BUILD.gn) |
| 296 | build target using a template from the output of the |
Rachael Newitt | fc2e334 | 2023-07-04 23:07:31 | [diff] [blame^] | 297 | [//tools/licenses/licenses.py](../tools/licenses/licenses.py) script. Assuming |
| 298 | you‘ve followed the rules above to ensure that you have the proper path to the |
| 299 | LICENSE file and set the Shipped value, if it passes the checks, it’ll be |
| 300 | included automatically. |