File: unstable_rust_feature_usage.md

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (58 lines) | stat: -rw-r--r-- 2,252 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Unstable Rust usage in Chromium

## Policy

Unstable features are **unsupported** by default in Chromium. Any use of an
unstable language or library feature should be agreed upon by the Rust toolchain
team before enabling it.

Since Chromium imports the Rust toolchain at its HEAD and builds it in a
nightly-like configuration, it is technically possible to depend on unstable
features. However, unstable features often change in a backwards-incompatible
way without a warning. If such incompatible changes are introduced, importing a
new version of toolchain now requires the owner to fix forward, instead of being
an automated process. This makes toolchain upgrades prohibitively difficult.

When an exception is required, consider:

-   Whether the unstable feature brings significant value that is unattainable
    in stable alternatives
-   The risk of breaking changes to the feature
-   Ways to fallback in case a backward-incompatible toolchain change is
    introduced

## Exceptions

This section maintains a list of exceptions from the policy above:

- `#![feature(portable_simd)]` needed by the ETC1 encoder (see
  [the discussion in the doc here](https://docs.google.com/document/d/1lh9x43gtqXFh5bP1LeYevWj0EcIRgIu0XGahHY08aeY/edit?tab=t.0)
    - `//ui/android/texture_compressor`
    - `//third_party/rust/bytemuck`
- `#![feature(linkage)]` and `#![feature(rustc_attrs)]` needed to use
  PartitionAlloc from Rust (removal is tracked by https://crbug.com/410596442)
    - `//build/rust/allocator`
- `maybe_uninit_write_slice`, `assert_matches`, `maybe_uninit_slice`:
  Grandfathered-in exception in prototype code (i.e. not used and not shipping)
    - `mojo/public/rust/...`

### How to allow unstable features in BUILD.gn

Example `BUILD.gn` for first-party code:

    ```
    # BUILD.gn:
    rust_static_library("some_target_name") {
      configs -= [ "//build/config/compiler:disallow_unstable_features" ]
      rustflags = [ "-Zallow-features=portable_simd" ]
    }
    ```

Example `gnrt_config.toml` entry for a third-party crate
(run `tools/crates/run_gnrt.py gen` to regenerate the crate's `BUILD.gn` file):

    ```
    # gnrt_config.toml:
    [crate.bytemuck.extra_kv]
    allow_unstable_features = ["portable_simd"]
    ```