tree: afde0af2061a1a78677f73161c9f3883d5063a7c [search]
  1. addr2line/
  2. adler2/
  3. ahash/
  4. aho_corasick/
  5. alloc_no_stdlib/
  6. alloc_stdlib/
  7. android_system_properties/
  8. anstyle/
  9. antlr4rust/
  10. anyhow/
  11. arbitrary_int/
  12. array_init/
  13. autocfg/
  14. backtrace/
  15. base64/
  16. better_any/
  17. bincode/
  18. bincode_derive/
  19. bit_set/
  20. bit_vec/
  21. bitbybit/
  22. bitflags/
  23. brotli_decompressor/
  24. build_id2/
  25. bytemuck/
  26. bytemuck_derive/
  27. byteorder/
  28. byteorder_lite/
  29. bytes/
  30. calendrical_calculations/
  31. cc/
  32. cfg_aliases/
  33. cfg_if/
  34. chromium_crates_io/
  35. chrono/
  36. clap/
  37. clap_builder/
  38. clap_lex/
  39. cobs/
  40. codespan_reporting/
  41. const_format/
  42. const_format_proc_macros/
  43. const_panic/
  44. core_affinity2/
  45. core_foundation_sys/
  46. core_maths/
  47. crc32fast/
  48. ctor/
  49. ctor_proc_macro/
  50. cxx/
  51. cxxbridge_cmd/
  52. cxxbridge_flags/
  53. cxxbridge_macro/
  54. derivre/
  55. diplomat/
  56. diplomat_core/
  57. diplomat_runtime/
  58. displaydoc/
  59. dtor/
  60. dtor_proc_macro/
  61. either/
  62. equivalent/
  63. erased_serde/
  64. exceptional/
  65. extended/
  66. fast_rands/
  67. fastbloom/
  68. fdeflate/
  69. fend_core/
  70. fixed_decimal/
  71. flate2/
  72. foldhash/
  73. font_types/
  74. fs2/
  75. getrandom/
  76. gimli/
  77. harfrust/
  78. harfrust_capi/
  79. hashbrown/
  80. heck/
  81. hex/
  82. hmac_sha256/
  83. hostname/
  84. iana_time_zone/
  85. icu4x_data/
  86. icu_calendar/
  87. icu_capi/
  88. icu_casemap/
  89. icu_casemap_data/
  90. icu_collections/
  91. icu_decimal/
  92. icu_decimal_data/
  93. icu_experimental/
  94. icu_experimental_data/
  95. icu_list/
  96. icu_list_data/
  97. icu_locale/
  98. icu_locale_core/
  99. icu_locale_data/
  100. icu_locale_fallback/
  101. icu_normalizer/
  102. icu_normalizer_data/
  103. icu_pattern/
  104. icu_plurals/
  105. icu_plurals_data/
  106. icu_properties/
  107. icu_properties_data/
  108. icu_provider/
  109. icu_provider_adapters/
  110. icu_time/
  111. image/
  112. incremental_font_transfer/
  113. indexmap/
  114. itertools/
  115. itoa/
  116. ixdtf/
  117. jiff_tzdb/
  118. jpeg_encoder/
  119. jxl/
  120. jxl_gainmap/
  121. jxl_macros/
  122. jxl_simd/
  123. jxl_transforms/
  124. konst/
  125. konst_macro_rules/
  126. lazy_static/
  127. libafl/
  128. libafl_bolts/
  129. libafl_core/
  130. libafl_derive/
  131. libc/
  132. libm/
  133. libz_rs_sys/
  134. link_section/
  135. linktime_proc_macro/
  136. litemap/
  137. ll_mp/
  138. llguidance/
  139. lock_api/
  140. log/
  141. mach2/
  142. memchr/
  143. meminterval/
  144. memo_map/
  145. memoffset/
  146. minibsod/
  147. minijinja/
  148. miniz_oxide/
  149. moxcms/
  150. murmur3/
  151. nix/
  152. no_std_time/
  153. nonzero_macros/
  154. num_bigint/
  155. num_complex/
  156. num_derive/
  157. num_enum/
  158. num_enum_derive/
  159. num_integer/
  160. num_rational/
  161. num_traits/
  162. object/
  163. once_cell/
  164. ordered_float/
  165. ownedref/
  166. parking_lot/
  167. parking_lot_core/
  168. png/
  169. portable_atomic/
  170. postcard/
  171. potential_utf/
  172. primal_check/
  173. proc_macro2/
  174. prost/
  175. prost_derive/
  176. pxfm/
  177. qr_code/
  178. quote/
  179. rand_core/
  180. read_fonts/
  181. ref_cast/
  182. ref_cast_impl/
  183. regex/
  184. regex_automata/
  185. regex_lite/
  186. regex_syntax/
  187. resb/
  188. rustc_demangle/
  189. rustc_demangle_capi/
  190. rustfft/
  191. rustversion/
  192. ryu/
  193. safe_arch/
  194. scc/
  195. scopeguard/
  196. sdd/
  197. serde/
  198. serde_anymap/
  199. serde_core/
  200. serde_derive/
  201. serde_json/
  202. serde_json_lenient/
  203. serial_test/
  204. serial_test_derive/
  205. sfv/
  206. shared_brotli_patch_decoder/
  207. shmem_providers/
  208. simd_adler32/
  209. siphasher/
  210. skera/
  211. skrifa/
  212. small_ctor/
  213. smallvec/
  214. stable_deref_trait/
  215. static_assertions/
  216. strck/
  217. strength_reduce/
  218. strsim/
  219. strum/
  220. strum_macros/
  221. subtle/
  222. symphonia/
  223. symphonia_bundle_flac/
  224. symphonia_bundle_mp3/
  225. symphonia_codec_pcm/
  226. symphonia_codec_vorbis/
  227. symphonia_common/
  228. symphonia_core/
  229. symphonia_format_isomp4/
  230. symphonia_format_mkv/
  231. symphonia_format_ogg/
  232. symphonia_format_riff/
  233. symphonia_metadata/
  234. symphonia_utils_xiph/
  235. syn/
  236. synstructure/
  237. temporal_capi/
  238. temporal_rs/
  239. termcolor/
  240. thiserror/
  241. thiserror_impl/
  242. timezone_provider/
  243. tinystr/
  244. toktrie/
  245. transpose/
  246. tuple_list/
  247. tuple_list_ex/
  248. typed_arena/
  249. typed_builder/
  250. typed_builder_macro/
  251. typed_path/
  252. typeid/
  253. typewit/
  254. tzif/
  255. uds/
  256. unicode_ident/
  257. unicode_width/
  258. unicode_xid/
  259. unty/
  260. utf16_iter/
  261. utf8_iter/
  262. utf_types/
  263. uuid/
  264. version_check/
  265. virtue/
  266. wait_timeout/
  267. wide/
  268. winapi_util/
  269. windows_aarch64_msvc/
  270. windows_i686_msvc/
  271. windows_link/
  272. windows_sys/
  273. windows_targets/
  274. windows_x86_64_msvc/
  275. write16/
  276. write_fonts/
  277. writeable/
  278. xml/
  279. xxhash_rust/
  280. yoke/
  281. yoke_derive/
  282. zerocopy/
  283. zerofrom/
  284. zerofrom_derive/
  285. zeroize/
  286. zeroize_derive/
  287. zerotrie/
  288. zerovec/
  289. zerovec_derive/
  290. zip/
  291. zlib_rs/
  292. zmij/
  293. zoneinfo64/
  294. zune_core/
  295. zune_jpeg/
  296. .clang-format
  297. DEPS
  298. OWNERS
  299. OWNERS-review-checklist.md
  300. PRESUBMIT.py
  301. README-importing-new-crates.md
  302. 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 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.