• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4
5import("//build/config/rust.gni")
6
7if (toolchain_has_rust) {
8  config("edition_2024") {
9    rustflags = [ "--edition=2024" ]
10  }
11
12  config("edition_2021") {
13    rustflags = [ "--edition=2021" ]
14  }
15
16  config("edition_2018") {
17    rustflags = [ "--edition=2018" ]
18  }
19
20  config("edition_2015") {
21    rustflags = [ "--edition=2015" ]
22  }
23
24  if (enable_rust_cxx) {
25    import("//build/rust/cxx_version.gni")
26
27    config("cxx_include_path") {
28      defines = [ "CR_CXX_INCLUDE=\"third_party/rust/chromium_crates_io/vendor/cxx-${cxx_version}/include/cxx.h\"" ]
29    }
30
31    # The required dependencies for cxx-generated bindings, that must be included
32    # on the C++ side.
33    static_library("cxx_cppdeps") {
34      sources = [
35        "//third_party/rust/chromium_crates_io/vendor/cxx-${cxx_version}/include/cxx.h",
36        "//third_party/rust/chromium_crates_io/vendor/cxx-${cxx_version}/src/cxx.cc",
37
38        # Our version-independent forwarding header, which we patch cxx.cc to
39        # use since we want it to use an absolute path for its include.
40        "//third_party/rust/cxx/v1/cxx.h",
41      ]
42
43      defines = [ "RUST_CXX_NO_EXCEPTIONS" ]
44      public_configs = [ ":cxx_include_path" ]
45
46      # We cannot depend on base/base_export.h because base depends on us.
47      if (is_component_build) {
48        if (is_win) {
49          defines += [ "CXX_RS_EXPORT=__declspec(dllexport)" ]
50        } else {
51          defines +=
52              [ "CXX_RS_EXPORT=__attribute__((visibility(\"default\")))" ]
53        }
54      } else {
55        defines += [ "CXX_RS_EXPORT=" ]
56      }
57
58      deps = [
59        # Depending on the C++ bindings side of cxx then requires also depending
60        # on the Rust bindings, since one calls the other. And the Rust bindings
61        # require the Rust standard library.
62        ":cxx_rustdeps",
63      ]
64    }
65
66    group("cxx_rustdeps") {
67      # The required dependencies for cxx-generated bindings, that must be
68      # included on the Rust side.
69      public_deps = [ "//third_party/rust/cxx/v1:lib" ]
70    }
71  }
72}
73
74# Enables code behind #[cfg(test)]. This should only be used for targets where
75# testonly=true.
76config("test") {
77  rustflags = [
78    "--cfg",
79    "test",
80  ]
81}
82
83# TODO(crbug.com/gn/104): GN rust_proc_macro targets are missing this
84# command line flag, for the proc_macro crate which is provided by rustc for
85# compiling proc-macros.
86config("proc_macro_extern") {
87  rustflags = [
88    "--extern",
89    "proc_macro",
90  ]
91}
92
93# Forbids unsafe code in crates with this config.
94config("forbid_unsafe") {
95  rustflags = [ "-Funsafe_code" ]
96}
97
98config("panic_immediate_abort") {
99  visibility = [ "//build/rust/std/rules:*" ]
100  if (is_official_build) {
101    rustflags = [
102      "--cfg",
103      "feature=\"panic_immediate_abort\"",
104    ]
105  }
106}
107
108config("is_gtest_unittests") {
109  rustflags = [
110    "--cfg",
111    "is_gtest_unittests",
112  ]
113}
114