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