[rust] Fix gnrt update/vendor after the ICU4X 2.4.0 update

Since crrev.com/c/8633019, `gnrt update` and `gnrt vendor` fail on a
clean checkout with "failed to select a version for `icu_properties`".
Every third-party Rust crate roll runs these commands, so no crate can
be rolled until this is fixed.

Why they fail:
- chromium_crates_io/Cargo.toml now requires icu_properties ^2.4.0.
- harfrust 0.14.0, as published on crates.io, requires exactly
  icu_properties 2.2.0.
- crrev.com/c/8633019 relaxed that requirement with a local patch to
  Chromium's vendored copy of harfrust. Builds and `gnrt gen` read the
  vendored copy, so they work. `gnrt update` and `gnrt vendor` read the
  crates.io version, which still has the exact pin, so Cargo cannot
  pick an icu_properties version.

Repro on origin/main ba3a1adcba90f:
  $ tools/crates/run_gnrt.py update -- smallvec@1.16.2
  error: failed to select a version for `icu_properties`.
      ... required by package `harfrust v0.14.0`
  versions that meet the requirements `=2.2.0` are: 2.2.0
    previously selected package `icu_properties v2.4.0`
  cargo update exited with status exit status: 101
With this CL the same command updates smallvec 1.16.2 -> 1.16.3.

Fix: a [patch.crates-io] entry tells Cargo to use the vendored,
already-patched harfrust instead of the crates.io one. No code changes:
Cargo.lock only drops harfrust's crates.io source line, and `gnrt gen`
produces no BUILD.gn changes.

While the [patch.crates-io] entry exists, Cargo will not update
harfrust automatically. Remove the entry once harfrust publishes a
release without the exact icu_properties pin.

Prepared with AI assistance.

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