1 # Copyright 2021 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.
5 import("//build/buildflag_header.gni")
6 import("//build/config/rust.gni")
8 if (toolchain_has_rust) {
9 config("edition_2021") {
10 rustflags = [ "--edition=2021" ]
13 config("edition_2018") {
14 rustflags = [ "--edition=2018" ]
17 config("edition_2015") {
18 rustflags = [ "--edition=2015" ]
22 # The required dependencies for cxx-generated bindings, that must be included
24 static_library("cxx_cppdeps") {
26 "//third_party/rust/cxx/v1/crate/include/cxx.h",
27 "//third_party/rust/cxx/v1/crate/src/cxx.cc",
30 defines = [ "RUST_CXX_NO_EXCEPTIONS" ]
32 # We cannot depend on base/base_export.h because base depends on us.
33 if (is_component_build) {
35 defines += [ "CXX_RS_EXPORT=__declspec(dllexport)" ]
38 [ "CXX_RS_EXPORT=__attribute__((visibility(\"default\")))" ]
41 defines += [ "CXX_RS_EXPORT=" ]
44 # Depending on the C++ bindings side of cxx then requires also depending
45 # on the Rust bindings, since one calls the other. And the Rust bindings
46 # require the Rust standard library.
47 deps = [ ":cxx_rustdeps" ]
50 # The required dependencies for cxx-generated bindings, that must be included
52 group("cxx_rustdeps") {
53 public_deps = [ "//third_party/rust/cxx/v1:lib" ]
58 # Enables code behind #[cfg(test)]. This should only be used for targets where
67 # TODO(crbug.com/gn/104): GN rust_proc_macro targets are missing this
68 # command line flag, for the proc_macro crate which is provided by rustc for
69 # compiling proc-macros.
70 config("proc_macro_extern") {
77 # Forbids unsafe code in crates with this config.
78 config("forbid_unsafe") {
79 rustflags = [ "-Funsafe_code" ]
82 config("panic_immediate_abort") {
83 visibility = [ "//build/rust/std/rules:*" ]
84 if (is_official_build) {
87 "feature=\"panic_immediate_abort\"",