Lukasz Anforowicz | c8ebad8 | 2025-05-22 20:51:41 | [diff] [blame] | 1 | # Unstable Rust usage in Chromium |
Tatsuyuki Ishi | b3425ab0 | 2025-04-10 19:02:20 | [diff] [blame] | 2 | |
Lukasz Anforowicz | c8ebad8 | 2025-05-22 20:51:41 | [diff] [blame] | 3 | ## Policy |
Tatsuyuki Ishi | b3425ab0 | 2025-04-10 19:02:20 | [diff] [blame] | 4 | |
Lukasz Anforowicz | c8ebad8 | 2025-05-22 20:51:41 | [diff] [blame] | 5 | Unstable features are **unsupported** by default in Chromium. Any use of an |
| 6 | unstable language or library feature should be agreed upon by the Rust toolchain |
| 7 | team before enabling it. |
Tatsuyuki Ishi | b3425ab0 | 2025-04-10 19:02:20 | [diff] [blame] | 8 | |
Lukasz Anforowicz | c8ebad8 | 2025-05-22 20:51:41 | [diff] [blame] | 9 | Since Chromium imports the Rust toolchain at its HEAD and builds it in a |
| 10 | nightly-like configuration, it is technically possible to depend on unstable |
| 11 | features. However, unstable features often change in a backwards-incompatible |
| 12 | way without a warning. If such incompatible changes are introduced, importing a |
| 13 | new version of toolchain now requires the owner to fix forward, instead of being |
| 14 | an automated process. This makes toolchain upgrades prohibitively difficult. |
| 15 | |
| 16 | When an exception is required, consider: |
| 17 | |
| 18 | - Whether the unstable feature brings significant value that is unattainable |
| 19 | in stable alternatives |
| 20 | - The risk of breaking changes to the feature |
| 21 | - Ways to fallback in case a backward-incompatible toolchain change is |
| 22 | introduced |
| 23 | |
| 24 | ## Exceptions |
| 25 | |
| 26 | This section maintains a list of exceptions from the policy above: |
| 27 | |
| 28 | - `#![feature(portable_simd)]` needed by the ETC1 encoder (see |
| 29 | [the discussion in the doc here](https://docs.google.com/document/d/1lh9x43gtqXFh5bP1LeYevWj0EcIRgIu0XGahHY08aeY/edit?tab=t.0) |
| 30 | - `//ui/android/texture_compressor` |
| 31 | - `//third_party/rust/bytemuck` |
| 32 | - `#![feature(linkage)]` and `#![feature(rustc_attrs)]` needed to use |
| 33 | PartitionAlloc from Rust (removal is tracked by https://crbug.com/410596442) |
| 34 | - `//build/rust/allocator` |
| 35 | - `maybe_uninit_write_slice`, `assert_matches`, `maybe_uninit_slice`: |
| 36 | Grandfathered-in exception in prototype code (i.e. not used and not shipping) |
| 37 | - `mojo/public/rust/...` |
| 38 | |
| 39 | ### How to allow unstable features in BUILD.gn |
| 40 | |
| 41 | Example `BUILD.gn` for first-party code: |
| 42 | |
| 43 | ``` |
| 44 | # BUILD.gn: |
| 45 | rust_static_library("some_target_name") { |
| 46 | configs -= [ "//build/config/compiler:disallow_unstable_features" ] |
| 47 | rustflags = [ "-Zallow-features=portable_simd" ] |
| 48 | } |
| 49 | ``` |
| 50 | |
| 51 | Example `gnrt_config.toml` entry for a third-party crate |
| 52 | (run `tools/crates/run_gnrt.py gen` to regenerate the crate's `BUILD.gn` file): |
| 53 | |
| 54 | ``` |
| 55 | # gnrt_config.toml: |
| 56 | [crate.bytemuck.extra_kv] |
| 57 | allow_unstable_features = ["portable_simd"] |
| 58 | ``` |