1# Copyright 2023 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5# This file configures how to generate GN rules for third-party Rust crates. 6# 7# `[crate.foo]` sections below can configure generation of `BUILD.gn` and/or 8# `README.chromium` by specifying the following options: 9# 10# allow_first_party_usage: If false, the crate should not be visible to first 11# party code even though it is present in the Cargo.toml file. It defaults to 12# true. Use this if you need to control features for a crate that is only 13# meant for use as a transitive dependency of third-party crates. 14# e.g. allow_first_party_usage = false 15# 16# ban_features: A list of crate features that are disallowed in Chromium. 17# Typically `ban_features` is used when a crate-feature-gated code failed or 18# hasn't gone through a security audit. 19# 20# build_script_outputs: A list of file paths, rooted from where the BUILD.gn 21# file is located, of files generated by the crate's build script. 22# e.g. build_script_outputs = [ "crate/src/gen/gen_stuff.rs" ] 23# 24# extra_input_roots: A list of additional arbitrary files and/or directories 25# that are part of the crate (these need to be listed as `inputs` in the 26# generated `BUILD.gn`). An example scenario that needs `extra_input_roots` 27# is when a crate uses `include_str!` to include `README.md` as a doc 28# comment. 29# 30# extra_src_roots: A list of additional Rust sources that come from outside of 31# the crate's `src` directory (these need to be added to `sources` in the 32# generated `BUILD.gn`). An example scenario that needs `extra_src_roots` is 33# when a crate uses generated code via `include!("../generated/foo.rs")`. 34# 35# group: One of 'safe', 'sandbox', or 'test. This indicates where the library 36# is allowed to be used and where its GN rules will be written. 37# 38# The group of least privilege is inherited by a crate C from all crates that 39# depend on C transitively. For crates listed in Cargo.toml, and not depended 40# on by other crates, the default is 'safe'. 41# TODO(danakj): The default should probably be 'sandbox'? 42# 43# 'safe': The library satisfies the rule-of-2 and can be used in any process. 44# 'sandbox': The library does not satisfy the rule-of-2 and must be used in 45# a sandboxed process such as the renderer or a utility process. 46# 'test': The library is only used in tests. 47# 48# license: The name of the license. This should normally be populated from the 49# crate's Cargo.toml, but it can be specified to override it. 50# 51# license_files: A list of license files, relative to the crate's root. 52# This is normally found automatically based on convention, but it can be 53# specified to override it. A license file is expected for all shipped 54# libraries. 55# 56# security_critical: A boolean that overrides if the crate is marked security- 57# critical in the README.chromium. It defaults to true if the crate is not in 58# the 'test' group/. 59# 60# shipped: A boolean that overrides if the crate is marked shipped in the 61# README.chromium. It defaults to true if the crate is not in the 'test' 62# group. 63# 64# bin_targets: A list of binary target names to cover. This list is empty by 65# default, which means that the default generated `BUILD.gn` will only cover 66# the library target (if any) of the package. 67# 68# Additional, less commonly needed options can also be discovered by reading 69# the doc comments in `//tools/crates/gnrt/lib/config.rs` (e.g. `CrateConfig`'s 70# fields correspond to per-crate options like `extra_input_roots`). 71 72[gn] 73build_file_template = "BUILD.gn.hbs" 74readme_file_template = "README.chromium.hbs" 75removed_cargo_template = "removed_Cargo.toml.hbs" 76removed_librs_template = "removed_lib.rs.hbs" 77 78[vet] 79config_template = "vet_config.toml.hbs" 80 81[resolve] 82root = "chromium" 83# These crates are dependencies in some configurations, but we don't use them. 84remove_crates = [ 85 # C/C++ dependencies must be explicitly writting in GN rules somehow. 86 'cc', 87 'link-cplusplus', 88 'shlex', 89 # minimal-lexical is unsound see https://crrev.com/c/4977110 for more info. 90 # It is a dependency of nom, but not actually used. 91 'minimal-lexical', 92 # Windows targets that we do not ever target. 93 'windows_aarch64_gnullvm', 94 'windows_i686_gnu', 95 'windows_i686_gnullvm', 96 'windows_x86_64_gnu', 97 'windows_x86_64_gnullvm', 98 # Behind a feature that we do not enable. 99 'wasi' 100] 101 102[crate.anyhow] 103group = 'test' 104 105[crate.base64] 106group = 'test' 107 108[crate.bstr] 109ban_features = [ 110 # The unicode feature is not audited for UB-Risk-2. 111 'unicode' 112] 113 114[crate.bytes] 115group = 'test' 116 117[crate.clap] 118# These files are included from source files and are thus required as part of 119# building the crate. 120extra_input_roots = ['../README.md'] 121extra_src_roots = ['../examples'] 122 123[crate.clap_builder] 124extra_input_roots = ['../README.md'] 125 126[crate.codespan-reporting] 127# TODO(https://crbug.com/369075726): Remove this exception. 128no_license_file_tracked_in_crbug_369075726 = true 129 130[crate.cxx] 131remove_deps = ['cc', 'link-cplusplus'] 132# This removes the use of cc, and disables the `build_with_cargo` cfg which 133# also removes the use of link-cplusplus. 134remove_build_rs = true 135 136[crate.cxxbridge-cmd] 137shipped = false 138bin_targets = ["cxxbridge"] 139 140[crate.flate2] 141ban_features = [ 142 # `any_zlib` feature is banned because Chromium does not use the `zlib` 143 # backend (and because this backend's extensive `unsafe` usage hasn't been 144 # audited). 145 'any_zlib', 146] 147 148[crate.hex] 149group = 'test' 150 151[crate.hex-literal] 152group = 'test' 153extra_input_roots = ['../README.md'] 154 155[crate.itertools] 156group = 'test' 157 158[crate.libc] 159ban_features = [ 160 # `extra_traits` feature is banned because of 161 # https://github.com/rust-lang/libc/issues/3560 162 'extra_traits', 163] 164 165[crate.log] 166 167[crate.nom] 168remove_deps = ['minimal-lexical'] 169 170[crate.png] 171extra_kv = { allow_unstable_features = 'portable_simd' } 172 173[crate.prost] 174extra_input_roots = ['../README.md'] 175group = 'test' 176 177[crate.prost-derive] 178group = 'test' 179 180[crate.rand] 181group = 'test' 182 183[crate.rand_pcg] 184group = 'test' 185 186[crate.read-fonts] 187extra_src_roots = ['../generated'] 188 189[crate.regex] 190group = 'test' 191 192[crate.relative-path] 193# TODO(https://crbug.com/369075726): Remove this exception. 194no_license_file_tracked_in_crbug_369075726 = true 195 196[crate.rstest] 197group = 'test' 198 199[crate.rstest_reuse] 200group = 'test' 201 202[crate.rustversion] 203allow_first_party_usage = false 204extra_build_script_src_roots = ['../build/rustc.rs'] 205build_script_outputs = [ "version.expr" ] 206 207[crate.rustc-demangle-capi] 208shipped = false 209# TODO(https://crbug.com/369075726): Remove this exception. 210no_license_file_tracked_in_crbug_369075726 = true 211 212[crate.serde_json] 213group = 'test' 214 215[crate.skrifa] 216extra_src_roots = ['../generated'] 217 218[crate.small_ctor] 219group = 'test' 220 221[crate.unicode-ident] 222license_files = ['LICENSE-APACHE', 'LICENSE-UNICODE'] 223 224[crate.unicode-linebreak] 225allow_first_party_usage = false 226build_script_outputs = [ "tables.rs" ] 227 228[crate.windows-sys] 229extra_kv = { visibility = [ '//build/rust/tests/windows_sys_test' ] } 230 231[crate.windows_aarch64_msvc] 232native_libs_roots = [ '../lib' ] 233 234[crate.windows_i686_msvc] 235native_libs_roots = [ '../lib' ] 236 237[crate.windows_x86_64_msvc] 238native_libs_roots = [ '../lib' ] 239 240[crate.wycheproof] 241group = 'test' 242extra_input_roots = ['data'] 243