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