blob: bbad8fc9070f966911906704943b481db9d0effd [file] [log] [blame] [view]
Lukasz Anforowiczc8ebad82025-05-22 20:51:411# Unstable Rust usage in Chromium
Tatsuyuki Ishib3425ab02025-04-10 19:02:202
Lukasz Anforowiczc8ebad82025-05-22 20:51:413## Policy
Tatsuyuki Ishib3425ab02025-04-10 19:02:204
Lukasz Anforowiczc8ebad82025-05-22 20:51:415Unstable features are **unsupported** by default in Chromium. Any use of an
6unstable language or library feature should be agreed upon by the Rust toolchain
7team before enabling it.
Tatsuyuki Ishib3425ab02025-04-10 19:02:208
Lukasz Anforowiczc8ebad82025-05-22 20:51:419Since Chromium imports the Rust toolchain at its HEAD and builds it in a
10nightly-like configuration, it is technically possible to depend on unstable
11features. However, unstable features often change in a backwards-incompatible
12way without a warning. If such incompatible changes are introduced, importing a
13new version of toolchain now requires the owner to fix forward, instead of being
14an automated process. This makes toolchain upgrades prohibitively difficult.
15
16When 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
26This 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
41Example `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
51Example `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 ```