Add num_enum dependency for libafl crate usage

Due to the size of crrev.com/c/7564051, this CL works to split all of
the unsafe dependencies into separate CLs for individual review. The end
goal is to have all unsafe transitive dependencies for libafl imported
and reviewed prior to importing the remaining dependencies (including
libafl). We have approval for importing libafl by Chrome TSCs/ATLs (see
https://groups.google.com/a/google.com/g/chrome-tsc-discuss/c/jvyNkbHOLhM).

The num_enum crate has also been marked as `group = test` and
`allow_first_party_usage = false`.

Bug: 495772162
Change-Id: I6a486efa915ffedc115a163b6b8988b6bb6aaaf9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7698012
Reviewed-by: Liza Burakova <[email protected]>
Commit-Queue: Antonio Alphonse <[email protected]>
Reviewed-by: Titouan Rigoudy <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1619975}
NOKEYCHECK=True
GitOrigin-RevId: df23efb886f36dff99e0b94d4e29e1d4e18353d1
121 files changed
tree: 769d5f5a793841ba6ec9fefb8f9115c2302a76d6
  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. arrayvec/
  12. autocfg/
  13. backtrace/
  14. base64/
  15. better_any/
  16. bincode/
  17. bincode_derive/
  18. bit_set/
  19. bit_vec/
  20. bitflags/
  21. bytemuck/
  22. bytemuck_derive/
  23. byteorder/
  24. byteorder_lite/
  25. bytes/
  26. calendrical_calculations/
  27. cc/
  28. cfg_aliases/
  29. cfg_if/
  30. chromium_crates_io/
  31. chrono/
  32. clap/
  33. clap_builder/
  34. clap_lex/
  35. codespan_reporting/
  36. const_format/
  37. const_format_proc_macros/
  38. const_panic/
  39. core_foundation_sys/
  40. core_maths/
  41. crc32fast/
  42. cxx/
  43. cxxbridge_cmd/
  44. cxxbridge_flags/
  45. cxxbridge_macro/
  46. derivre/
  47. diplomat/
  48. diplomat_core/
  49. diplomat_runtime/
  50. displaydoc/
  51. either/
  52. encoding_rs/
  53. equivalent/
  54. erased_serde/
  55. fdeflate/
  56. fend_core/
  57. fixed_decimal/
  58. flate2/
  59. foldhash/
  60. font_types/
  61. fs2/
  62. getrandom/
  63. gimli/
  64. hashbrown/
  65. heck/
  66. hex/
  67. hmac_sha256/
  68. hostname/
  69. iana_time_zone/
  70. icu_calendar/
  71. icu_calendar_data/
  72. icu_casemap/
  73. icu_casemap_data/
  74. icu_collections/
  75. icu_decimal/
  76. icu_decimal_data/
  77. icu_experimental/
  78. icu_experimental_data/
  79. icu_list/
  80. icu_list_data/
  81. icu_locale/
  82. icu_locale_core/
  83. icu_locale_data/
  84. icu_normalizer/
  85. icu_normalizer_data/
  86. icu_pattern/
  87. icu_plurals/
  88. icu_plurals_data/
  89. icu_properties/
  90. icu_properties_data/
  91. icu_provider/
  92. icu_time/
  93. image/
  94. indexmap/
  95. itertools/
  96. itoa/
  97. ixdtf/
  98. jiff_tzdb/
  99. jxl/
  100. jxl_macros/
  101. jxl_simd/
  102. jxl_transforms/
  103. lazy_static/
  104. libc/
  105. libm/
  106. litemap/
  107. llguidance/
  108. lock_api/
  109. log/
  110. memchr/
  111. memo_map/
  112. minijinja/
  113. miniz_oxide/
  114. moxcms/
  115. murmur3/
  116. nix/
  117. num_bigint/
  118. num_derive/
  119. num_enum/
  120. num_enum_derive/
  121. num_integer/
  122. num_rational/
  123. num_traits/
  124. object/
  125. once_cell/
  126. opusic_sys/
  127. ordered_float/
  128. parking_lot/
  129. parking_lot_core/
  130. png/
  131. potential_utf/
  132. proc_macro2/
  133. proc_macro_error2/
  134. proc_macro_error_attr2/
  135. prost/
  136. prost_derive/
  137. pxfm/
  138. qr_code/
  139. quote/
  140. read_fonts/
  141. regex_automata/
  142. regex_syntax/
  143. resb/
  144. rustc_demangle/
  145. rustc_demangle_capi/
  146. rustversion/
  147. ryu/
  148. scopeguard/
  149. serde/
  150. serde_core/
  151. serde_derive/
  152. serde_json/
  153. serde_json_lenient/
  154. simd_adler32/
  155. skrifa/
  156. small_ctor/
  157. smallvec/
  158. src/
  159. stable_deref_trait/
  160. static_assertions/
  161. strck/
  162. strsim/
  163. strum/
  164. strum_macros/
  165. subtle/
  166. symphonia/
  167. symphonia_adapter_libopus/
  168. symphonia_bundle_flac/
  169. symphonia_bundle_mp3/
  170. symphonia_codec_pcm/
  171. symphonia_codec_vorbis/
  172. symphonia_core/
  173. symphonia_metadata/
  174. symphonia_utils_xiph/
  175. syn/
  176. synstructure/
  177. temporal_capi/
  178. temporal_rs/
  179. termcolor/
  180. thiserror/
  181. thiserror_impl/
  182. timezone_provider/
  183. tinystr/
  184. toktrie/
  185. typed_arena/
  186. typed_path/
  187. typeid/
  188. typewit/
  189. tzif/
  190. unicode_ident/
  191. unicode_width/
  192. unicode_xid/
  193. unty/
  194. utf8_iter/
  195. uuid/
  196. version_check/
  197. virtue/
  198. winapi_util/
  199. windows_aarch64_msvc/
  200. windows_i686_msvc/
  201. windows_link/
  202. windows_sys/
  203. windows_targets/
  204. windows_x86_64_msvc/
  205. writeable/
  206. xml/
  207. yoke/
  208. yoke_derive/
  209. zerocopy/
  210. zerofrom/
  211. zerofrom_derive/
  212. zerotrie/
  213. zerovec/
  214. zerovec_derive/
  215. zip/
  216. zmij/
  217. zoneinfo64/
  218. .clang-format
  219. DEPS
  220. OWNERS
  221. OWNERS-review-checklist.md
  222. PRESUBMIT.py
  223. README-importing-new-crates.md
  224. 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 //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.