tree: 48551978c13da1a101e3a4d7bc77ef11a17cdc7c [path history] [tgz]
  1. adler2/
  2. anstyle/
  3. anyhow/
  4. arrayvec/
  5. autocfg/
  6. base64/
  7. bitflags/
  8. bytemuck/
  9. bytemuck_derive/
  10. bytes/
  11. calendrical_calculations/
  12. cc/
  13. cfg_if/
  14. chromium_crates_io/
  15. clap/
  16. clap_builder/
  17. clap_lex/
  18. codespan_reporting/
  19. combine/
  20. core_maths/
  21. crc32fast/
  22. cxx/
  23. cxxbridge_cmd/
  24. cxxbridge_flags/
  25. cxxbridge_macro/
  26. derivre/
  27. diplomat/
  28. diplomat_core/
  29. diplomat_runtime/
  30. displaydoc/
  31. either/
  32. encoding_rs/
  33. equivalent/
  34. fdeflate/
  35. fend_core/
  36. fixed_decimal/
  37. flate2/
  38. foldhash/
  39. font_types/
  40. hashbrown/
  41. heck/
  42. hex/
  43. icu_calendar/
  44. icu_calendar_data/
  45. icu_casemap/
  46. icu_casemap_data/
  47. icu_collections/
  48. icu_decimal/
  49. icu_decimal_data/
  50. icu_experimental/
  51. icu_experimental_data/
  52. icu_list/
  53. icu_list_data/
  54. icu_locale/
  55. icu_locale_core/
  56. icu_locale_data/
  57. icu_normalizer/
  58. icu_normalizer_data/
  59. icu_pattern/
  60. icu_plurals/
  61. icu_plurals_data/
  62. icu_properties/
  63. icu_properties_data/
  64. icu_provider/
  65. icu_time/
  66. indexmap/
  67. itertools/
  68. itoa/
  69. ixdtf/
  70. jiff_tzdb/
  71. lazy_static/
  72. libc/
  73. libm/
  74. litemap/
  75. llguidance/
  76. log/
  77. memchr/
  78. miniz_oxide/
  79. num_bigint/
  80. num_integer/
  81. num_rational/
  82. num_traits/
  83. png/
  84. potential_utf/
  85. proc_macro2/
  86. prost/
  87. prost_derive/
  88. qr_code/
  89. quote/
  90. read_fonts/
  91. regex_automata/
  92. regex_syntax/
  93. rustc_demangle/
  94. rustc_demangle_capi/
  95. rustversion/
  96. ryu/
  97. serde/
  98. serde_derive/
  99. serde_json/
  100. serde_json_lenient/
  101. simd_adler32/
  102. skrifa/
  103. small_ctor/
  104. smallvec/
  105. src/
  106. stable_deref_trait/
  107. static_assertions/
  108. strck/
  109. strsim/
  110. strum/
  111. strum_macros/
  112. subtle/
  113. symphonia/
  114. symphonia_bundle_flac/
  115. symphonia_core/
  116. symphonia_metadata/
  117. symphonia_utils_xiph/
  118. syn/
  119. synstructure/
  120. temporal_capi/
  121. temporal_rs/
  122. termcolor/
  123. timezone_provider/
  124. tinystr/
  125. toktrie/
  126. tzif/
  127. unicode_ident/
  128. unicode_width/
  129. winapi_util/
  130. windows_aarch64_msvc/
  131. windows_i686_msvc/
  132. windows_sys/
  133. windows_targets/
  134. windows_x86_64_msvc/
  135. writeable/
  136. yoke/
  137. yoke_derive/
  138. zerofrom/
  139. zerofrom_derive/
  140. zerotrie/
  141. zerovec/
  142. zerovec_derive/
  143. zip/
  144. .clang-format
  145. OWNERS
  146. OWNERS-review-checklist.md
  147. PRESUBMIT.py
  148. README-importing-new-crates.md
  149. 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/    (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 like vet_config.toml.hbs and supply-chain/.

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.