tree: 5fd083770794b89f14ea1fe4c91d5efcdfb7115d
  1. addr2line/
  2. adler2/
  3. ahash/
  4. aho_corasick/
  5. android_system_properties/
  6. anstyle/
  7. antlr4rust/
  8. anyhow/
  9. arbitrary_int/
  10. array_init/
  11. arrayvec/
  12. autocfg/
  13. backtrace/
  14. base64/
  15. better_any/
  16. bincode/
  17. bincode_derive/
  18. bit_set/
  19. bit_vec/
  20. bitflags/
  21. bytemuck/
  22. bytemuck_derive/
  23. byteorder/
  24. byteorder_lite/
  25. bytes/
  26. calendrical_calculations/
  27. cc/
  28. cfg_if/
  29. chromium_crates_io/
  30. chrono/
  31. clap/
  32. clap_builder/
  33. clap_lex/
  34. codespan_reporting/
  35. core_foundation_sys/
  36. core_maths/
  37. crc32fast/
  38. cxx/
  39. cxxbridge_cmd/
  40. cxxbridge_flags/
  41. cxxbridge_macro/
  42. derivre/
  43. diplomat/
  44. diplomat_core/
  45. diplomat_runtime/
  46. displaydoc/
  47. either/
  48. encoding_rs/
  49. equivalent/
  50. fdeflate/
  51. fend_core/
  52. fixed_decimal/
  53. flate2/
  54. foldhash/
  55. font_types/
  56. getrandom/
  57. gimli/
  58. hashbrown/
  59. heck/
  60. hex/
  61. hmac_sha256/
  62. iana_time_zone/
  63. icu_calendar/
  64. icu_calendar_data/
  65. icu_casemap/
  66. icu_casemap_data/
  67. icu_collections/
  68. icu_decimal/
  69. icu_decimal_data/
  70. icu_experimental/
  71. icu_experimental_data/
  72. icu_list/
  73. icu_list_data/
  74. icu_locale/
  75. icu_locale_core/
  76. icu_locale_data/
  77. icu_normalizer/
  78. icu_normalizer_data/
  79. icu_pattern/
  80. icu_plurals/
  81. icu_plurals_data/
  82. icu_properties/
  83. icu_properties_data/
  84. icu_provider/
  85. icu_time/
  86. image/
  87. indexmap/
  88. itertools/
  89. itoa/
  90. ixdtf/
  91. jiff_tzdb/
  92. jxl/
  93. jxl_macros/
  94. jxl_simd/
  95. jxl_transforms/
  96. lazy_static/
  97. libc/
  98. libm/
  99. litemap/
  100. llguidance/
  101. lock_api/
  102. log/
  103. memchr/
  104. memo_map/
  105. minijinja/
  106. miniz_oxide/
  107. moxcms/
  108. murmur3/
  109. num_bigint/
  110. num_derive/
  111. num_integer/
  112. num_rational/
  113. num_traits/
  114. object/
  115. once_cell/
  116. opusic_sys/
  117. ordered_float/
  118. parking_lot/
  119. parking_lot_core/
  120. png/
  121. potential_utf/
  122. proc_macro2/
  123. proc_macro_error2/
  124. proc_macro_error_attr2/
  125. prost/
  126. prost_derive/
  127. pxfm/
  128. qr_code/
  129. quote/
  130. read_fonts/
  131. regex_automata/
  132. regex_syntax/
  133. resb/
  134. rustc_demangle/
  135. rustc_demangle_capi/
  136. rustversion/
  137. ryu/
  138. scopeguard/
  139. serde/
  140. serde_core/
  141. serde_derive/
  142. serde_json/
  143. serde_json_lenient/
  144. simd_adler32/
  145. skrifa/
  146. small_ctor/
  147. smallvec/
  148. src/
  149. stable_deref_trait/
  150. static_assertions/
  151. strck/
  152. strsim/
  153. strum/
  154. strum_macros/
  155. subtle/
  156. symphonia/
  157. symphonia_adapter_libopus/
  158. symphonia_bundle_flac/
  159. symphonia_bundle_mp3/
  160. symphonia_codec_pcm/
  161. symphonia_codec_vorbis/
  162. symphonia_core/
  163. symphonia_metadata/
  164. symphonia_utils_xiph/
  165. syn/
  166. synstructure/
  167. temporal_capi/
  168. temporal_rs/
  169. termcolor/
  170. thiserror/
  171. thiserror_impl/
  172. timezone_provider/
  173. tinystr/
  174. toktrie/
  175. typed_arena/
  176. typed_path/
  177. tzif/
  178. unicode_ident/
  179. unicode_width/
  180. unty/
  181. utf8_iter/
  182. uuid/
  183. version_check/
  184. virtue/
  185. winapi_util/
  186. windows_aarch64_msvc/
  187. windows_i686_msvc/
  188. windows_link/
  189. windows_sys/
  190. windows_targets/
  191. windows_x86_64_msvc/
  192. writeable/
  193. xml/
  194. yoke/
  195. yoke_derive/
  196. zerocopy/
  197. zerofrom/
  198. zerofrom_derive/
  199. zerotrie/
  200. zerovec/
  201. zerovec_derive/
  202. zip/
  203. zmij/
  204. zoneinfo64/
  205. .clang-format
  206. DEPS
  207. OWNERS
  208. OWNERS-review-checklist.md
  209. PRESUBMIT.py
  210. README-importing-new-crates.md
  211. README.md
