# Copyright 2023 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. # This file configures how to generate GN rules for third-party Rust crates. # # `[crate.foo]` sections below can configure generation of `BUILD.gn` and/or # `README.chromium` by specifying the following options: # # allow_first_party_usage: If false, the crate should not be visible to first # party code even though it is present in the Cargo.toml file. It defaults to # true. Use this if you need to control features for a crate that is only # meant for use as a transitive dependency of third-party crates. # e.g. allow_first_party_usage = false # # ban_features: A list of crate features that are disallowed in Chromium. # Typically `ban_features` is used when a crate-feature-gated code failed or # hasn't gone through a security audit. # # build_script_outputs: A list of file paths, rooted from where the BUILD.gn # file is located, of files generated by the crate's build script. # e.g. build_script_outputs = [ "crate/src/gen/gen_stuff.rs" ] # # extra_input_roots: A list of additional arbitrary files and/or directories # that are part of the crate (these need to be listed as `inputs` in the # generated `BUILD.gn`). An example scenario that needs `extra_input_roots` # is when a crate uses `include_str!` to include `README.md` as a doc # comment. # # extra_src_roots: A list of additional Rust sources that come from outside of # the crate's `src` directory (these need to be added to `sources` in the # generated `BUILD.gn`). An example scenario that needs `extra_src_roots` is # when a crate uses generated code via `include!("../generated/foo.rs")`. # # group: One of 'safe', 'sandbox', or 'test. This indicates where the library # is allowed to be used and where its GN rules will be written. # # The group of least privilege is inherited by a crate C from all crates that # depend on C transitively. For crates listed in Cargo.toml, and not depended # on by other crates, the default is 'safe'. # TODO(danakj): The default should probably be 'sandbox'? # # 'safe': The library satisfies the rule-of-2 and can be used in any process. # 'sandbox': The library does not satisfy the rule-of-2 and must be used in # a sandboxed process such as the renderer or a utility process. # 'test': The library is only used in tests. # # license: The name of the license. This should normally be populated from the # crate's Cargo.toml, but it can be specified to override it. # # license_files: A list of license files, relative to the crate's root. # This is normally found automatically based on convention, but it can be # specified to override it. A license file is expected for all shipped # libraries. # # security_critical: A boolean that overrides if the crate is marked security- # critical in the README.chromium. It defaults to true if the crate is not in # the 'test' group/. # # shipped: A boolean that overrides if the crate is marked shipped in the # README.chromium. It defaults to true if the crate is not in the 'test' # group. # # bin_targets: A list of binary target names to cover. This list is empty by # default, which means that the default generated `BUILD.gn` will only cover # the library target (if any) of the package. # # Additional, less commonly needed options can also be discovered by reading # the doc comments in `//tools/crates/gnrt/lib/config.rs` (e.g. `CrateConfig`'s # fields correspond to per-crate options like `extra_input_roots`). [gn] build_file_template = "BUILD.gn.hbs" readme_file_template = "README.chromium.hbs" removed_cargo_template = "removed_Cargo.toml.hbs" removed_librs_template = "removed_lib.rs.hbs" [vet] config_template = "vet_config.toml.hbs" [resolve] root = "chromium" # These crates are dependencies in some configurations, but we don't use them. # TODO(danakj): Can we figure out the wasi and winapi ones automatically? # minimal-lexical is unsound see https://crrev.com/c/4977110 for more info. It is a dependency of nom, but not actually used remove_crates = ['cc', 'link-cplusplus', 'wasi', 'winapi-i686-pc-windows-gnu', 'winapi-x86_64-pc-windows-gnu', 'minimal-lexical'] [crate.anyhow] group = 'test' [crate.base64] group = 'test' [crate.bytes] group = 'test' [crate.clap] # These files are included from source files and are thus required as part of # building the crate. extra_input_roots = ['../README.md'] extra_src_roots = ['../examples'] [crate.clap_builder] extra_input_roots = ['../README.md'] [crate.cxx] remove_deps = ['cc', 'link-cplusplus'] # This removes the use of cc, and disables the `build_with_cargo` cfg which # also removes the use of link-cplusplus. remove_build_rs = true [crate.cxxbridge-cmd] shipped = false bin_targets = ["cxxbridge"] [crate.hex] group = 'test' [crate.hex-literal] group = 'test' extra_input_roots = ['../README.md'] [crate.libc] ban_features = [ # `extra_traits` feature is banned because of # https://github.com/rust-lang/libc/issues/3560 'extra_traits', ] [crate.log] group = 'test' [crate.nom] remove_deps = ['minimal-lexical'] [crate.prost] extra_input_roots = ['../README.md'] group = 'test' [crate.prost-derive] group = 'test' [crate.rand] group = 'test' [crate.rand_pcg] group = 'test' [crate.read-fonts] extra_src_roots = ['../generated'] [crate.regex] group = 'test' [crate.rstest] group = 'test' [crate.rstest_reuse] group = 'test' [crate.rustversion] allow_first_party_usage = false extra_build_script_src_roots = ['../build/rustc.rs'] build_script_outputs = [ "version.expr" ] [crate.rustc-demangle-capi] shipped = false [crate.serde_json] group = 'test' [crate.small_ctor] group = 'test' [crate.unicode-ident] license_files = ['LICENSE-APACHE', 'LICENSE-UNICODE'] [crate.unicode-linebreak] allow_first_party_usage = false build_script_outputs = [ "tables.rs" ] [crate.wycheproof] group = 'test' extra_input_roots = ['data']