third_party/rust/README.md

Rust third-party code

This directory contains third-party Rust libraries from https://crates.io (and sometimes thin wrappers around them for Chromium interop).

gnrt: Cargo.toml => vendor + BUILD.gn + README.chromium

Third-party libraries from crates.io, depend on Cargo as a build system. Chromium uses gnrt tool to automate

  • Vendoring crates sources into Chromium repository
  • Generating BUILD.gn and README.chromium files based on crate's Cargo.toml.

The tool can be found in //tools/crates/gnrt and is typically invoked using //tools/crates/run_gnrt.py.

Directory structure for third-party crates

The directory structure for a crate “foo” version 3.4.2 is:

//third_party/
    rust/
        foo/
            wrapper/             (optional FFI glue or Chromium integration)
            v3/                  (version 3.4.2 maps to the v3 epoch)
                BUILD.gn         (generated by gnrt gen)
                README.chromium  (generated by gnrt vendor)
        chromium_crates_io/
            vendor/
                foo-v3/  (sources downloaded from crates.io by gnrt vendor)
            patches/
                foo-v3/  (patches automatically applied during gnrt vendor)
                    0001-Some-changes.diff
                    0002-Other-changes.diff
            Cargo.toml        (version and enabled features of "foo")
            Cargo.lock
            gnrt_config.toml  (additional configuration of "foo")

TODO(https://crbug.com/417250983): Patch directory should be epoch-specific.

Most of the files above are managed automatically by gnrt. The only “foo”-specific manually-authored files and directories are:

There are also other, non-crate-specific files such as:

  • //third_party/rust:
    • .md - this doc and other docs
    • OWNERS, PRESUBMIT.py
  • //third_party/rust/chromium_crates_io:
    • BUILD.gn.hbs - template for BUILD.gn files
    • README.chromium.hbs - template for README.chromium files
    • PRESUBMIT.py
    • .py helper scripts used by PRESUBMIT.py and by //tools/crates.
    • Somewhat obsolete cargo vet-support items - we keep supply-chain/audits.toml to preserve Chromium audits that are imported into https://github.com/google/rust-crate-audits/blob/main/sources.list)
    • Various infrastructure pieces to disable auto-formatting of the vendored files (e.g. .gitattributes, .rustfmt.toml, .style.yapf, etc.)

Importing new third-party crates

See //third_party/rust/README-importing-new-crates.md for instructions on how to import a crate from https://crates.io into Chromium.

Updating existing third-party crates

Third-party crates will get updated semi-automatically through the process described in ../tools/crates/create_update_cl.md. If you nevertheless need to manually update a crate to its latest minor or major version, then follow the steps below. To facilitate easier review, we recommend uploading separate patchsets for 1) manual changes, and 2) tool-driven, automated changes.

  1. Change directory to the root src/ dir of Chromium.
  2. Update the versions in //third_party/rust/chromium_crates_io/Cargo.toml.
    • vpython3 ./tools/crates/run_gnrt.py update <crate name>.
    • Under the hood this invokes cargo update and accepts the same command line parameters. In particular, you may need to specify --breaking when working on major version updates.
  3. Download any updated crate's files:
    • ./tools/crates/run_gnrt.py vendor
  4. Add the downloaded files to git:
    • git add -f third_party/rust/chromium_crates_io/vendor
    • The -f is important, as files may be skipped otherwise from a .gitignore inside the crate.
  5. Generate the BUILD.gn files
    • vpython3 ./tools/crates/run_gnrt.py gen
    • Or, directly through (nightly) cargo: cargo run --release --manifest-path tools/crates/gnrt/Cargo.toml --target-dir out/gnrt gen
  6. Add the generated files to git:
    • git add third_party/rust

Writing a wrapper for binding generation

Most Rust libraries will need a more C++-friendly API written on top of them in order to generate C++ bindings to them. The wrapper library can be placed in //third_party/rust/<cratename>/wrapper or at another single place that all C++ goes through to access the library. The CXX is used to generate bindings between C++ and Rust.

See //third_party/rust/serde_json_lenient/v0_1/wrapper/ and //components/qr_code_generator for examples.

See //docs/rust-ffi.md for information on C++/Rust FFI.